题目二:课程设计报告
生活随笔
收集整理的这篇文章主要介绍了
题目二:课程设计报告
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目2.李刚是一爱折腾的人,当然爱折腾的人均有梦想,他想当中国的盖次呢。可不,现在个人好友信息多了,复杂了,他想制作一个个人通讯录的制作管理软件。 刚好这个学期学了数据结构课,所以他准备使用数据结构知识来实现了。并考虑使用双向链表作数据结构。并制定了初步要求:
(1)每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。
(2)作为一个完整的系统,应具有友好的界面和较强的容错能力。
一、代码显示
// contact.h: interface for the contact class. // //#if !defined(AFX_CONTACT_H__D20C4212_AA82_4DAA_A8CB_57C4D633FDA2__INCLUDED_) #define AFX_CONTACT_H__D20C4212_AA82_4DAA_A8CB_57C4D633FDA2__INCLUDED_#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "contact.h" #include <string> using namespace std; class contact { public:string getphone();string getname();string getsex();string getaddress();string getage();string getQQ();string getweixin();string getbirthday();void addphone(string a);void addname(string a);void addsex(string a);void addaddress(string a);void addage(string a);void addQQ(string a);void addweixin(string a);void addbirthday(string a);contact();virtual ~contact();contact *next_contact;contact *last_contact; private:string name;string phonemun;string sex;string address;string age;string QQ;string num;string birthday;};#endif // !defined(AFX_CONTACT_H__D20C4212_AA82_4DAA_A8CB_57C4D633FDA2__INCLUDED_) <pre name="code" class="cpp">#include "addressbook.h" #include <conio.h> void menu() {system("cls");printf(" |------------------|\n");printf(" | 通讯录 |\n");printf(" |------------------|\n");printf(" |---1. 增加联系人--|\n");printf(" |---2. 删除联系人--|\n");printf(" |---3. 修改联系人--|\n");printf(" |---4. 显示联系人--|\n");printf(" |---5. 查询联系人--|\n");printf(" |---6. 退出 --|\n");printf(" |---------------|\n"); } int handle(char c) {switch(c){case '1':add();menu();break;case '2':delete_contact();menu();break;case '3':modify_contact();menu();break;case '4':display_contact();menu();break;case '5':query_contact();menu();break;case '6':return 0; default:system("cls");menu();cout<<" 非法选项,请选择1-6,谢谢合作。";break;}return 1; } void add() {contact *new_contact;string name,phone,sex,address,postcode,age,QQ,weixin,birthday;system("cls");new_contact = new contact; contact_num++;printf(" |-----------------------------------|\n");printf(" | 增加联系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf("请输入名字:\n");cin>>name;new_contact->addname(name);printf("请输入电话:\n");cin>>phone;char c[20];strcpy(c,phone.c_str());for (int i=0;i<phone.size();i++){if (c[i]>'9'||c[i]<0){cout<<"非法电话,输入任意键回主菜单\n";getch();return ;}}new_contact->addphone(phone);printf("请输入性别:\n");cin>>sex;new_contact->addsex(sex);printf("请输入住址:\n");cin>>address;new_contact->addaddress(address);printf("请输入年龄:\n");cin>>age;new_contact->addage(age);printf("请输入QQ号:\n");cin>>QQ;new_contact->addQQ(QQ);printf("请输入微信号:\n");cin>>weixin;new_contact->addweixin(weixin);printf("请输入出生日期:\n");cin>>birthday;new_contact->addbirthday(birthday);if (contact_num==1){root.next_contact = new_contact;root.last_contact = new_contact;}else{new_contact->next_contact = root.next_contact;root.next_contact->last_contact = new_contact;root.next_contact = new_contact;}cout<<endl<<endl<<"增加成功,按任意键回主菜单";getch();return ; } void delete_contact() {string name;contact *this_contact;this_contact = root.next_contact;if (contact_num == 0){cout<<"无联系人可以删除,输入任意键继续操作";getch();return ;}system("cls");printf(" |-----------------------------------|\n");printf(" | 删除联系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------输入需要删除的联系人姓名-------------|\n");cin>>name;while(this_contact != NULL){if (this_contact->getname()==name){if (this_contact->last_contact == NULL&&this_contact->next_contact == NULL){root.next_contact = NULL;root.last_contact = NULL;delete this_contact;cout<<"\n删除成功,输入任意键回主菜单";getch();return ;}else if (this_contact->last_contact == NULL){root.next_contact = this_contact->next_contact;this_contact->next_contact->last_contact = NULL;delete this_contact;cout<<"\n删除成功,输入任意键回主菜单";getch();return ;}else if (this_contact->next_contact == NULL){this_contact->last_contact->next_contact = NULL;root.last_contact = this_contact->last_contact;delete this_contact;cout<<"\n删除成功,输入任意键回主菜单";getch();return ;}else{this_contact->last_contact->next_contact = this_contact->next_contact;this_contact->next_contact->last_contact = this_contact->last_contact;delete this_contact;cout<<"\n删除成功,输入任意键回主菜单";getch();return ;}}this_contact = this_contact->next_contact;}cout<<endl<<endl<<"无此联系人,删除失败,输入任意键回主菜单";getch();return ; } void modify_contact() {contact *this_contact;string name;string choose;system("cls");printf(" |-----------------------------------|\n");printf(" | 修改联系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------输入需要修改的联系人姓名-------------|\n");cin>>name;this_contact = root.next_contact;while(this_contact != NULL){if (this_contact->getname()==name){for (int i=0;i<2;i++){system("cls");printf(" |-----------------------------------|\n");printf(" | 修改联系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");switch(i){case 0: printf(" |-----------输入需要修改的联系人姓名-------------|\n");cout<<"输入修改后的名字,无需修改请按0回车\n";cout<<this_contact->getname()<<endl;cin>>choose;if (choose != "0"){this_contact->addname(choose);}break;case 1: printf(" |-----------输入需要修改的联系人电话-------------|\n");cout<<"输入修改后的电话,无需修改请按0回车\n";cout<<this_contact->getphone()<<endl;cin>>choose;if (choose != "0"){this_contact->addphone(choose);}break;}}cout<<"修改成功,输入任意键回主菜单";getch();return ;}this_contact = this_contact->next_contact;}cout<<endl<<endl<<"无此联系人,修改失败,输入任意键回主菜单";getch();return ;} void query_contact() {contact *this_contact;string name;system("cls");printf(" |-----------------------------------|\n");printf(" | 查找联系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------输入需要查找的联系人姓名-------------|\n");cin>>name;this_contact = root.next_contact;while(this_contact != NULL){if (this_contact->getname()==name){cout<<endl<<endl<<"姓名 :"<<this_contact->getname()<<endl;cout<<"电话 :"<<this_contact->getphone()<<endl;cout<<endl<<endl<<"输入任意键回主菜单";getch();return ;}this_contact = this_contact->next_contact;}cout<<endl<<endl<<"无此联系人,查找失败,输入任意键回主菜单";getch();return ; } void display_contact() {system("cls");contact *this_contact;char format[]=" ";this_contact = root.next_contact;printf("|-----------------------------------|\n");printf("| 联系人 |\n");printf("|-----------------------------------|\n");printf("姓名\t电话\t性别\t住址\t\t年龄\tQQ\t\t微信\t出生日期 \n");while(this_contact != NULL){strcpy(format,this_contact->getname().c_str());cout<<format;strcpy(format,this_contact->getphone().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getsex().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getaddress().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getage().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getQQ().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getweixin().c_str());cout<<"\t"<<format;strcpy(format,this_contact->getbirthday().c_str());cout<<"\t"<<format<<endl;this_contact = this_contact->next_contact;}cout<<endl<<endl<<" 输入任意键到主菜单";getch();return ; } void main() {menu();m = getch();while(1){if (handle(m)==0){exit(0);}m = getch();} }
1、操作平台
2、增加联系人:刘小明
3、显示联系人
4、删除联系人:汤瓜皮
5、修改联系人:刘小明
6、查找联系人:王心桐
7、退出系统
三、个人总结
学习编程这门课程,真的需要花很多心思和时间,而且需要坚持不懈,每天都花上一些时间去敲一下代码,想要更深入了解的话,甚至可能要经过上百次乃至上千次地对代码进行调试。可惜自己太懒并没用做到这一点,所以在做编程时都觉得和吃力,感觉自己什么都好想没都不懂。这次连一些基本的问题调试了很久才能解决。
总结
以上是生活随笔为你收集整理的题目二:课程设计报告的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 重构业务系统,我是这样做的
- 下一篇: RC延时电路简要分析