题目二:课程设计报告
生活随笔
收集整理的這篇文章主要介紹了
题目二:课程设计报告
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目2.李剛是一愛折騰的人,當然愛折騰的人均有夢想,他想當中國的蓋次呢。可不,現(xiàn)在個人好友信息多了,復雜了,他想制作一個個人通訊錄的制作管理軟件。?剛好這個學期學了數(shù)據(jù)結(jié)構(gòu)課,所以他準備使用數(shù)據(jù)結(jié)構(gòu)知識來實現(xiàn)了。并考慮使用雙向鏈表作數(shù)據(jù)結(jié)構(gòu)。并制定了初步要求:
(1)每個好友信息包含姓名、性別、住址、郵編、幾歲、電話、QQ、微信帳號、生日等。
(2)作為一個完整的系統(tǒng),應具有友好的界面和較強的容錯能力。
一、代碼顯示
// 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. 增加聯(lián)系人--|\n");printf(" |---2. 刪除聯(lián)系人--|\n");printf(" |---3. 修改聯(lián)系人--|\n");printf(" |---4. 顯示聯(lián)系人--|\n");printf(" |---5. 查詢聯(lián)系人--|\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(" | 增加聯(lián)系人 |\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<<"無聯(lián)系人可以刪除,輸入任意鍵繼續(xù)操作";getch();return ;}system("cls");printf(" |-----------------------------------|\n");printf(" | 刪除聯(lián)系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------輸入需要刪除的聯(lián)系人姓名-------------|\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<<"無此聯(lián)系人,刪除失敗,輸入任意鍵回主菜單";getch();return ; } void modify_contact() {contact *this_contact;string name;string choose;system("cls");printf(" |-----------------------------------|\n");printf(" | 修改聯(lián)系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------輸入需要修改的聯(lián)系人姓名-------------|\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(" | 修改聯(lián)系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");switch(i){case 0: printf(" |-----------輸入需要修改的聯(lián)系人姓名-------------|\n");cout<<"輸入修改后的名字,無需修改請按0回車\n";cout<<this_contact->getname()<<endl;cin>>choose;if (choose != "0"){this_contact->addname(choose);}break;case 1: printf(" |-----------輸入需要修改的聯(lián)系人電話-------------|\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<<"無此聯(lián)系人,修改失敗,輸入任意鍵回主菜單";getch();return ;} void query_contact() {contact *this_contact;string name;system("cls");printf(" |-----------------------------------|\n");printf(" | 查找聯(lián)系人 |\n");printf(" |-----------------------------------|\n");printf("\n");printf("\n");printf(" |-----------輸入需要查找的聯(lián)系人姓名-------------|\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<<"無此聯(lián)系人,查找失敗,輸入任意鍵回主菜單";getch();return ; } void display_contact() {system("cls");contact *this_contact;char format[]=" ";this_contact = root.next_contact;printf("|-----------------------------------|\n");printf("| 聯(lián)系人 |\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、增加聯(lián)系人:劉小明
3、顯示聯(lián)系人
4、刪除聯(lián)系人:湯瓜皮
5、修改聯(lián)系人:劉小明
6、查找聯(lián)系人:王心桐
7、退出系統(tǒng)
三、個人總結(jié)
? ? ?學習編程這門課程,真的需要花很多心思和時間,而且需要堅持不懈,每天都花上一些時間去敲一下代碼,想要更深入了解的話,甚至可能要經(jīng)過上百次乃至上千次地對代碼進行調(diào)試。可惜自己太懶并沒用做到這一點,所以在做編程時都覺得和吃力,感覺自己什么都好想沒都不懂。這次連一些基本的問題調(diào)試了很久才能解決。
總結(jié)
以上是生活随笔為你收集整理的题目二:课程设计报告的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 重构业务系统,我是这样做的
- 下一篇: RC延时电路简要分析