当前位置: 首页 > news >正文

绍兴网站建设团队台州网站制作维护

绍兴网站建设团队,台州网站制作维护,做网站商家,四川省建设招标网站首页C自学精简教程 目录(必读) 作业目标#xff1a; 这个作业中#xff0c;你需要综合运用之前文章中的知识#xff0c;来解决一个相对完整的应用程序。 作业描述#xff1a; 1 在这个作业中你需要在文本文件中存储学生通讯录的信息#xff0c;并在程序启动的时候加载这些…C自学精简教程 目录(必读) 作业目标 这个作业中你需要综合运用之前文章中的知识来解决一个相对完整的应用程序。 作业描述 1 在这个作业中你需要在文本文件中存储学生通讯录的信息并在程序启动的时候加载这些数据到内存中。 2 在程序运行过程中允许用户用键盘输入信息来完成对通讯录数的增删改查。 交互示例 开始代码 开始代码不是完整的代码需要你填写一部分代码使之完整。 答案在本文最后。 当你填写完整之后运行程序和示例的交互输出一致就算完成了这个作业 开始代码 #include iostream #include iostream #include iomanip #include string #include vector #include fstream using namespace std;class Person { public:friend ostream operator(ostream os, const Person _person);friend istream operator(istream is, Person _person);public:string m_id;string m_name;string m_tel; };ostream operator(ostream os, const Person person) {os left setw(5) person.m_id setw(15) person.m_name setw(20) person.m_tel;return os; }istream operator(istream is, Person person) {//(1) your code // 使用输入操作符重载将流中的数据提取赋值给person对象的成员变量中//see https://zhuanlan.zhihu.com/p/412724745return is; }class PersonManager { public:void InputOnePerson(void);bool LoadAllPersonFromFile(const string fileName);bool DeletePerson(void);bool QueryPersonByName() const;bool QueryPersonByTel() const;void ShowAllPerson(void) const;bool SaveAllPersonToFile(void) const;private:vectorPerson m_allPerson; };bool PersonManager::DeletePerson(void) {cout Please input person id for delete:;string id;cin id;for (auto itr m_allPerson.begin(); itr ! m_allPerson.cend(); itr){if (itr-m_id id){//(2) your code// 容器的erase方法支持删除容器的元素时传入指向元素的迭代器//see https://zhuanlan.zhihu.com/p/441293600}}return false; } bool PersonManager::QueryPersonByName() const {//注意该函数需要返回bool值cout Please input name for query:;string name;cin name;for (auto itr m_allPerson.cbegin(); itr ! m_allPerson.cend(); itr){if (itr-m_name name){cout Find: endl;//(3) your code//see https://zhuanlan.zhihu.com/p/376440190//see https://zhuanlan.zhihu.com/p/376446724}}cout not found name endl;return false; } bool PersonManager::QueryPersonByTel() const {cout Please input tel for query:;string tel;cin tel;for (auto itr m_allPerson.cbegin(); itr ! m_allPerson.cend(); itr){if (itr-m_tel tel){cout Find: endl;//(4) your code//see https://zhuanlan.zhihu.com/p/376440190//see https://zhuanlan.zhihu.com/p/376446724}}cout not found tel endl;return false; }void PersonManager::ShowAllPerson(void) const {cout All Person: endl;cout left setw(5) id setw(15) name setw(20) tel endl;for (auto item : m_allPerson){cout item endl;} } bool PersonManager::SaveAllPersonToFile(void) const {ofstream fout(data_saved.txt);//下面的常量迭代器 cbegin cend 中的 c 指的是 const的意思表示不可以修改容器的元素for (auto itr m_allPerson.cbegin(); itr ! m_allPerson.cend(); itr){//(5) your code //see https://zhuanlan.zhihu.com/p/262508774}return true; }bool PersonManager::LoadAllPersonFromFile(const string fileName) {ifstream fin(fileName);if (!fin){cout load data failed . file fileName not exits. endl;return false;}Person person;while (fin person){m_allPerson.push_back(person);}cout load data from file success. endl;return true; }void PersonManager::InputOnePerson(void) {cout Please input one person endl;cout Please input id;string id;cin id;Person person;person.m_id id;for (auto itr m_allPerson.cbegin(); itr ! m_allPerson.cend(); itr){if (itr-m_id id){cout id already existed! Save failed. endl;return;}}cout Please input name;string name;cin name;person.m_name name;cout Please input tel;string tel;cin tel;person.m_tel tel;cout Input finished, save successed. endl;m_allPerson.push_back(person); }int main(int argv, char* argc[]) {PersonManager personMgr;personMgr.LoadAllPersonFromFile(input_data.txt);personMgr.ShowAllPerson();while(true){coutinput a commond : endl;cout1 [AddPerson]endl;cout2 [ShowAllPerson]endl;cout3 [QueryPerson by name]endl;cout4 [QueryPerson by tel]endl;cout5 [SaveAllPersonToFile]endl;cout6 [DeletePerson]endl;cout0 [ExitAndSaveChange]endl;int commond;cincommond;switch(commond){case 1: { personMgr.InputOnePerson(); break;}case 2: { personMgr.ShowAllPerson(); break;}case 3: { personMgr.QueryPersonByName(); break;}case 4: { personMgr.QueryPersonByTel(); break;}case 5: { personMgr.SaveAllPersonToFile(); break;}case 6: { personMgr.DeletePerson(); break;}case 0: { personMgr.SaveAllPersonToFile(); return 0;}default:{ coutSystem Exit.endl; return 0;}}}return 0; }输入文件 input_data.txt 文件内容 2 zhangsan2 13788889992 3 zhangsan3 13788889993 4 zhangsan4 13788889994 5 wanger 13333333333 运行与输出 load data from file success. All Person: id name tel 2 zhangsan2 13788889992 3 zhangsan3 13788889993 4 zhangsan4 13788889994 5 wanger 13333333333 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 2 All Person: id name tel 2 zhangsan2 13788889992 3 zhangsan3 13788889993 4 zhangsan4 13788889994 5 wanger 13333333333 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 1 Please input one person Please input id1 Please input namezhangsan Please input tel13344445555 Input finished, save successed. input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 2 All Person: id name tel 2 zhangsan2 13788889992 3 zhangsan3 13788889993 4 zhangsan4 13788889994 5 wanger 13333333333 1 zhangsan 13344445555 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 3 Please input name for query:zhangsan Find: 1 zhangsan 13344445555 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 3 Please input name for query:zhang not found zhang input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 4 Please input tel for query:13344445555 Find: 1 zhangsan 13344445555 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 4 Please input tel for query:1334444 not found 1334444 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 6 Please input person id for delete:4 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 2 All Person: id name tel 2 zhangsan2 13788889992 3 zhangsan3 13788889993 5 wanger 13333333333 1 zhangsan 13344445555 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 5 input a commond : 1 [AddPerson] 2 [ShowAllPerson] 3 [QueryPerson by name] 4 [QueryPerson by tel] 5 [SaveAllPersonToFile] 6 [DeletePerson] 0 [ExitAndSaveChange] 0 最终保存数据到文件 data_saved.txt 文件 data_saved.txt 的内容为 2 zhangsan2 13788889992 3 zhangsan3 13788889993 5 wanger 13333333333 1 zhangsan 13344445555 你的结果也是这样吗 答案在此 C自学精简教程 全部答案 学生完成该作业展示 另一个学生实现的效果
http://www.dnsts.com.cn/news/242336.html

相关文章:

  • 网站建设搭建大连品尚茗居装修公司怎么样
  • 单页营销网站后台梁志天室内设计作品
  • 秦皇岛建设局网站6网站开发得多少钱
  • 搜狗收录网站wordpress 4.8.5 漏洞
  • 烟台城乡建设学校96级给排水网站百度app安卓版下载
  • 无锡本地模板网站建设产品陕西做网站
  • 免费网站使用建筑资料管理规程
  • 米拓模板网站建设优设网app
  • 自己创造网站现在做网站用的软件
  • 论坛内网站怎么建设网站seo方案建议
  • 技术支持 光速东莞网站建设佛山英文网建站
  • 网站运行需求黄山自驾游最佳攻略
  • 班级网站建设思路17网一起做网店广州货源网
  • 电子商务网站的设计枣阳网站开发公司哪家好
  • 设计师网站库哈尔滨市土地局
  • 西宁手机网站微站建设开发平台指的是什么
  • 社交网站建设计划书高校网站建设滞后
  • 驻马店网站网站建设优秀网站主题
  • 唯美网站模板黄页88网怎么推广
  • 推广型网站开发网址巨量算数官方入口
  • 网站建设需求登记表 免费下载新手运营从哪开始学
  • 网站建设suteng网站建设服务合同印花税
  • 安徽省建设造价网站杭州哪家网站建设公司好
  • 做二维码的网站用jsp做的网站代码
  • ftp怎么做网站的备份最有创意促销活动方案
  • 南阳网站建设与管理婚纱网站建设目的
  • 公司网站建设小知识公司网站制作投标
  • 家装网站容桂网站制作咨询
  • 登陆注册是静态网站室内设计用什么软件比较好
  • 青岛海川建设集团有限公司网站wordpress成功的网站