C++類實現(xiàn)通訊錄功能
本文實例為大家分享了C++類實現(xiàn)通訊錄功能的具體代碼,供大家參考,具體內(nèi)容如下
軟件使用的是Microsoft Visual Studio
編寫通訊錄之前,先思考一下要實現(xiàn)什么功能,大概的結(jié)構(gòu),要創(chuàng)建幾個類等等。
首先,是思考要實現(xiàn)什么功能。
一般的通訊錄有添加,刪除,修改,查找,顯示等功能,一般聯(lián)系人的信息包括:姓名,性別,年齡,電話號碼,家庭地址。
我們首先新建一個類,用來初始化姓名,年齡,性別,電話號碼,家庭地址,這幾個變量
#pragma once #include<iostream> #include<string> //#include "MailList.hpp" using namespace std; class MailList { public: ?? ?void setName(string);//給變量賦值函數(shù) ?? ?void setAge(string); ?? ?void setSex(string); ?? ?void setTel(string); ?? ?void setAddress(string); ?? ?string getName();//返回變量值函數(shù) ?? ?string getAge(); ?? ?string getSex(); ?? ?string getTel(); ?? ?string getAddress(); ? private: ?? ?string name;//私有函數(shù)成員,定義變量 ?? ?string age; ?? ?string sex; ?? ?string tel; ?? ?string address; }; ? ? void MailList::setName(string name) { ?? ?this->name=name; } void MailList::setAge(string age) { ?? ?this->age=age; } void MailList::setSex(string sex) { ?? ?this->sex=sex; } void MailList::setTel(string tel) { ?? ?this->tel=tel; } void MailList::setAddress(string address) { ?? ?this->address=address; } string MailList::getName() { ?? ?return this->name; } string MailList::getAge() { ?? ?return this->age; } string MailList::getSex() { ?? ?return this->sex; } string MailList::getTel() { ?? ?return this->tel; } string MailList::getAddress() { ?? ?return this->address; }
這里也可以使用構(gòu)造函數(shù)初始化函數(shù)成員,構(gòu)造函數(shù)函數(shù)名與類名一樣。
然后,創(chuàng)建一個通訊錄管理類,先把總的結(jié)構(gòu)搭建起來
class MailListManager//通訊錄管理類 { public: ?? ?MailListManager();//構(gòu)造函數(shù) ?? ?void initList();//初始化通訊錄功能,在通訊錄里記錄為空時使用 ?? ?void insertList();//添加聯(lián)系人功能,在通訊錄里有記錄時使用 ?? ?void showList();//顯示聯(lián)系人功能,顯示通訊錄中所有聯(lián)系人的記錄 ?? ?void deleteList();//刪除聯(lián)系人功能 ?? ?void selectList();//查找聯(lián)系人功能 ?? ?void updateList();//修改聯(lián)系人功能 ?? ?void dropList();//清空通訊錄功能 ?? ?void save();//保存到文件,文件的寫入 ?? ?void loading();//加載,讀出文件 ?? ?string pw();//密碼加密(我沒能實現(xiàn)) ?? ?int exiet(string);//檢查聯(lián)系人是否存在 ? private: ? ?? ?MailList mail[Max];//數(shù)組,MailList類型,這屬于實例化對象 ?? ?int len;//計數(shù)器 ? }; MailListManager::MailListManager()//構(gòu)造函數(shù)就是用來初始化函數(shù)成員的,未初始化的函數(shù)成員不可用。這里初始化一下計數(shù)器 { ?? ?len = 0; } int MailListManager::exiet(string name)//定義檢查函數(shù),檢查聯(lián)系人是否存在,以姓名的匹配為條件 { ? } void MailListManager::loading()//定義加載函數(shù) { ? } void MailListManager::save()//定義保存函數(shù) { ? } void MailListManager::initList()//定義初始化函數(shù) { ? } void MailListManager::insertList()//定義添加函數(shù) { ? } void MailListManager::showList()//定義顯示函數(shù) { ? } void MailListManager::updateList()//定義修改函數(shù) { ? } void MailListManager::deleteList()//定義刪除函數(shù) { ? } void MailListManager::selectList()//定義查找函數(shù) { ? } void MailListManager::dropList()//定義清空函數(shù) { ? }
總結(jié)構(gòu)搭建好后,再開始編寫里面的定義內(nèi)容。
//這里聲明部分就不顯示了,直接看定義 ? void MailListManager::loading()//加載函數(shù)的定義 { ?? ?len = 0;//計數(shù)器len,每次調(diào)用加載函數(shù)的時候都要重新初始化為0,這樣做是防止之后添加聯(lián)系人時重復(fù)加載導致保存多次。 ?? ?string name, sex, age, tel, address;//局部變量,每次使用都要聲明一下的 ?? ?ifstream in;//實例化文件類“fstream”對象 ?? ?in.open("maillist/mail.txt");//打開文件 ?? ?if (!in)//如果文件未打開 ?? ?{ ? ?? ??? ?cout << "--文件打開失敗--" << endl; ?? ??? ?system("pause"); ?? ?} ?? ?else ?? ?{ ?? ??? ?while (!in.eof())//如果未達到文件末尾 ?? ??? ?{ ?? ??? ??? ?in >> name >> age >> sex >> tel >> address; ?? ??? ??? ?if (in.fail())break;//ifstream類的作用是從文件中讀出數(shù)據(jù)到控制臺上,但沒有顯示出來,這就相當于再次賦值給數(shù)組,就是給之前聲明的MailList類的數(shù)組,所以這里使用數(shù)組mail[*].***保存數(shù)據(jù),因為不知道到底有多少數(shù)據(jù),所以用死循環(huán)來控制,跳出條件是達到文件末尾就跳出,這樣就可以保證將文件中的內(nèi)容全部存到數(shù)組里 ?? ??? ??? ?mail[len].setName(name); ?? ??? ??? ?mail[len].setAge(age); ?? ??? ??? ?mail[len].setSex(sex); ?? ??? ??? ?mail[len].setTel(tel); ?? ??? ??? ?mail[len].setAddress(address); ?? ??? ??? ?len++; ?? ??? ?} ?? ?} ?? ?in.close(); } int MailListManager::exiet(string name)//檢驗聯(lián)系人是否存在 { ?? ?for (int i = 0; i < len; i++)//每當調(diào)用檢驗聯(lián)系人的函數(shù)之前,一定要加載一下,讓數(shù)據(jù)全部保存到控制臺的數(shù)組中,且要從控制臺輸入一個名字傳給檢驗聯(lián)系人函數(shù),讓傳入的名字與數(shù)組中的數(shù)據(jù)逐一對比,從而檢驗聯(lián)系人是否存在 ?? ?{ ?? ??? ?if (mail[i].getName() == name) ?? ??? ?{ ?? ??? ??? ?return i;//如果存在,返回數(shù)組下標 ?? ??? ?} ?? ?} ?? ?return -1;//不存在,返回-1 } void MailListManager::save()//保存文件函數(shù) { ?? ?ofstream out;//ofstream類的作用是把控制臺上的數(shù)據(jù)寫入文件 ?? ?out.open("maillist/mail.txt");//打開文件 ?? ?if (!out)//如果文件未打開 ?? ?{ ?? ??? ?cout << "--文件打開失敗--" << endl; ?? ?} ?? ?else ?? ?{ ?? ??? ?for (int i = 0; i < len; i++)//這里的計數(shù)器len的值來自之后定義的函數(shù)中,len的值取決于誰調(diào)用的保存函數(shù) ?? ??? ?{ ?? ??? ??? ?out << mail[i].getName() << " " << mail[i].getAge() << " " << mail[i].getSex() << " " << mail[i].getTel() << " " << mail[i].getAddress() << endl; ?? ??? ?} ?? ?} ? ? ?? ?out.close(); } ? ? void MailListManager::initList()//初始化聯(lián)系人。之前我先寫了添加,修改,刪除,在解決一些問題的時候發(fā)現(xiàn)添加功能調(diào)用加載函數(shù)與刪除修改功能調(diào)用加載函數(shù)有沖突,導致重復(fù)顯示,所以在老師的幫助下加入了這個初始化聯(lián)系人功能,當然有更好的方法,只是我暫時還不會用(TvT) { ?? ?string name, age, sex, tel, address; ?? ?cout << "請輸入聯(lián)系人的信息(在姓名后輸入stop停止輸入):" << endl; ?? ?while (true) ?? ?{ ?? ??? ?cout << "姓名:"; ?? ??? ?cin >> name; ?? ??? ?if (name == "stop") break; ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?mail[len].setName(name);//簡單的調(diào)用函數(shù),不想講了 ?? ??? ??? ?cout << "年齡:"; ?? ??? ??? ?cin >> age; ?? ??? ??? ?mail[len].setAge(age); ?? ??? ??? ?cout << "性別:"; ?? ??? ??? ?cin >> sex; ?? ??? ??? ?mail[len].setSex(sex); ?? ??? ??? ?cout << "電話號碼:"; ?? ??? ??? ?cin >> tel; ?? ??? ??? ?mail[len].setTel(tel); ?? ??? ??? ?cout << "家庭地址:"; ?? ??? ??? ?cin >> address; ?? ??? ??? ?mail[len].setAddress(address); ?? ??? ??? ?len++;//這個len最終的值會給到save.....emmm..說“給”好像不太準確,找不到合適的詞了,反正代碼順著往下執(zhí),len加到最后不會再變了,save直接用它。 ?? ??? ?} ?? ?} ?? ?save(); ? } void MailListManager::insertList()//添加聯(lián)系人函數(shù) { ?? ?this->loading();//加載一下初始化聯(lián)系人的數(shù)據(jù) ?? ?string name, age, sex, tel, address;//局部變量要重新聲明 ?? ?cout << "請輸入插入聯(lián)系人的數(shù)量:" << endl; ?? ?int count = 0;//再來個計數(shù)器,控制每次想要添加的聯(lián)系人的數(shù)量 ?? ?cin >> count;//讓用戶來指定每次添加多少人 ?? ?for (int i = 0; i < count; i++) ?? ?{ ?? ??? ?cout << "姓名:"; ?? ??? ?cin >> name; ?? ??? ?mail[i].setName(name);//函數(shù)調(diào)用過程,還是說一下吧。mail[]數(shù)組的類型是MailList,然后它是MailListManager這個類的函數(shù)成員,通過它作為橋梁來調(diào)用MailListManager類成員函數(shù) ?? ??? ?cout << "年齡:"; ?? ??? ?cin >> age; ?? ??? ?mail[i].setAge(age); ?? ??? ?cout << "性別:"; ?? ??? ?cin >> sex; ?? ??? ?mail[i].setSex(sex); ?? ??? ?cout << "電話號碼:"; ?? ??? ?cin >> tel; ?? ??? ?mail[i].setTel(tel); ?? ??? ?cout << "家庭地址:"; ?? ??? ?cin >> address; ?? ??? ?mail[i].setAddress(address); ?? ?} ?? ?ofstream out;//添加有單獨的保存文件定義,因為只有添加功能需要使用文件追加 ?? ?out.open("maillist/mail.txt", ios::app); ?? ?if (!out) ?? ?{ ?? ??? ?cout << "--文件打開失敗--" << endl; ?? ?} ?? ?else ?? ?{ ?? ??? ?for (int i = 0; i < count; i++) ?? ??? ?{ ?? ??? ??? ?out << mail[i].getName() << " " << mail[i].getAge() << " " << mail[i].getSex() << " " << mail[i].getTel() << " " << mail[i].getAddress() << endl; ?? ??? ?} ?? ??? ?out.close(); ?? ?} } void MailListManager::showList()//顯示聯(lián)系人 { ? ?? ?loading(); ?? ?MailList temp; ?? ?for (int j=0;j<len;j++)//這里是給聯(lián)系人排序,通過名字排序 ?? ?{ ?? ??? ?for (int i = j+1; i < len; i++) ?? ??? ?{ ?? ??? ??? ?if (mail[j].getName() > mail[i].getName()) ?? ??? ??? ?{ ?? ??? ??? ??? ?temp = mail[i]; ?? ??? ??? ??? ?mail[i] = mail[j];//交換 ?? ??? ??? ??? ?mail[j] = temp;?? ? ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?} ?? ?for (int i = 0; i < len; i++)//這里的len值來自loading() ?? ?{ ?? ??? ?cout << setw(10) << mail[i].getName() << " ?" << setw(8) << mail[i].getAge() << " ?" << setw(4) << ?? ??? ??? ?mail[i].getSex() << " ?" << setw(15) << mail[i].getTel() << " ?" << setw(20) << mail[i].getAddress();//setw()是格式控制函數(shù) ?? ??? ?cout << endl << endl; ?? ?} } void MailListManager::updateList()//修改聯(lián)系人,修改聯(lián)系人之前要找到這個聯(lián)系人,存在才能刪除 { ?? ?loading();//加載一下 ?? ?string name, age, sex, tel, address; ?? ?cout << "請輸入要修改的聯(lián)系人姓名:"; ?? ?cin >> name; ?? ?int ret = exiet(name);//檢驗一下是否存在,存在exiet()會返回該聯(lián)系人所在的數(shù)組下標,在這個數(shù)組下標里重新輸入一遍數(shù)據(jù)覆蓋掉原有數(shù)據(jù)就是修改聯(lián)系人了 ?? ?if (ret != -1) ?? ?{ ?? ??? ?cout << "請重新輸入聯(lián)系人信息:" << endl; ?? ??? ?cout << "姓名:"; ?? ??? ?cin >> name; ?? ??? ?mail[ret].setName(name); ?? ??? ?cout << "年齡:"; ?? ??? ?cin >> age; ?? ??? ?mail[ret].setAge(age); ?? ??? ?cout << "性別:"; ?? ??? ?cin >> sex; ?? ??? ?mail[ret].setSex(sex); ?? ??? ?cout << "電話號碼:"; ?? ??? ?cin >> tel; ?? ??? ?mail[ret].setTel(tel); ?? ??? ?cout << "家庭地址:"; ?? ??? ?cin >> address; ?? ??? ?mail[ret].setAddress(address); ?? ?} ?? ?else ?? ??? ?cout << "啊哦~聯(lián)系人不存在喔(-o-)"; ?? ?save();//改完記得重新保存一下,不然是沒有任何改動的哦 } void MailListManager::deleteList()//刪除聯(lián)系人,理同修改一樣,只不過是信息的覆蓋變?yōu)榱藘?nèi)容前移覆蓋 { ?? ?loading(); ?? ?string name; ?? ?int o; ?? ?cout << "請輸入要刪除的聯(lián)系人的姓名: ?"; ?? ?cin >> name; ?? ?int ret = exiet(name); ?? ?if (ret == -1) ?? ?{ ?? ??? ?cout << "啊哦~聯(lián)系人不存在喔(-o-)"; ?? ?} ?? ?else ?? ?{ ?? ??? ?cout << "確定要刪除嗎?" << endl << "1.確定" << " ? ?" << "2.我再想想" << endl << "請選擇:"; ?? ??? ?cin >> o; ?? ??? ?if (o == 2) ?? ??? ??? ?cout << "好的~"; ?? ??? ?else ?? ??? ?{ ? ?? ??? ??? ?for (int i = ret; i < len; i++) ?? ??? ??? ?{ ?? ??? ??? ??? ?mail[i] = mail[i + 1]; ?? ??? ??? ?} ? ? ?? ??? ??? ?cout << "刪除成功!"; ?? ??? ?} ?? ?} ?? ?save(); ? } void MailListManager::selectList()//查找聯(lián)系人,查找聯(lián)系人就更簡單啦,調(diào)用一下檢驗存在的函數(shù),然后根據(jù)下標直接輸出此聯(lián)系人信息就好 { ?? ?loading(); ?? ?string name; ?? ?cout << "請輸入要查找的人的姓名: ? "; ?? ?cin >> name; ?? ?int ret = exiet(name); ?? ?if (ret != -1) ?? ?{ ?? ??? ?cout << "姓名:" << mail[ret].getName() << endl; ?? ??? ?cout << "年齡:" << mail[ret].getAge() << endl; ?? ??? ?cout << "性別:" << mail[ret].getSex() << endl; ?? ??? ?cout << "電話號碼:" << mail[ret].getTel() << endl; ?? ??? ?cout << "家庭地址:" << mail[ret].getAddress() << endl; ?? ?} ?? ?else ?? ??? ?cout << "啊哦~聯(lián)系人不存在喔(-o-)"; } void MailListManager::dropList()//清空通訊錄,重新寫入文件,寫入一個空字符覆蓋之前的數(shù)據(jù),就清空啦 { ?? ?int n; ?? ?cout << "確定清空嗎?" << endl << " ?" << "1.YES" << " ? " << "2.NO" << "請選擇:"; ?? ?cin >> n; ?? ?if (n == 2) ?? ?{ ?? ??? ?cout << "好的~"; ?? ?} ?? ?else ?? ?{ ?? ??? ?ofstream out; ?? ??? ?out.open("maillist/mail.txt"); ?? ??? ?if (!out) ?? ??? ?{ ?? ??? ??? ?cout << "--文件打開失敗--" << endl; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?out << " "; ?? ??? ??? ?cout << "清除成功" << endl; ?? ??? ?} ?? ??? ?out.close(); ?? ?} } string MailListManager::pw()//密碼加密,未完成 { ?? ?char psw[100] = { 0 }, c; ?? ?int i = 0; /*?? ?cin >> c*/; ?? ?while ((c = getch()) != '\r') ?? ?{ ?? ??? ?if (c != '\b') ?? ??? ?{ ?? ??? ??? ?cout << "*"; ?? ??? ??? ?psw[i++]; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?cout << "\b \b"; ?? ??? ??? ?i--; ?? ??? ?} ?? ?} ?? ?psw[i] = '\0'; ?? ?cout << psw; ? ?? }
然后再寫個登陸類
#include<iostream> #include<fstream> #include<string> using namespace std; class User { public: ?? ?User(); ?? ?void loading(); ?? ?int check(string); ?? ?int login(string, string); ?? ?void sign(string,string); private: ?? ?string s[50]; ?? ?int len; ? }; User::User() { ?? ?len = 0; } ? void User::loading()//加載函數(shù) { ?? ?string name, password; ?? ?ifstream in; ?? ?in.open("User/user.txt"); ?? ?if (!in) ?? ?{ ?? ??? ?cout << "錯誤!"; ?? ?} ?? ?else ?? ?{ ?? ??? ?while (!in.eof()) ?? ??? ?{ ?? ??? ??? ?in >> s[len]; ?? ??? ??? ?if (in.fail())break; ?? ??? ??? ?len++; ?? ??? ?} ? ?? ?} ?? ?in.close(); } int User::check(string name)//檢驗函數(shù) { ?? ?loading(); ?? ?for (int i = 0; i < len; i=i+2) ?? ?{ ?? ??? ?if (name == s[i]) ?? ??? ?{ ?? ??? ??? ?return i; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?return -1; ?? ??? ?} ?? ?} } int User::login(string name, string password)//登陸函數(shù) { ?? ?if (check(name) == -1) ?? ?{ ?? ??? ?cout << "用戶根本不存在喔!"; ?? ?} ?? ?else ?? ?{ ?? ??? ?if (s[check(name) + 1] == password) ?? ??? ?{ ?? ??? ??? ?return 1; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?cout << "密碼輸入錯誤!"; ?? ??? ?} ?? ?} } void User::sign(string name,string password)//注冊函數(shù) { ?? ?loading(); ?? ?if (check(name) != -1)//已有用戶名 ?? ?{ ?? ??? ?cout << "用戶名已存在!"; ?? ?} ?? ?else ?? ?{ ?? ??? ?ofstream out; ?? ??? ?out.open("User/user.txt", ios::app); ?? ??? ?if (!out) ?? ??? ?{ ?? ??? ??? ?cout << "文件打開失敗!"; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?out <<endl<< name<<" "<< password; ?? ??? ?} ?? ??? ?out.close(); ?? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?注冊成功!"; ?? ??? ?system("pause"); ?? ?} }
登陸類的加載函數(shù),檢驗函數(shù)邏輯同之前管理類的一樣,登陸函數(shù)與注冊函數(shù),實際上就是文件讀出與寫入。
最后,寫主函數(shù)
#include"MailListManager.hpp" #include"userl.hpp" void menu() { ?? ?cout << endl << endl << endl ; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-----------(^O^)---------" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 1、初始化聯(lián)系人 ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 2、顯示聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 3、刪除聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 4、查找聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 5、修改聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 6、清空聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 7、添加聯(lián)系人 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- ? ? 0、退出通訊錄 ? ? -" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?---------(·v·)---------" << endl; }//手動格式控制O(∩_∩)O哈哈~ int main() { ?? ?User u;//實例化對象 ?? ?int e; ?? ?cout << endl << endl << endl << endl << endl << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?******************歡迎使用通訊錄管理系統(tǒng)~******************" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?********************** ? ? ? ? ? ? ?***********************" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?**1.我已有賬戶,登錄**" <<" ? ? ? ? ? ? ?"<< "** 2.我沒有賬戶,注冊**" << endl; ?? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ?********************** ? ? ? ? ? ? ?***********************" << endl;//這是一個登陸界面,有賬戶才能管理通訊錄哦 ?? ?cout << endl<<endl; ?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 請選擇:"; ?? ?cin >> e; ?? ?if (e == 1) ?? ?{ ?? ??? ?while (true) ?? ??? ?{ ?? ??? ??? ?MailListManager* m = new MailListManager;//來個指針指向堆區(qū) ?? ??? ??? ?system("cls"); ?? ??? ??? ?string name, password; ?? ??? ??? ?cout <<endl<<endl<< " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請輸入:" << endl << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?用戶名:"; ?? ??? ??? ?cin >> name; ?? ??? ??? ?cout << endl << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?密碼:"; ?? ??? ??? ?cin >> password; ?? ??? ??? ?/*password = getch();*/ ?//這兩段本來是用來密碼加密的,但我沒實現(xiàn)所以注釋掉了 ?? ??? ??? ?/*m->pw();*/ ?? ??? ??? ?/*password = putch(getch());*/ ?? ??? ??? ?int i = u.login(name, password);//調(diào)用User里的登陸函數(shù),并將返回值給i,i=1就證明用戶名密碼輸入正確,反之就是輸入錯誤 ?? ??? ??? ?if (i == 1) ?? ??? ??? ?{ ?? ??? ??? ??? ?int n; ?? ??? ??? ??? ?while (true) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ??? ?cout <<endl<<endl<< " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?登錄成功!歡迎" << name << endl; ?? ??? ??? ??? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?通訊錄管理系統(tǒng)功能選項" << endl; ?? ??? ??? ??? ??? ?menu(); ?? ??? ??? ??? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請選擇:"; ?? ??? ??? ??? ??? ?cin >> n; ?? ??? ??? ??? ??? ?switch (n) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?case 7:system("cls"); m->insertList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 2:system("cls"); m->showList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 3:system("cls"); m->deleteList(); ?system("pause"); break; ?? ??? ??? ??? ??? ?case 4:system("cls"); m->selectList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 5:system("cls"); m->updateList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 6:system("cls"); m->dropList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 1:system("cls"); m->initList(); system("pause"); break;//調(diào)用各種函數(shù) ?? ??? ??? ??? ??? ?case 0:exit(0); break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?delete m; ?? ??? ??? ??? ?m = NULL; ?? ??? ??? ?} ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<endl<<endl << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請重新輸入" << endl; ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ?} ? ?? ?} ?? ?else ?? ?{ ?? ??? ?u.loading();//調(diào)用User類里的加載函數(shù) ?? ??? ?while (true) ?? ??? ?{ ?? ??? ??? ?system("cls"); ?? ??? ??? ?string name, password; ?? ??? ??? ?cout <<endl<<endl<< " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請輸入:" << endl << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?用戶名:"; ?? ??? ??? ?cin >> name; ?? ??? ??? ?if (u.check(name) !=-1) ?? ??? ??? ?{ ?? ??? ??? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?用戶名已存在!請重新輸入:"<<endl; ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?MailListManager* m = new MailListManager; ?? ??? ??? ??? ?cout << endl << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?密碼:"; ?? ??? ??? ??? ?cin >> password; ?? ??? ??? ??? ?/*m->pw();*/ ?? ??? ??? ??? ?u.sign(name, password);//調(diào)用User類的注冊函數(shù),保存注冊用戶信息 ?? ??? ??? ??? ?int n; ?? ??? ??? ??? ?while (true) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ??? ?cout <<endl<<endl<< " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?注冊成功!歡迎" << name << endl; ?? ??? ??? ??? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?通訊錄管理系統(tǒng)功能選項" << endl; ?? ??? ??? ??? ??? ?menu(); ?? ??? ??? ??? ??? ?cout << " ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?請選擇:"; ?? ??? ??? ??? ??? ?cin >> n; ?? ??? ??? ??? ??? ?switch (n) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?case 1:system("cls"); m->insertList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 2:system("cls"); m->showList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 3:system("cls"); m->deleteList(); ?system("pause"); break; ?? ??? ??? ??? ??? ?case 4:system("cls"); m->selectList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 5:system("cls"); m->updateList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 6:system("cls"); m->dropList(); system("pause"); break; ?? ??? ??? ??? ??? ?case 7:system("cls"); m->initList(); system("pause"); break;//調(diào)用各種函數(shù) ?? ??? ??? ??? ??? ?case 0: exit(0); break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?return 0; }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python擴展C/C++庫的方法(C轉(zhuǎn)換為Python)
這篇文章主要介紹了Python擴展C/C++庫的方法(C轉(zhuǎn)換為Python),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10C/C++ winsock實現(xiàn)不同設(shè)備實時通訊的示例代碼
這篇文章主要為大家詳細介紹了C/C++如何利用winsock連接實現(xiàn)不同設(shè)備實時通訊,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2023-09-09