能幫忙看看哪里的問題嗎,一直運行不出來
/*通信錄的設計
基本要求:
定義date類,至少包括年月日;
定義person類,至少包括姓名、性別和出生日期;
定義人員(staff)類,從person類派生,至少包括電話、地址、郵政編碼、郵箱、QQ號和類別(例如:同學、朋友等)。
功能要求:
1、設計選單實作功能選擇;
2、輸入功能:輸入人員資訊,并保存到檔案中;
3、查詢功能:
1)能夠根據姓名、電話精確查詢人員資訊;
2)能夠根據地址進行模糊查詢人員資訊;
3)根據人員類別查詢人員資訊
4、根據姓名對人員資訊排序輸出
5、能根據姓名、電話修改人員資訊
6、能根據姓名、電話洗掉人員資訊
*/
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<iterator>
using namespace std;
class date
{
private:
int year, month, day;
public:
date() { }
date(int a, int b, int c) :year(a), month(b), day(c)
{
cout << "www" << endl;
}
date(date &m)
{
year = m.year;
month = m.month;
day = m.day;
}
void set_date()
{
cout << "請輸入出生日期:" << endl;
cin >> year >> month >> day;
}
void show_date()
{
cout << "出生日期是:" << year << "年" << month << "月" << day << "日";
}
~date() { }
};
class person
{
private:
string name;
string sex;
date birthday;
public:
person() { }
person(string x, string y) :name(x), sex(y), birthday()
{
cout << "本帶參函式已被呼叫" << endl;
}
void set_person()
{
cout << "請輸入姓名:" << endl;
cin >> name;
cout << "請輸入性別:" << endl;
cin >> sex;
birthday.set_date();
}
void show_person()
{
cout << "姓名是:" << name << endl;
cout << "性別是:" << sex << endl;
birthday.show_date();
}
~person()
{
cout << "aaa" << endl;
}
void set_name(string g)
{
name = g;
}
string get_name()
{
return name;
}
};
class staff :public person
{
private:
string telephone;
string address;
int post_code;
string mailbox;
string qq;
string category;
person people;
public:
staff() { }
staff(string x, string y, string tel, string add, string mai, int pos, string q, string cat) :person(x, y), telephone(tel), address(add), post_code(pos), mailbox(mai), qq(q), category(cat)
{
}
void set_staff()
{
people.set_person();
cout << "請輸入電話號碼:" << endl;
cin >> telephone;
cout << "請輸入地址:" << endl;
cin >> address;
cout << "請輸入郵政編碼:" << endl;
cin >> post_code;
cout << "請輸入郵箱:" << endl;
cin >> mailbox;
cout << "請輸入QQ號碼:" << endl;
cin >> qq;
cout << "請輸入類別:" << endl;
cin >> category;
}
void set_telephone(string bbb)
{
telephone = bbb;
}
string get_telephone()
{
return telephone;
}
void set_address(string add)
{
address = add;
}
string get_address()
{
return address;
}
void set_category(string cat)
{
category = cat;
}
string get_category()
{
return category;
}
void show_staff()
{
people.show_person();
cout << "電話號碼是:" << telephone << endl;
cout << "地址是:" << address << endl;
cout << "郵政編碼是:" << post_code << endl;
cout << "郵箱是:" << mailbox << endl;
cout << "QQ號碼是:" << qq << endl;
cout << "類別是:" << category << endl;
}
};
class stafftool
{
public:
friend class staff;
void show_menu()
{
cout << "--歡迎使用通訊錄管理系統--" << endl;
cout << "--------------------------" << endl;
cout << " 1.輸入人員資訊" << endl;
cout << "2.根據姓名或電話查詢資訊" << endl;
cout << " 3.根據地址查詢資訊" << endl;
cout << " 4.根據人員類別查詢資訊" << endl;
cout << " 5.根據姓名對資訊排序輸出" << endl;
cout << "6.根據姓名或電話修改資訊" << endl;
cout << "7.根據姓名或電話洗掉資訊" << endl;
cout << "--------------------------" << endl;
}
vector<staff> v;
vector<staff> v1;
vector<staff>::iterator it;
int search_staff() //2.根據姓名或電話查詢資訊
{
int h;
string s,k;
long len;
len = v.size();
cout << "請輸入查找方式:1.姓名查找 2電話號碼查找" << endl;
cin >> h;
if (h == 0)
{
cout << "出錯了!" << endl;
return 0;
}
else if (h == 1)
{
cout << "請輸入待查找的姓名:" << endl;
cin >> s;
for (int i = 0; i < v.size(); i++)
{
if (v[i].get_name() == s)
{
cout << "資訊為:" << endl;
v[i].show_staff();
}
else
{
cout << "查無此人!" << endl;
}
}
}
else if (h == 2)
{
cout << "請輸入待查找的電話號碼:" << endl;
cin >> k;
for (int i = 0; i < v.size(); i++)
{
if (v[i].get_telephone() == k)
{
cout << "資訊為:" << endl;
v[i].show_staff();
}
else
{
cout << "查無此人!" << endl;
}
}
}
}
int ser_staff()
{
string temp;
cout << "請輸入待查找的地址:" << endl;
cin >> temp;
for (int i = 0; i < v.size(); i++)
{
if (v[i].get_address() == temp)
{
cout << "資訊為:" << endl;
v[i].show_staff();
}
else
{
cout << "查無此人!" << endl;
}
}
}//根據地址查詢資訊
int sec_staff()
{
string temp;
cout << "請輸入待查找的人員類別:" << endl;
cin >> temp;
for (int i = 0; i < v.size(); i++)
{
if (v[i].get_category() == temp)
{
cout << "資訊為:" << endl;
v[i].show_staff();
}
else
{
cout << "查無此人!" << endl;
}
}
}//根據人員類別查詢資訊
int delstaff() //根據姓名或電話洗掉資訊
{
int count = 0;
int opt;
string nam,tel;
cout << "請輸入待洗掉人員的姓名或電話:" << endl;
cin >> opt;
if (opt == 0)
{
cout << "出錯了!" << endl;
return 0;
}
else if (opt == 1)
{
cout << "請輸入待洗掉人員的姓名:" << endl;
cin >> nam;
for (it = v.begin(); it != v.end(); ++it)
{
if (nam.compare(it->get_name()) == 0)
{
++count;
}
else
{
break;
}
}
if (count == 0)
{
cout << "該姓名不存在!" << endl;
}
else
{
if (count == 1)
{
for (it = v.begin(); it != v.end();)
{
if (nam == it->get_name())
{
it = v.erase(it);
}
else
{
++it;
}
}
}
else
{
for (int i = 0; i < v.size(); i++)
{
if (nam == v[i].get_name())
{
it->show_staff();
}
}
}
}
}
else if (opt == 2)
{
cout << "請輸入待洗掉人員的電話:" << endl;
cin >> tel;
for (it = v.begin(); it != v.end(); ++it)
{
if (tel.compare(it->get_telephone()) == 0)
{
++count;
}
else
{
break;
}
}
if (count == 0)
{
cout << "該電話不存在!" << endl;
}
else
{
if (count == 1)
{
for (it = v.begin(); it != v.end();)
{
if (tel == it->get_telephone())
{
it = v.erase(it);
}
else
{
++it;
}
}
}
}
}
cout << "洗掉成功!" << endl;
}
int updatestaff() //根據姓名或電話修改資訊
{
int opt;
string nam, tel;
cout << "請輸入修改方式: 1.根據姓名修改 2.根據電話修改" << endl;
cin >> opt;
if (opt == 0)
{
cout << "出錯了!" << endl;
return 0;
}
else if (opt == 1)
{
cout << "請輸入待更改人員姓名:" << endl;
cin >> nam;
for (it = v.begin(); it != v.end(); ++it)
{
cout << "a" << endl;
if (nam.compare(it->get_name()) == 0)
{
it->set_staff();
cout << "修改成功" << endl;
}
}
}
else if (opt == 2)
{
cout << "請輸入待更改人員電話" << endl;
cin >> tel;
for (it = v.begin(); it != v.end(); ++it)
{
if (tel.compare(it->get_telephone()) == 0)
{
it->set_staff();
cout << "修改成功" << endl;
}
}
}
}
};
int main()
{
staff t;
stafftool t1;
vector<staff> v;
vector<staff>::iterator it;
ofstream ofs;
string s, temp;
char A;
int select = 0;//創建用戶選擇輸入的變數
while (true)
{
t1.show_menu();// 選單呼叫
cin >> select;
switch (select)
{
case 1:
ofs.open("E:\\課設\\通訊錄的設計", ios::in);
if (!ofs)
cout << "open failed" << endl;
else
cout << "請輸入人員資訊:" << endl;
t.set_staff(); //1.輸入人員資訊
v.push_back(t);
for (it = v.begin(); it != v.end(); it++)
{
it->set_staff();
cout << endl;
}
cout << "open success" << endl;
ofs.close();
case 2:
t1.search_staff(); //2.根據姓名或電話查詢資訊
break;
case 3:
t1.ser_staff(); //3.根據地址查詢資訊
break;
case 4:
t1.sec_staff(); ////根據人員類別查詢資訊
break;
case 5:
cout << "根據姓名對資訊排序輸出:" << endl;
for (int i = 0; i <= 2; i++)
{
for (int j = 2; j > i; j--)
{
s = v[i].get_name();
if (s.compare(v[j - 1].get_name()) > 0)
{
temp = v[j].get_name();
v[j].get_name() = v[j + 1].get_name();
v[j + 1].get_name() = temp;
}
}
}
cout << "輸出排序后的通訊錄:" << endl;
it->show_staff();
break; //5.根據姓名對資訊排序輸出
case 6:
t1.updatestaff(); //6.根據姓名或電話修改資訊
break;
case 7:
t1.delstaff(); //7.根據姓名或電話洗掉資訊
break;
default:
break;
}
cout << "請問是否繼續使用系統?是(y) 否(n)" << endl;
cin >> A;
if (A == 'y')
continue;
if (A == 'n')
break;
}
system("pause");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/228618.html
標籤:C++ 語言
下一篇:C語言
