大一时写的代码,很菜
实验要求:
综合运用面向对象程序设计的思想编写设计一个管理系统(如成績管理系統、学籍管理系统、計算器、通讯录等),并绘制其UML关系图。
参考代码:
//综合管理系统(通讯录)
//mail_list.h
#include<iostream>
using namespace std;
class date {
int year, month, day;
public:
date() {
}
~date() {
}
date(int year, int month, int day) :year(year), month(month), day(day) {
}
void setdate() {
cout << "输入出生日期" << endl;
cout << "年:";
cin >> year;
cout << "月:";
cin >> month;
cout << "日:";
cin >> day;
}
void showdate() {
cout << "出生日期:" << year << "年" << month << "月" << day << "日 ";
}
int getyear() {
return year;
}
int getmonth() {
return month;
}
int getday() {
return day;
}
};
class contact {
int qq, tele;
string vx; //用string类代替字符数组
public:
contact() {
}
~contact() {
}
contact(int qq, int tele, string vx) :qq(qq), tele(tele), vx(vx) {
}
void setcon() {
cout << "输入联系方式\nQQ:";
cin >> qq;
cout << "手机号码/电话号码:";
cin >> tele;
cout << "微信:";
cin >> vx;
}
void showcon() {
cout << "QQ:" << qq << " 手机号码/电话号码:" << tele << " 微信:" << vx << " ";
}
int getqq() {
return qq;
}
int gettele() {
return tele;
}
string getvx() {
return vx;
}
};
class mail_list :public date, public contact {
int sex, old;
string name;
date birthday;
contact con;
public:
mail_list(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string adress) :date(year, month, day), contact(qq, tele, vx), name(name), sex(sex), old(old), adress(adress) {
}
mail_list() {
}
~mail_list() {
}
string adress;
virtual void display() {
cout << "一切准备就绪!" << endl;
}
virtual void show() {
showmail();
}
string getname() {
return name;
}
int getsex() {
return sex;
}
int getold() {
return old;
}
void setmail() {
cout << "姓名:";
cin >> name;
cout << "性别(1---男,2---女):";
cin >> sex;
while (sex != 1 && sex != 2) {
cout << "输入错误,请按要求输入!" << endl;
cout << "性别(1---男,2---女):";
cin >> sex;
}
cout << "年龄:";
cin >> old;
setdate();
setcon();
}
void showmail() {
cout << "姓名:" << name << " 性别:";
sex == 1 ? cout << "男 " : cout << "女 ";
showdate();
cout << "年龄:" << old << " ";
showcon();
}
};
class family :virtual public mail_list {
string relationship;
public:
family(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string adress) :mail_list(name, sex, old, year, month, day, qq, tele, vx, adress) { //给基类的构造函数传参
}
family() {
}
~family() {
}
virtual void display() {
cout << "你可以对家人、";
}
string getrelationship() {
return relationship;
}
virtual void show() {
showfam();
}
void setfam() {
setmail();
cout << "关系:";
cin >> relationship;
}
void showfam() {
showmail();
cout << "关系:" << relationship << endl;
}
};
class friends :virtual public mail_list {
string work;
public:
friends() {
}
~friends() {
;
}
friends(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string work, string adress) :mail_list(name, sex, old, year, month, day, qq, tele, vx, adress), work(work) {
}
virtual void display() {
cout << "朋友、";
}
string getwork() {
return work;
}
string getadress() {
return adress;
}
virtual void show() {
showfri();
}
void setfri() {
setmail();
cout << "家庭住址:";
cin >> adress;
cout << "职业:";
cin >> work;
}
void showfri() {
showmail();
cout << "家庭住址:" << adress << " 职业:" << work << endl;
}
};
class classmates :virtual public mail_list, virtual public friends {
public:
classmates() {
}
~classmates() {
}
classmates(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string work, string adress) :mail_list(name, sex, old, year, month, day, qq, tele, vx, adress), friends(name, sex, old, year, month, day, qq, tele, vx, adress, work) {
}
virtual void display() {
cout << "同学、";
}
virtual void show() {
showmate();
}
void setmate() {
setfri();
}
void showmate() {
showfri();
}
};
class colleagues :virtual public mail_list {
string department;
public:
colleagues() {
}
~colleagues() {
}
colleagues(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string adress) :mail_list(name, sex, old, year, month, day, qq, tele, vx, adress) {
}
virtual void display() {
cout << "同事、";
}
virtual void show() {
showcoll();
}
string getdepartment() {
return department;
}
string getadress() {
return adress;
}
void setcoll() {
setmail();
cout << "家庭住址:";
cin >> adress;
cout << "部门:";
cin >> department;
}
void showcoll() {
showmail();
cout << "家庭住址:" << adress << " 部门:" << department << endl;
}
};
class lover :public family, public classmates, virtual public friends, public colleagues {
public:
lover() {
}
~lover() {
}
lover(string name, int sex, int old, int year, int month, int day, int qq, int tele, string vx, string work, string adress) :mail_list(name, sex, old, year, month, day, qq, tele, vx, adress), friends(name, sex, old, year, month, day, qq, tele, vx, adress, work) {
}
string name, department, adress, work, relationship, vx;
int sex, old, year, month, day, qq, tele;
string getname() {
return name;
}
void show1() { //显示家人
cout << "姓名:" << name << " 性别:";
sex == 1 ? cout << "男 " : cout << "女 ";
cout << "出生日期:" << year << "年" << month << "月" << day << "日 ";
cout << "年龄:" << old << " ";
cout << "QQ:" << qq << " 手机号码/电话号码:" << tele << " 微信:" << vx << " 关系:" << relationship << endl;
}
void show2() { //显示朋友
cout << "姓名:" << name << " 性别:";
sex == 1 ? cout << "男 " : cout << "女 ";
cout << "出生日期:" << year << "年" << month << "月" << day << "日 ";
cout << "年龄:" << old << " ";
cout << "QQ:" << qq << " 手机号码/电话号码:" << tele << " 微信:" << vx << endl;
cout << "家庭住址:" << adress << " 职业:" << work << endl;
}
void show3() { //显示同学
cout << "姓名:" << name << " 性别:";
sex == 1 ? cout << "男 " : cout << "女 ";
cout << "出生日期:" << year << "年" << month << "月" << day << "日 ";
cout << "年龄:" << old << " ";
cout << "QQ:" << qq << " 手机号码/电话号码:" << tele << " 微信:" << vx << endl;
cout << "家庭住址:" << adress << " 职业:" << work << endl;
}
void show4() { //显示同事
cout << "姓名:" << name << " 性别:";
sex == 1 ? cout << "男 " : cout << "女 ";
cout << "出生日期:" << year << "年" << month << "月" << day << "日 ";
cout << "年龄:" << old << " ";
cout << "QQ:" << qq << " 手机号码/电话号码:" << tele << " 微信:" << vx << endl;
cout << "家庭住址:" << adress << " 部门:" << department << endl;
}
virtual void display() {
cout << "特别关心等联系人进行操作!" << endl;
}
virtual void show() {
}
};
//mail_list.cpp
#include<iostream>
#include<vector>
#include"mail_list.h"
#define MAX 100
using namespace std;
int c1 = -1, c2 = -1, c3 = -1, c4 = -1, c5 = -1, c6 = -1, c7 = -1, c8 = -1;
int k = 1;
friends t0("小李", 1, 18, 2002, 8, 11, 6666, 8888, "9999", "腾讯公司顶级程序员", "天美工作室");
vector<family>f(MAX);
vector<friends>fri(MAX);
vector<classmates>c(MAX);
vector<colleagues>coll(MAX);
vector<lover>l(MAX);
vector<lover>ll(MAX);
vector<lover>lll(MAX);
vector<lover>llll(MAX);
void Show(mail_list* ptr) {
ptr->show();
}
void showMenu() {
cout << "************************" << endl;
cout << "* 1.添加联系人 *" << endl;
cout << "************************" << endl;
cout << "* 2.显示联系人 *" << endl;
cout << "************************" << endl;
cout << "* 3.删除联系人 *" << endl;
cout << "************************" << endl;
cout << "* 4.查找联系人 *" << endl;
cout << "************************" << endl;
cout << "* 5.修改联系人 *" << endl;
cout << "************************" << endl;
cout << "* 6.清空联系人 *" << endl;
cout << "************************" << endl;
cout << "* 7.退出通讯录 *" << endl;
cout << "************************" << endl;
}
void addmail() { //添加联系人
int add;
if (true) {
cout << "添加联系人:" << endl;
cout << "******************" << endl;
cout << "*1.添加家人 *" << endl;
cout << "******************" << endl;
cout << "*2.添加朋友 *" << endl;
cout << "******************" << endl;
cout << "*3.添加同学 *" << endl;
cout << "******************" << endl;
cout << "*4.添加同事 *" << endl;
cout << "******************" << endl;
cout << "*5.添加特别关心 *" << endl;
cout << "******************" << endl;
cin >> add;
switch (add) {
case 1:
c1++;
if (c1 == MAX+1) {
cout << "家人已满!\n";
}
else
{
f[c1].setfam();
cout << "添加成功!" << endl;
}
break;
case 2:
c2++;
if (c2 == MAX + 1) {
cout << "朋友已满!\n";
}
else {
fri[c2].setfri();
cout << "添加成功!" << endl;
}
break;
case 3:
c3++;
if (c3 == MAX + 1) {
cout << "同学已满!\n";
}
else {
c[c3].setmate();
cout << "添加成功!" << endl;
}
break;
case 4:
c4++;
if (c4 == MAX + 1) {
cout << "同事已满!\n";
}
else {
coll[c4].setcoll();
cout << "添加成功!" << endl;
}
break;
case 5: //起始
int i, m, t = 0;
string n;
if (true) {
cout << "添加特别关心:" << endl;
cout << "**************" << endl;
cout << "*1.家人 *" << endl;
cout << "**************" << endl;
cout << "*2.朋友 *" << endl;
cout << "**************" << endl;
cout << "*3.同学 *" << endl;
cout << "**************" << endl;
cout << "*4.同事 *" << endl;
cout << "**************" << endl;
cin >> m;
switch (m) {
case 1:
c5++;
if (c5 == MAX + 1) {
cout << "家人已满!\n";
}
else {
cout << "请输入TA的姓名" << endl;
cin >> n;
for (i = 0; i < c1 + 1; i++) {
if (n == f[i].getname()) {
t = 1;
l[c5].name = f[i].getname();
l[c5].old = f[i].getold();
l[c5].sex = f[i].getsex();
l[c5].year = f[i].getyear();
l[c5].month = f[i].getmonth();
l[c5].day = f[i].getday();
l[c5].qq = f[i].getqq();
l[c5].tele = f[i].gettele();
l[c5].vx = f[i].getvx();
l[c5].relationship = f[i].getrelationship();
cout << "添加成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
c5--;
}
}
break;
case 2:
c6++;
if (c6 == MAX + 1) {
cout << "朋友已满!\n";
}
else {
cout << "请输入TA的姓名" << endl;
cin >> n;
if (n == "小李") {
t = 1;
ll[c6].name = t0.getname();
ll[c6].old = t0.getold();
ll[c6].sex = t0.getsex();
ll[c6].year = t0.getyear();
ll[c6].month = t0.getmonth();
ll[c6].day = t0.getday();
ll[c6].qq = t0.getqq();
ll[c6].tele = t0.gettele();
ll[c6].vx = t0.getvx();
ll[c6].adress = t0.getadress();
ll[c6].work = t0.getwork();
cout << "添加成功!" << endl;
}
else {
for (i = 0; i < c2 + 1; i++) {
if (n == fri[i].getname()) {
t = 1;
ll[c6].name = fri[i].getname();
ll[c6].old = fri[i].getold();
ll[c6].sex = fri[i].getsex();
ll[c6].year = fri[i].getyear();
ll[c6].month = fri[i].getmonth();
ll[c6].day = fri[i].getday();
ll[c6].qq = fri[i].getqq();
ll[c6].tele = fri[i].gettele();
ll[c6].vx = fri[i].getvx();
ll[c6].adress = fri[i].getadress();
ll[c6].work = fri[i].getwork();
cout << "添加成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
c6--;
}
}
}
break;
case 3:
c7++;
if (c7 == MAX + 1) {
cout << "同学已满!\n";
}
else {
cout << "请输入TA的姓名" << endl;
cin >> n;
for (i = 0; i < c3 + 1; i++) {
if (n == c[i].getname()) {
t = 1;
lll[c7].name = c[i].getname();
lll[c7].old = c[i].getold();
lll[c7].sex = c[i].getsex();
lll[c7].year = c[i].getyear();
lll[c7].month = c[i].getmonth();
lll[c7].day = c[i].getday();
lll[c7].qq = c[i].getqq();
lll[c7].tele = c[i].gettele();
lll[c7].vx = c[i].getvx();
lll[c7].adress = c[i].getadress();
lll[c7].work = c[i].getwork();
cout << "添加成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
c7--;
}
}
break;
case 4:
c8++;
if (c8 == MAX + 1) {
cout << "同事已满!\n";
}
else {
cout << "请输入TA的姓名" << endl;
cin >> n;
for (i = 0; i < c4 + 1; i++) {
if (n == coll[i].getname()) {
t = 1;
llll[c8].name = coll[i].getname();
llll[c8].old = coll[i].getold();
llll[c8].sex = coll[i].getsex();
llll[c8].year = coll[i].getyear();
llll[c8].month = coll[i].getmonth();
llll[c8].day = coll[i].getday();
llll[c8].qq = coll[i].getqq();
llll[c8].tele = coll[i].gettele();
llll[c8].vx = coll[i].getvx();
llll[c8].adress = coll[i].getadress();
llll[c8].department = coll[i].getdepartment();
cout << "添加成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
c8--;
}
}
break;
break;
}
} //结束
}
system("pause");
system("cls"); //清屏
}
}
void showmail_list() { //显示联系人
int i, t = 0, m = 0, n = 0, r = 0, q = 0;
if (c1 == -1 && c2 == -1 && c3 == -1 && c4 == -1 && c5 == -1 && c6 == -1 && c7 == -1 && c8 == -1 && k == 0) {
cout << "无联系人,请添加后再来!\n";
}
else {
cout << "家人:" << endl;
if (c1 != -1) {
t = 1;
for (i = 0; i < c1 + 1; i++) {
Show(&f[i]); //调用虚函数show()
cout << endl;
}
}
if (t == 0) {
cout << "无\n";
}
cout << "朋友:" << endl;
if (k != 0) {
m = 1;
Show(&t0);//调用虚函数show()
}
if (c2 != -1) {
m = 1;
for (i = 0; i < c2 + 1; i++) {
Show(&fri[i]);//调用虚函数show()
cout << endl;
}
}
if (m == 0) {
cout << "无\n";
}
cout << "同学:" << endl;
if (c3 != -1) {
n = 1;
for (i = 0; i < c3 + 1; i++) {
Show(&c[i]);//调用虚函数show()
cout << endl;
}
}
if (n == 0) {
cout << "无\n";
}
cout << "同事:" << endl;
if (c4 != -1) {
r = 1;
for (i = 0; i < c4 + 1; i++) {
Show(&coll[i]);//调用虚函数show()
cout << endl;
}
}
if (r == 0) {
cout << "无\n";
}
cout << "特别关心:" << endl;
if (c5 != -1) {
q = 1;
cout << "家人:\n";
for (i = 0; i < c5 + 1; i++) {
l[i].show1();
cout << endl;
}
}
if (c6 != -1) {
q = 1;
cout << "朋友:\n";
for (i = 0; i < c6 + 1; i++) {
ll[i].show2();
cout << endl;
}
}
if (c7 != -1) {
q = 1;
cout << "同学:\n";
for (i = 0; i < c7 + 1; i++) {
lll[i].show3();
cout << endl;
}
}
if (c8 != -1) {
q = 1;
cout << "同事:\n";
for (i = 0; i < c8 + 1; i++) {
llll[i].show4();
cout << endl;
}
}
if (q == 0) {
cout << "无\n";
}
}
system("pause"); //使联系人不至于刚出现就清屏
system("cls");
}
void delemail() { //删除联系人
int dele, i, t = 0;
string n;
if (true) {
cout << "删除联系人:" << endl;
cout << "******************" << endl;
cout << "*1.删除家人 *" << endl;
cout << "******************" << endl;
cout << "*2.删除朋友 *" << endl;
cout << "******************" << endl;
cout << "*3.删除同学 *" << endl;
cout << "******************" << endl;
cout << "*4.删除同事 *" << endl;
cout << "******************" << endl;
cout << "*5.删除特别关心 *" << endl;
cout << "******************" << endl;
cin >> dele;
switch (dele) {
case 1:
cout << "输入你要删除的家人姓名" << endl;
cin >> n;
for (i = 0; i < c1 + 1; i++) {
if (f[i].getname() == n) {
t = 1;//标记已找到联系人
f[i].~family();
for (i = i; i < c1; i++) {
f[i] = f[i + 1];
}
cout << "删除成功!\n";
c1--;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 2:cout << "输入你要删除的朋友姓名" << endl;
cin >> n;
if (n == "小李") {
t = 1;
t0.~friends();
k = 0;
cout << "删除成功!\n";
}
else {
for (i = 0; i < c2 + 1; i++) {
if (fri[i].getname() == n) {
t = 1;
fri[i].~friends();
for (i = i; i < c2; i++) {
fri[i] = fri[i + 1];
}
cout << "删除成功!\n";
c2--;
}
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 3:
cout << "输入你要删除的同学姓名" << endl;
cin >> n;
for (i = 0; i < c3 + 1; i++) {
if (c[i].getname() == n) {
t = 1;
c[i].~classmates();
for (i = i; i < c3; i++) {
c[i] = c[i + 1];
}
cout << "删除成功!\n";
c3--;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 4:
cout << "输入你要删除的同事姓名" << endl;
cin >> n;
for (i = 0; i < c4 + 1; i++) {
if (coll[i].getname() == n) {
t = 1;
coll[i].~colleagues();
for (i = i; i < c4; i++) {
coll[i] = coll[i + 1];
}
cout << "删除成功!\n";
c4--;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 5:
cout << "输入你要删除的特别关心姓名" << endl;
cin >> n;
for (i = 0; i < c5 + 1; i++) {
if (l[i].getname() == n) {
t = 1;
l[i].~lover();
for (i = i; i < c5; i++) {
l[i] = l[i + 1];
}
cout << "删除成功!\n";
c5--;
}
}
for (i = 0; i < c6 + 1; i++) {
if (ll[i].getname() == n) {
t = 1;
ll[i].~lover();
for (i = i; i < c6; i++) {
ll[i] = ll[i + 1];
}
cout << "删除成功!\n";
c6--;
}
}
for (i = 0; i < c7 + 1; i++) {
if (lll[i].getname() == n) {
t = 1;
lll[i].~lover();
for (i = i; i < c7; i++) {
lll[i] = lll[i + 1];
}
cout << "删除成功!\n";
c7--;
}
}
for (i = 0; i < c8 + 1; i++) {
if (llll[i].getname() == n) {
t = 1;
llll[i].~lover();
for (i = i; i < c8; i++) {
llll[i] = llll[i + 1];
}
cout << "删除成功!\n";
c8--;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
}
system("pause");
system("cls");
}
}
void checkmail() { //查找联系人
int i, check, t = 0;
string n;
if (true) {
cout << "查找联系人:" << endl;
cout << "******************" << endl;
cout << "*1.查找家人 *" << endl;
cout << "******************" << endl;
cout << "*2.查找朋友 *" << endl;
cout << "******************" << endl;
cout << "*3.查找同学 *" << endl;
cout << "******************" << endl;
cout << "*4.查找同事 *" << endl;
cout << "******************" << endl;
cout << "*5.查找特别关心 *" << endl;
cout << "******************" << endl;
cin >> check;
switch (check) {
case 1:
cout << "请输入你要查找的家人姓名" << endl;
cin >> n;
for (i = 0; i < c1 + 1; i++) {
if (n == f[i].getname()) {
t = 1;
Show(&f[i]);//调用虚函数show()
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 2:
cout << "请输入你要查找的朋友姓名" << endl;
cin >> n;
if (n == "小李") {
t = 1;
Show(&t0);//调用虚函数show()
}
else {
for (i = 0; i < c2 + 1; i++) {
if (n == fri[i].getname()) {
t = 1;
Show(&fri[i]);//调用虚函数show()
break;
}
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 3:
cout << "请输入你要查找的同学姓名" << endl;
cin >> n;
for (i = 0; i < c3 + 1; i++) {
if (n == c[i].getname()) {
t = 1;
Show(&c[i]);//调用虚函数show()
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 4:
cout << "请输入你要查找的同事姓名" << endl;
cin >> n;
for (i = 0; i < c4 + 1; i++) {
if (n == coll[i].getname()) {
t = 1;
Show(&coll[i]);//调用虚函数show()
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 5:
cout << "请输入你要查找的特别关心姓名" << endl;
cin >> n;
for (i = 0; i < c5 + 1; i++) {
if (l[i].getname() == n) {
t = 1;
l[i].show1();
}
}
for (i = 0; i < c6 + 1; i++) {
if (ll[i].getname() == n) {
t = 1;
ll[i].show2();
}
}
for (i = 0; i < c7 + 1; i++) {
if (lll[i].getname() == n) {
t = 1;
lll[i].show3();
}
}
for (i = 0; i < c8 + 1; i++) {
if (llll[i].getname() == n) {
t = 1;
llll[i].show4();
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
}
}
system("pause");
system("cls");
}
void modifymail() { //修改联系人
int i, modify, t = 0;
string n;
if (true) {
cout << "修改联系人:" << endl;
cout << "******************" << endl;
cout << "*1.修改家人 *" << endl;
cout << "******************" << endl;
cout << "*2.修改朋友 *" << endl;
cout << "******************" << endl;
cout << "*3.修改同学 *" << endl;
cout << "******************" << endl;
cout << "*4.修改同事 *" << endl;
cout << "******************" << endl;
cin >> modify;
switch (modify) {
case 1:
cout << "请输入你要修改的家人姓名" << endl;
cin >> n;
for (i = 0; i < c1 + 1; i++) {
if (n == f[i].getname()) {
t = 1;
f[i].setfam();
cout << "修改成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 2:
cout << "请输入你要修改的朋友姓名" << endl;
cin >> n;
if (n == "小李") {
t = 1;
t0.setfri();
cout << "修改成功!" << endl;
}
else {
for (i = 0; i < c2 + 1; i++) {
if (n == fri[i].getname()) {
t = 1;
fri[i].setfri();
cout << "修改成功!" << endl;
break;
}
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 3:
cout << "请输入你要修改的同学姓名" << endl;
cin >> n;
for (i = 0; i < c3 + 1; i++) {
if (n == c[i].getname()) {
t = 1;
c[i].setmate();
cout << "修改成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
case 4:
cout << "请输入你要修改的同事姓名" << endl;
cin >> n;
for (i = 0; i < c4 + 1; i++) {
if (n == coll[i].getname()) {
t = 1;
coll[i].setcoll();
cout << "修改成功!" << endl;
break;
}
}
if (t == 0) {
cout << "找不到此联系人!" << endl;
}
break;
}
}
system("pause");
system("cls");
}
void alldele() { //清空联系人
c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = -1;
t0.~friends();
k = 0;
cout << "清空成功!" << endl;
system("pause");
system("cls");
}
void fun(mail_list* ptr) {
ptr->display();
}
int main() {
mail_list t1;
family t2;
friends t3;
classmates t4;
colleagues t5;
lover t6;
fun(&t1); //调用虚函数display()
fun(&t2);
fun(&t3);
fun(&t4);
fun(&t5);
fun(&t6);
int s;
while (true) {
showMenu();
cin >> s;
switch (s) {
case 1:
addmail();
break;
case 2:
showmail_list();
break;
case 3:
delemail();
break;
case 4:
checkmail();
break;
case 5:
modifymail();
break;
case 6:
alldele();
break;
case 7:
return 0;
break;
}
}
}
//目前存在的问题:
//1.t0的析构函数没有用,删除小李后还是会显示
//2.修改信息实现修改个别信息和全部信息
//已解决:
//程序运行后添加的联系人联系方式和出生日期显示有问题 ,在头文件中有解决方法
//清空通讯录后可能会导致程序停止//已解决
//查找联系人的找不到联系人的程序是无效的 //用t标记即可
//特别关心查不到该联系人出不来(添加特别关心功能有问题)//已解决
//添加联系人时添加成功显示不出来 //在system("cls");前加上 system("pause");就好了!
//添加无的提示
UML图:
实验心得:
- 通过本次实验,我对类的继承、虚基类、复杂的类及其构造函数、虚函数、多态等知识有了更加深的理解和认识。在以后的程序编写会更加熟练。
- 类的复杂关系可以用UML图展示,类中也用了许多虚基类,用派生类构造函数给基类函数实现了初始联系人(小李),用虚函数实现了对显示不同分组联系人的显示,实现了运行时的多态。
- 在类的继承里,如果基类的构造函数有参数,一定要注意给基类传参。当一个类同时被多个类继承时,要注意虚基类的使用。
- 灵活使用system(“pause”)和system(“cls”)可以使程序持续运行和清屏。