实验五:

Info.hpp

 1 #include<iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5   class Info
 6   {
 7         private:
 8               string nickname;
 9               string contact;
10               string city;
11               int n;
12         public:
13               Info(string nick=" ",string cont=" ",string cit=" ",int count=0): nickname{nick},contact{cont},city{cit},n{count}
14               {
15                       number+=n;
16               }
17             void back()
18              { 
19                  number -= n; 
20              }
21         void print()  const
22         { 
23              cout<<left<<setw(20)<<"昵称: "<<nickname<<endl; 
24              cout<<left<<setw(20)<<"联系方式: "<<contact<<endl;
25              cout<<left<<setw(20)<<"所在城市: "<<city<<endl;
26              cout<<left<<setw(20)<<"预定参加人数: "<<n<<endl; 
27         }
28         static int number;
29   };
30   
31     int  Info::number =0;

livehouse.cpp:

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 #include"Info.hpp"
 5 #include<iomanip>
 6 using namespace std;
 7  void input(string &nickname,string &contact,string &city,int &n)
 8  {
 9        cin>>nickname;
10        cin>>contact;
11        cin>>city;
12        cin>>n;
13  }
14    int main()
15    {
16            const int capacity=100;
17            vector<Info> audience_info_list{0};
18         string a;
19         cout<<"录入信息: "<<endl;
20             cout<<"   姓名"<<setw(20)<<"联系方式"<<setw(20)<<"  城市"<<setw(20)<<"预定人数"<<endl;
21         while(cin>>a)  //作为每一次最前面的输入,不等于ctrl+z的时候接着输入类成员 
22         {
23             string nickname, contact, city;
24              int n;
25               input(nickname,contact,city,n);
26               Info t(nickname,contact,city,n);
27               audience_info_list.push_back(t);
28               if(Info::number>capacity)
29               {
30                     audience_info_list.back();
31                    t.back();
32                    cout<<"对不起,只剩"<<capacity-Info::number<<"个位置"<<endl;
33                      char select;
34                     cout<<"1. 输入u,更新预定信息"<<endl;
35                     cout<<"2. 输入q,退出预定"<<endl;
36                     cout<<"你的选择是: ";
37                     cin>>select;
38                     if(select=='u')
39                       continue;
40                     else if(select=='q')
41                       break;
42               }
43               
44          }
45          cout<<"截至目前,一共有"<<Info::number<<"名观众参加。 "<<"预定听众信息如下: "<<endl;
46          cout<<endl;
47           for (const auto &u:audience_info_list )
48              {
49                  
50              u.print();
51              cout<<endl;
52              cout<<endl;
53               }
54            return 0; 
55             
56    }
57     

 

 

 

 

 

实验六:

jiemi.cpp

 1 #include<iostream>
 2 #include<vector>
 3 #include<string>
 4 using namespace std;
 5   class TextCoder
 6   {
 7         private:
 8              string text;
 9         public:
10               TextCoder(string t=" "): text{t}
11               {
12               }
13            string encoder()
14            {
15                   string v=text;
16                    int i=0;
17                    for(i=0;i<v.length();i++)
18                    {
19                         if(v[i]>='a'&&v[i]<='z')
20                            {
21                                  if(v[i]+5<='z')
22                                       v[i]=v[i]+5;
23                                    else
24                                       v[i]='a'+v[i]+5-'z';
25                            }
26                     else if(v[i]>='A'&&v[i]<='Z')
27                            {
28                                  if(v[i]+5<='Z')
29                                       v[i]=v[i]+5;
30                                    else
31                                       v[i]='A'+v[i]+5-'Z';
32                            }
33                    }
34                    text=v;
35                    return v;
36            }
37            string coder()
38            {
39                   string v1=text;
40                    int j=0;
41                    for(j=0;j<v1.length();j++)
42                    {
43                         if(v1[j]>='a'&&v1[j]<='z')
44                            {
45                                  if(v1[j]-5>='a')
46                                       v1[j]=v1[j]-5;
47                                    else
48                                       v1[j]='z'-('a'-v1[j]+5);
49                            }
50                     else if(v1[j]>='A'&&v1[j]<='Z')
51                            {
52                                  if(v1[j]-5>='A')
53                                       v1[j]=v1[j]-5;
54                                    else
55                                       v1[j]='Z'-('A'-v1[j]+5);
56                            }
57                    }
58                    text=v1;
59                    return v1;
60            }
61            
62   };

 

 

 

 

 

原文地址:http://www.cnblogs.com/lc114514/p/16807186.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性