实验任务5
task5.cpp
1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include"Info.hpp" 5 using namespace std; 6 int main() 7 { 8 const int capacity=100; 9 vector<Info> audience_info_list; 10 cout<<"录入信息:"<<endl; 11 cout<<endl; 12 cout<<"昵称\t"; 13 cout<<"联系方式(邮箱/手机号)\t"; 14 cout<<"所在城市\t"; 15 cout<<"预定参加人数\t"; 16 cout<<endl; 17 string nickname,contact,city; 18 int n,num=0; 19 while(cin>>nickname) 20 { 21 cin>>contact>>city>>n; 22 num+=n; 23 if(capacity-num>=0) 24 { 25 Info p=Info(nickname,contact,city,n); 26 audience_info_list.push_back(p); 27 } 28 else 29 { 30 num-=n; 31 char c; 32 cout<<"对不起,只剩"<<capacity-num<<"个位置."<<endl; 33 cout<<"1. 输入u,更新(update)预定信息"<<endl; 34 cout<<"2. 输入q,退出预定"<<endl; 35 cout<<"你的选择:"; 36 cin>>c; 37 cout<<endl; 38 if(c =='q') 39 break; 40 else if(c =='u') 41 { 42 cout<<"请更新您的预定信息"<<endl; 43 continue; 44 } 45 } 46 } 47 cout<<"截至目前,一共有"<<num<<"名听众预定参加。预定听众信息如下:"<<endl; 48 for(int i=0;i<audience_info_list.size();++i) 49 { 50 audience_info_list.at(i).print(); 51 cout<<endl; 52 } 53 }
Info.hpp
1 #pragma once 2 #include<iostream> 3 #include<iomanip> 4 #include<string> 5 using namespace std; 6 class Info{ 7 public: 8 Info(string name0,string contact0,string city0,int n):nickname{name0},contact{contact0},city{city0},n{n}{} 9 void print(); 10 private: 11 string nickname,contact,city; 12 int n; 13 }; 14 void Info::print() 15 { 16 cout<<"昵称:\t"<<nickname<<endl; 17 cout<<"联系方式:\t "<<contact<<endl; 18 cout<<"所在城市:\t "<<city<<endl; 19 cout<<"预定人数:\t "<<n<<endl; 20 }
实验任务6
标签:Info,city,cout,int,C++,数组,include,string,指针 From: https://www.cnblogs.com/cwj202183290470/p/16807511.html