众所周知,这个电话簿是为了应付,啊不,为了完美完成实训任务而生...
这次的更新内容{
出于某些原因做了一份C语言版的代码
添加了一键删除功能;
完善了内容保存功能,避免了半路关闭系统,修改、添加等操作未保存的情况;
再次完善了容错系统...应该怎么输都会有对应解决情况,如果还有输错却没提示输错 的地方(应该是没了)...那我再去加个while(狗头);
}
第一个代码是C语言,第二个代码是C++;
c语言是用c++换过来的,或许会有一些小bug...
本人提供全套服务,如果想要报告书的话。。。留下你的赞,然后去最下面(狗头)
如果遇到任何bug,请留言!!!!!!!
仅供参考!!!!!!
附上一张图大致展示下该程序的运行:
(这个图之前做的,没有展示联系人读取和存储存储的过程。不过这个不重要~~~)
建议用c++的代码!!!!(在最后面)
对于c语言的代码,我试了几个编译器。
vs党请用第一个C语言代码,codeblocks党请用C语言第二个代码(由于gets_s的原因,code需要重新配置链接器),剩下的...私密马赛,支持的话就支持了,不支持的话...咳咳
好了废话说到这,放码过来了
.
博主能有什么坏心思,只是想要一个免费的赞而已~(狗头)(跪)
.
.
.
.
C语言第一个代码:
.
.
.
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
struct phone {
char name[2][100];
char sex[100];
char number[5][100];
char company[100];
int num;
}ph[10001];
int place;
int st[10001];
void quicksort(int left, int right);//快速排序函数,对通讯录中的联系人以其汉字拼音顺序排序
int smallfind(char s[]);//基础搜索函数,搜索该电话簿中所有符合条件的联系人
int RepetName(int low);//查找姓名相同的联系人,询问用户要对哪一个操作
void finds(char n[]);//搜索功能函数
void modify1(char n[]);//修改功能第1分支函数
void modify2(char k[]);//修改功能第2分支函数
void modify3(char k[]);//修改功能第3分支函数
void increase(char n[], char k[]);//添加联系人功能函数
void cut(char n[]);//删除联系人功能函数
void cutall();//一键删除函数
void see();//一览电话簿功能函数
void work();//工作函数,包含除main函数以外的所有函数
void goodbye();//结束界面
int readfile();//读取文件函数
void savefile();//保存文件函数
int main() {
system("color E1");
printf("\n\n\n");
printf(" * 通讯录 * \n");
printf(" o-------------------------------------------$--------------------------------------------o\n");
printf(" |此通讯录为基础通讯录,仅支持查找,修改,增加,删除以及一览电话簿等功能,剩余功能正在开发中|\n");
printf(" | |\n");
printf(" | 其中在修改功能里可以对联系人做出许多调整;修改,增加均支持备注和多个电话号绑定同一人 |\n");
printf(" | |\n");
printf(" | 若有多个联系人名字相同,建议添加备注,该通讯录支持备注查找联系人 |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | 一览电话簿请按 0 _____________ |\n");
printf(" | /. / |\n");
printf(" | 查找联系人请按 1 / | /| |\n");
printf(" | /_____________/ | |\n");
printf(" | 修改联系人请按 2 | | | | |\n");
printf(" | | ._ _ _ _ _ |_| |\n");
printf(" | 增加联系人请按 3 | / | / |\n");
printf(" | | / |/ |\n");
printf(" | 删除联系人请按 4 |_____________| |\n");
printf(" | |\n");
printf(" | 关闭通讯录请按 5 |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | |\n");
printf(" 0-------------------------------------------$--------------------------------------------0\n");
place = readfile();
work();
}
void goodbye() {
savefile();
system("color 0F");
printf("\n\n\n \033[46m*******************感谢使用!*******************\033[0m\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[45m制作人————————ssc\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[44m取材于————————《课本》\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[41m取材于————————《c++从入门到入土》\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[42m取材于————————《算法与程序设计寄础》\033[0m\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
system("color F4");
for (float y = 1.3f; y > -1.3f; y -= 0.12f) {
printf(" ");
for (float x = -1.65f; x < 1.65f; x += 0.06f) {
float a = x * x + y * y - 1;
putchar(a * a * a - x * x * y * y * y <= 0.0f ? '*' : ' ');
}
putchar('\n');
Sleep(100);
}
printf("\n");
Sleep(200);
printf("\n");
Sleep(200);
printf(" *******************下次再见!*******************\n");
}
void work() {
while (true) {
printf("\n一览电话簿请按 0,查找联系人请按 1,修改联系人请按 2\n");
printf("增加联系人请按 3,删除联系人请按 4,关闭通讯录请按 5");
printf("\n请输入指令: ");
char name_[100];
char number_[100];
char working[100];
gets_s(working);
if ((strcmp(working,"5")>0 || strcmp(working, "0") < 0 || strlen(working) >= 2) && strlen(working) > 1) {
printf("请输入正确的操作\n");
continue;
}
int wor = (int)working[0] - '0';
switch (wor) {
case 0: {
see();
break;
}
case 1: {//查找
printf("请输入要查找的联系人名称或备注或电话号码: ");
gets_s(name_);
finds(name_);
break;
}
case 2: {//修改
int d = 0;
while (1) {
printf("\n如果想为一个联系人添加备注请按0;");
printf("\n寻找要修改或补充信息的联系人的话请按1;如果想为一个联系人增加一个号码请按2;\n\n");
if (d == 1) printf("\n如果不想修改请按3;\n\n");
printf("请输入您的选择: ");
char u[100];
gets_s(u);
if (strcmp(u,"0")==0) {
printf("\n请输入要添加的联系人的名字或电话号码: ");
gets_s(name_);
modify3(name_);
break;
}
else if (strcmp(u,"1")==0) {
printf("\n请输入要修改的联系人原名称或备注或原号码: ");
gets_s(name_);
modify1(name_);
break;
}
else if (strcmp(u,"2")==0) {
printf("\n请输入要增加号码的联系人姓名或已有电话号: ");
gets_s(name_);
modify2(name_);
break;
}
else if (strcmp(u,"3")==0) return;
else {
printf("\n您的输入错误,请重新输入: ");
d = 1;
}
}
savefile();
break;
}
case 3: {//增加
printf("\n请输入要增加的联系人名称: ");
gets_s(name_);
printf("\n请输入要增加的联系人号码: ");
gets_s(number_);
increase(name_, number_);
savefile();
break;
}
case 4: {//删除
while (1) {
printf("\n您是想删除所有联系人还是指定联系人?\n");
printf("\n删除所有请按1,删除指定请按2: ");
char pl[100];
gets_s(pl);
if (strcmp(pl,"1")==0) {
cutall();
break;
}
else if (strcmp(pl,"2")==0) {
printf("\n请输入要删除的联系人名称或电话号码或备注: ");
gets_s(name_);
cut(name_);
break;
}
else {
printf("输入错误!请重新输入!\n\n");
continue;
}
}
savefile();
break;
}
case 5: {//退出
goodbye();
return;
}
}
}
}
int readfile() {
int number = 0;
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "r+");
if (fp == NULL) {
return 0;
}
while (fread(&ph[number++], sizeof(struct phone), 1, fp));
fclose(fp);
if (number >= 1) return number - 1;
else return 0;
}
void savefile() {
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "w+");
if (fp == NULL) {
return;
}
for (int i = 0; i < place; i++) {
fwrite(&ph[i], sizeof(struct phone), 1, fp);
}
fclose(fp);
}
void quicksort(int left, int right) {//快排
int p;
if (left < right) {
p = left;
int index = p + 1;
for (int i = index; i <= right; i++) {
if (strcmp(ph[i].name[0], ph[p].name[0])>0) {
phone t = ph[i];
ph[i] = ph[index];
ph[index] = t;
index++;
}
}
phone t = ph[p];
ph[p] = ph[index - 1];
ph[index - 1] = t;
p = index - 1;
quicksort(left, p - 1);
quicksort(p + 1, right);
}
}
int smallfind(char s[]) {
int sum = 0;
for (int i = 0; i < place; i++) {
if (strcmp(ph[i].name[0],s)==0 || strcmp(ph[i].name[1], s) == 0 || strcmp(ph[i].number[0], s) == 0 || strcmp(ph[i].number[1], s) == 0 || strcmp(ph[i].number[2], s) == 0 || strcmp(ph[i].number[3], s) == 0 || strcmp(ph[i].number[4], s) == 0) {//查找一个联系人时支持对其姓名或备注或电话的查找
st[sum++] = i;
}
else continue;
}
if (sum > 0)
return sum;
printf("没有该联系人!\n\n");
return -1;
}
int RepetName(int low) {
printf("\n当前名称的联系人共有%d个: \n\n",low);
for (int i = 0; i < low; i++) {
printf("\n姓名: "), puts(ph[st[i]].name[0]), printf("\n");
if (strcmp(ph[st[i]].sex, "") != 0)
printf("性别: "), puts(ph[st[i]].sex), printf("\n");
if (strcmp(ph[st[i]].name[1],"")!=0)
printf("备注: "), puts(ph[st[i]].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[st[i]].number[j]), printf("\n");
}
if (strcmp(ph[st[i]].company,"")!=0)
printf("公司: "), puts(ph[st[i]].company), printf("\n");
printf("\n");
}
printf("请问要修改第几个联系人:");
char g[100];
gets_s(g);//输入用getline,这样支持空格的写入
low = st[g[0] - '0' - 1];//重新赋予low新的含义,即要操作的位置
return low;
}
void finds(char n[]) {
if (place == 0) printf("电话簿里没有号码!\n");
int low = smallfind(n);
if (low == -1) return;
for (int i = 0; i < low; i++) {
printf("\n姓名: "), puts(ph[st[i]].name[0]), printf("\n");
if (strcmp(ph[st[i]].sex, "") != 0)
printf("性别: "), puts(ph[st[i]].sex), printf("\n");
if (strcmp(ph[st[i]].name[1], "") != 0)
printf("备注: "), puts(ph[st[i]].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[st[i]].number[j]), printf("\n");
}
if (strcmp(ph[st[i]].company, "") != 0)
printf("公司: "), puts(ph[st[i]].company), printf("\n");
printf("\n");
}
memset(st, 0, sizeof(int) * 10001);//每次用完都要清空
return;
}
void modify1(char n[]) {
int low = smallfind(n);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low = st[0];
printf("\n当前联系人的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1],"")!=0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
while (1) {
printf("\n如果您要修改姓名或备注请按1,修改号码请按2,修改性别和公司请按3: ");
char t[100];
gets_s(t);
char na[100];
char num[100];
if (strcmp(t,"1")==0) {
int i = 0;
while (1) {
printf("\n修改姓名请按1,修改备注请按2: ");
if (i == 1) printf("\n放弃修改请按0: ");
char h[100];
gets_s(h);
if (i == 1) if (strcmp(h,"0")==0) return;
if (strcmp(h, "1") == 0) {
printf("\n请输入要修改的名称: ");
gets_s(na);
strcpy(ph[low].name[0],na);
break;
}
else if (strcmp(h, "2") == 0) {
printf("\n请输入要修改的备注: ");
gets_s(na);
strcpy(ph[low].name[1],na);
break;
}
else {
printf("\n输入错误!请重新输入!\n");
i = 1;
}
}
break;
}
else if (strcmp(t, "2") == 0) {
while (1) {
char o[100];
if (ph[low].num >= 1) {
printf("\n该联系人共有"); printf("%d", ph[low].num); printf("个电话,请问要修改哪一个: ");
gets_s(o);
}
if (strcmp(o,"5")>0 || strcmp(o,"1")<0) {
printf("\n输入错误!!\n");
continue;
}
printf("\n请输入要修改的电话: ");
gets_s(num);
strcpy(ph[low].number[o[0] - 1 - '0'],num);
break;
}
break;
}
else if (strcmp(t, "3") == 0) {
while (1) {
printf("\n修改性别请按1,修改公司请按2: ");
char df[100];
gets_s(df);
if (strcmp(df, "1") == 0) {
printf("\n请输入要修改的性别: ");
char fg[100];
gets_s(fg);
strcpy(ph[low].sex,fg);
printf("\n修改成功!\n\n");
break;
}
else if (strcmp(df, "2") == 0) {
printf("\n请输入要修改的公司: ");
char fg[100];
gets_s(fg);
strcpy(ph[low].company,fg);
printf("\n修改成功!\n\n");
break;
}
else {
printf("\n您的输入错误!\n");
}
}
break;
}
else {
printf("\n输入错误,请重新输入!\n");
}
}
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
if (place > 1) quicksort(0, place - 1);
memset(st, 0, sizeof(int) * 10001);
}
void modify2(char k[]) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
if (ph[low].num >= 5) {
printf("\n该联系人可添加的号码已达上限5个!\n\n");
return;
}
printf("\n请输入您要为该联系人添加的新号码: ");
char y[100];
gets_s(y);
strcpy(ph[low].number[ph[low].num],y);
ph[low].num++;
printf("\n添加成功!\n");
printf("\n修改后的信息为: \n");
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
memset(st, 0, sizeof(int) * 10001);
return;
}
void modify3(char k[]) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
printf("\n请输入要添加的备注: ");
char pl[100];
gets_s(pl);
strcpy(ph[low].name[1],pl);
printf("\n添加成功!\n");
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
memset(st, 0, sizeof(int) * 10001);
return;
}
void increase(char n[100], char k[100]) {
strcpy(ph[place].name[0], n);
strcpy(ph[place].number[0], k);
ph[place].num++;
place++;
printf("\n添加成功!\n");
while (1) {
printf("您是否要添加该联系人的备注或其它电话号码等信息?需要请按1,不需要请按2: ");
char h[100];
gets_s(h);
if (strcmp(h,"1")==0) {
modify1(n);
break;
}
else if (strcmp(h, "2") == 0) {
if (place > 1) quicksort(0, place - 1);//添加完毕后重新排序
return;
}
else {
printf("\n您的输入错误,请重新输入!\n\n");
}
}
return;
}
void cut(char n[]) {
if (place == 0) {
printf("电话簿里没有号码可以删除!\n");
return;
}
int klj = 0;
while (1) {
if (klj == 1) {
printf("\n您是否要重新输入联系人名称以继续删除?\n");
printf("\n继续删除请按1,退出删除请按0: ");
char op[100];
gets_s(op);
if (strcmp(op, "1") != 0) {
break;
}
printf("\n请输入要删除的联系人的名字或备注或号码: ");
char tyu[100];
gets_s(tyu);
strcpy(n, tyu);
}
int low = smallfind(n);
if (low > 1) {
low = RepetName(low);
}
else if (low == -1) {
printf("未找到该联系人!您的输入有误或没有该联系人!\n");
klj = 1;
continue;
}
strcpy(ph[low].name[0], "");
strcpy(ph[low].name[1], "");
strcpy(ph[low].company, "");
strcpy(ph[low].sex, "");
ph[low].num = 0;
for (int j = 0; j < 5; j++) {
strcpy(ph[low].number[j], "");
}
if (place > 1) quicksort(0, place);//删除之后重新排序
place--;
printf("\n已删除该联系人\n");
memset(st, 0, sizeof(int) * 10001);
break;
}
return;
}
void cutall() {
printf("\n您确定删除吗?确定请按1,不确定请按2: ");
char plt[100];
gets_s(plt);
if (strcmp(plt,"1")==0) {
FILE* pss = NULL;
pss = fopen("PhoNum.txt", "w+");
fclose(pss);
memset(ph, 0, sizeof(ph));
place = 0;
printf("删除成功!\n");
}
else {
printf("\n取消删除!\n");
}
return;
}
void see() {
if (place == 0) {
printf("您没有联系人!\n");
return;
}
printf("\n您的电话表为: \n");
for (int i = 0; i < place; i++) {
printf("\n姓名: "), puts(ph[i].name[0]), printf("\n");
if (strcmp(ph[i].sex, "") != 0)
printf("性别: "), puts(ph[i].sex), printf("\n");
if (strcmp(ph[i].name[1], "") != 0)
printf("备注: "), puts(ph[i].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[i].number[j]), printf("\n");
}
if (strcmp(ph[i].company, "") != 0)
printf("公司: "), puts(ph[i].company), printf("\n");
printf("\n");
}
printf("\n已展示全部联系人\n\n");
}
。
。
。
。
C语言第二个代码:
。
。
。
。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
struct phone {
char name[2][100];
char sex[100];
char number[5][100];
char company[100];
int num;
}ph[10001];
int place;
int st[10001];
void quicksort(int left, int right);//快速排序函数,对通讯录中的联系人以其汉字拼音顺序排序
int smallfind(char s[]);//基础搜索函数,搜索该电话簿中所有符合条件的联系人
int RepetName(int low);//查找姓名相同的联系人,询问用户要对哪一个操作
void finds(char n[]);//搜索功能函数
void modify1(char n[]);//修改功能第1分支函数
void modify2(char k[]);//修改功能第2分支函数
void modify3(char k[]);//修改功能第3分支函数
void increase(char n[], char k[]);//添加联系人功能函数
void cut(char n[]);//删除联系人功能函数
void cutall();//一键删除函数
void see();//一览电话簿功能函数
void work();//工作函数,包含除main函数以外的所有函数
void goodbye();//结束界面
int readfile();//读取文件函数
void savefile();//保存文件函数
int main() {
system("color E1");
printf("\n\n\n");
printf(" * 通讯录 * \n");
printf(" o-------------------------------------------$--------------------------------------------o\n");
printf(" |此通讯录为基础通讯录,仅支持查找,修改,增加,删除以及一览电话簿等功能,剩余功能正在开发中|\n");
printf(" | |\n");
printf(" | 其中在修改功能里可以对联系人做出许多调整;修改,增加均支持备注和多个电话号绑定同一人 |\n");
printf(" | |\n");
printf(" | 若有多个联系人名字相同,建议添加备注,该通讯录支持备注查找联系人 |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | 一览电话簿请按 0 _____________ |\n");
printf(" | /. / |\n");
printf(" | 查找联系人请按 1 / | /| |\n");
printf(" | /_____________/ | |\n");
printf(" | 修改联系人请按 2 | | | | |\n");
printf(" | | ._ _ _ _ _ |_| |\n");
printf(" | 增加联系人请按 3 | / | / |\n");
printf(" | | / |/ |\n");
printf(" | 删除联系人请按 4 |_____________| |\n");
printf(" | |\n");
printf(" | 关闭通讯录请按 5 |\n");
printf(" | |\n");
printf(" | |\n");
printf(" | |\n");
printf(" 0-------------------------------------------$--------------------------------------------0\n");
place = readfile();
work();
}
void goodbye() {
savefile();
system("color 0F");
printf("\n\n\n \033[46m*******************感谢使用!*******************\033[0m\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[45m制作人————————ssc\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[44m取材于————————《课本》\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[41m取材于————————《c++从入门到入土》\033[0m\n");
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(200);
printf(" \033[42m取材于————————《算法与程序设计寄础》\033[0m\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
system("color F4");
for (float y = 1.3; y > -1.3; y -= 0.12) {
printf(" ");
for (float x = -1.65; x < 1.65; x += 0.06) {
float a = x * x + y * y - 1;
putchar(a * a * a - x * x * y * y * y <= 0.0 ? '*' : ' ');
}
putchar('\n');
Sleep(100);
}
printf("\n");
Sleep(200);
printf("\n");
Sleep(200);
printf(" *******************下次再见!*******************\n");
}
void work() {
while (1) {
printf("\n一览电话簿请按 0,查找联系人请按 1,修改联系人请按 2\n");
printf("增加联系人请按 3,删除联系人请按 4,关闭通讯录请按 5");
printf("\n请输入指令: ");
char name_[100];
char number_[100];
char working[100];
gets(working);
if ((strcmp(working, "5") > 0 || strcmp(working, "0") < 0 || strlen(working) >= 2) && strlen(working) > 1) {
printf("请输入正确的操作\n");
continue;
}
int wor = (int)working[0] - '0';
switch (wor) {
case 0: {
see();
break;
}
case 1: {//查找
printf("请输入要查找的联系人名称或备注或电话号码: ");
gets(name_);
finds(name_);
break;
}
case 2: {//修改
int d = 0;
while (1) {
printf("\n如果想为一个联系人添加备注请按0;");
printf("\n寻找要修改或补充信息的联系人的话请按1;如果想为一个联系人增加一个号码请按2;\n\n");
if (d == 1) printf("\n如果不想修改请按3;\n\n");
printf("请输入您的选择: ");
char u[100];
gets(u);
if (strcmp(u,"0")==0) {
printf("\n请输入要添加的联系人的名字或电话号码: ");
gets(name_);
modify3(name_);
break;
}
else if (strcmp(u,"1")==0) {
printf("\n请输入要修改的联系人原名称或备注或原号码: ");
gets(name_);
modify1(name_);
break;
}
else if (strcmp(u,"2")==0) {
printf("\n请输入要增加号码的联系人姓名或已有电话号: ");
gets(name_);
modify2(name_);
break;
}
else if (strcmp(u,"3")==0) return;
else {
printf("\n您的输入错误,请重新输入: ");
d = 1;
}
}
savefile();
break;
}
case 3: {//增加
printf("\n请输入要增加的联系人名称: ");
gets(name_);
printf("\n请输入要增加的联系人号码: ");
gets(number_);
increase(name_, number_);
savefile();
break;
}
case 4: {//删除
while (1) {
printf("\n您是想删除所有联系人还是指定联系人?\n");
printf("\n删除所有请按1,删除指定请按2: ");
char pl[100];
gets(pl);
if (strcmp(pl,"1")==0) {
cutall();
break;
}
else if (strcmp(pl,"2")==0) {
printf("\n请输入要删除的联系人名称或电话号码或备注: ");
gets(name_);
cut(name_);
break;
}
else {
printf("输入错误!请重新输入!\n\n");
continue;
}
}
savefile();
break;
}
case 5: {//退出
goodbye();
return;
}
}
}
}
int readfile() {
int number = 0;
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "r+");
if (fp == NULL) {
return 0;
}
while (fread(&ph[number++], sizeof(struct phone), 1, fp));
fclose(fp);
if (number >= 1) return number - 1;
else return 0;
}
void savefile() {
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "w+");
if (fp == NULL) {
return;
}
for (int i = 0; i < place; i++) {
fwrite(&ph[i], sizeof(struct phone), 1, fp);
}
fclose(fp);
}
void quicksort(int left, int right) {//快排
int p;
if (left < right) {
p = left;
int index = p + 1;
for (int i = index; i <= right; i++) {
if (strcmp(ph[i].name[0], ph[p].name[0]) > 0) {
struct phone t = ph[i];
ph[i] = ph[index];
ph[index] = t;
index++;
}
}
struct phone t = ph[p];
ph[p] = ph[index - 1];
ph[index - 1] = t;
p = index - 1;
quicksort(left, p - 1);
quicksort(p + 1, right);
}
}
int smallfind(char s[]) {
int sum = 0;
for (int i = 0; i < place; i++) {
if (strcmp(ph[i].name[0], s) == 0 || strcmp(ph[i].name[1], s) == 0 || strcmp(ph[i].number[0], s) == 0 || strcmp(ph[i].number[1], s) == 0 || strcmp(ph[i].number[2], s) == 0 || strcmp(ph[i].number[3], s) == 0 || strcmp(ph[i].number[4], s) == 0) {//查找一个联系人时支持对其姓名或备注或电话的查找
st[sum++] = i;
}
else continue;
}
if (sum > 0)
return sum;
printf("没有该联系人!\n\n");
return -1;
}
int RepetName(int low) {
printf("\n当前名称的联系人共有%d个: \n\n", low);
for (int i = 0; i < low; i++) {
printf("\n姓名: "), puts(ph[st[i]].name[0]), printf("\n");
if (strcmp(ph[st[i]].sex, "") != 0)
printf("性别: "), puts(ph[st[i]].sex), printf("\n");
if (strcmp(ph[st[i]].name[1], "") != 0)
printf("备注: "), puts(ph[st[i]].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[st[i]].number[j]), printf("\n");
}
if (strcmp(ph[st[i]].company, "") != 0)
printf("公司: "), puts(ph[st[i]].company), printf("\n");
printf("\n");
}
printf("请问要修改第几个联系人:");
char g[100];
gets(g);//输入用getline,这样支持空格的写入
low = st[g[0] - '0' - 1];//重新赋予low新的含义,即要操作的位置
return low;
}
void finds(char n[]) {
if (place == 0) printf("电话簿里没有号码!\n");
int low = smallfind(n);
if (low == -1) return;
for (int i = 0; i < low; i++) {
printf("\n姓名: "), puts(ph[st[i]].name[0]), printf("\n");
if (strcmp(ph[st[i]].sex, "") != 0)
printf("性别: "), puts(ph[st[i]].sex), printf("\n");
if (strcmp(ph[st[i]].name[1], "") != 0)
printf("备注: "), puts(ph[st[i]].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[st[i]].number[j]), printf("\n");
}
if (strcmp(ph[st[i]].company, "") != 0)
printf("公司: "), puts(ph[st[i]].company), printf("\n");
printf("\n");
}
memset(st, 0, sizeof(int) * 10001);//每次用完都要清空
return;
}
void modify1(char n[]) {
int low = smallfind(n);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low = st[0];
printf("\n当前联系人的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
while (1) {
printf("\n如果您要修改姓名或备注请按1,修改号码请按2,修改性别和公司请按3: ");
char t[100];
gets(t);
char na[100];
char num[100];
if (strcmp(t, "1") == 0) {
int i = 0;
while (1) {
printf("\n修改姓名请按1,修改备注请按2: ");
if (i == 1) printf("\n放弃修改请按0: ");
char h[100];
gets(h);
if (i == 1) if (strcmp(h, "0") == 0) return;
if (strcmp(h, "1") == 0) {
printf("\n请输入要修改的名称: ");
gets(na);
strcpy(ph[low].name[0], na);
break;
}
else if (strcmp(h, "2") == 0) {
printf("\n请输入要修改的备注: ");
gets(na);
strcpy(ph[low].name[1], na);
break;
}
else {
printf("\n输入错误!请重新输入!\n");
i = 1;
}
}
break;
}
else if (strcmp(t, "2") == 0) {
while (1) {
char o[100];
if (ph[low].num >= 1) {
printf("\n该联系人共有"); printf("%d", ph[low].num); printf("个电话,请问要修改哪一个: ");
gets(o);
}
if (strcmp(o, "5") > 0 || strcmp(o, "1") < 0) {
printf("\n输入错误!!\n");
continue;
}
printf("\n请输入要修改的电话: ");
gets(num);
strcpy(ph[low].number[o[0] - 1 - '0'], num);
break;
}
break;
}
else if (strcmp(t, "3") == 0) {
while (1) {
printf("\n修改性别请按1,修改公司请按2: ");
char df[100];
gets(df);
if (strcmp(df, "1") == 0) {
printf("\n请输入要修改的性别: ");
char fg[100];
gets(fg);
strcpy(ph[low].sex, fg);
printf("\n修改成功!\n\n");
break;
}
else if (strcmp(df, "2") == 0) {
printf("\n请输入要修改的公司: ");
char fg[100];
gets(fg);
strcpy(ph[low].company, fg);
printf("\n修改成功!\n\n");
break;
}
else {
printf("\n您的输入错误!\n");
}
}
break;
}
else {
printf("\n输入错误,请重新输入!\n");
}
}
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
if (place > 1) quicksort(0, place - 1);
memset(st, 0, sizeof(int) * 10001);
}
void modify2(char k[]) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
if (ph[low].num >= 5) {
printf("\n该联系人可添加的号码已达上限5个!\n\n");
return;
}
printf("\n请输入您要为该联系人添加的新号码: ");
char y[100];
gets(y);
strcpy(ph[low].number[ph[low].num], y);
ph[low].num++;
printf("\n添加成功!\n");
printf("\n修改后的信息为: \n");
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
memset(st, 0, sizeof(int) * 10001);
return;
}
void modify3(char k[]) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
printf("\n请输入要添加的备注: ");
char pl[100];
gets(pl);
strcpy(ph[low].name[1], pl);
printf("\n添加成功!\n");
printf("\n修改后的信息为: \n");
printf("\n姓名: "), puts(ph[low].name[0]), printf("\n");
if (strcmp(ph[low].sex, "") != 0)
printf("性别: "), puts(ph[low].sex), printf("\n");
if (strcmp(ph[low].name[1], "") != 0)
printf("备注: "), puts(ph[low].name[1]), printf("\n");
for (int j = 0; j < ph[low].num; j++) {
printf("电话: "), puts(ph[low].number[j]), printf("\n");
}
if (strcmp(ph[low].company, "") != 0)
printf("公司: "), puts(ph[low].company), printf("\n");
printf("\n");
memset(st, 0, sizeof(int) * 10001);
return;
}
void increase(char n[100], char k[100]) {
strcpy(ph[place].name[0], n);
strcpy(ph[place].number[0], k);
ph[place].num++;
place++;
printf("\n添加成功!\n");
while (1) {
printf("您是否要添加该联系人的备注或其它电话号码等信息?需要请按1,不需要请按2: ");
char h[100];
gets(h);
if (strcmp(h, "1") == 0) {
modify1(n);
break;
}
else if (strcmp(h, "2") == 0) {
if (place > 1) quicksort(0, place - 1);//添加完毕后重新排序
return;
}
else {
printf("\n您的输入错误,请重新输入!\n\n");
}
}
return;
}
void cut(char n[]) {
if (place == 0) {
printf("电话簿里没有号码可以删除!\n");
return;
}
int klj = 0;
while (1) {
if (klj == 1) {
printf("\n您是否要重新输入联系人名称以继续删除?\n");
printf("\n继续删除请按1,退出删除请按0: ");
char op[100];
gets(op);
if (strcmp(op, "1") != 0) {
break;
}
printf("\n请输入要删除的联系人的名字或备注或号码: ");
char tyu[100];
gets(tyu);
strcpy(n, tyu);
}
int low = smallfind(n);
if (low > 1) {
low = RepetName(low);
}
else if (low == -1) {
printf("未找到该联系人!您的输入有误或没有该联系人!\n");
klj = 1;
continue;
}
strcpy(ph[low].name[0], "");
strcpy(ph[low].name[1], "");
strcpy(ph[low].company, "");
strcpy(ph[low].sex, "");
ph[low].num = 0;
for (int j = 0; j < 5; j++) {
strcpy(ph[low].number[j], "");
}
if (place > 1) quicksort(0, place);//删除之后重新排序
place--;
printf("\n已删除该联系人\n");
memset(st, 0, sizeof(int) * 10001);
break;
}
return;
}
void cutall() {
printf("\n您确定删除吗?确定请按1,不确定请按2: ");
char plt[100];
gets(plt);
if (strcmp(plt, "1") == 0) {
FILE* pss = NULL;
pss = fopen("PhoNum.txt", "w+");
fclose(pss);
memset(ph, 0, sizeof(ph));
place = 0;
printf("删除成功!\n");
}
else {
printf("\n取消删除!\n");
}
return;
}
void see() {
if (place == 0) {
printf("您没有联系人!\n");
return;
}
printf("\n您的电话表为: \n");
for (int i = 0; i < place; i++) {
printf("\n姓名: "), puts(ph[i].name[0]), printf("\n");
if (strcmp(ph[i].sex, "") != 0)
printf("性别: "), puts(ph[i].sex), printf("\n");
if (strcmp(ph[i].name[1], "") != 0)
printf("备注: "), puts(ph[i].name[1]), printf("\n");
for (int j = 0; j < ph[i].num; j++) {
printf("电话: "), puts(ph[i].number[j]), printf("\n");
}
if (strcmp(ph[i].company, "") != 0)
printf("公司: "), puts(ph[i].company), printf("\n");
printf("\n");
}
printf("\n已展示全部联系人\n\n");
}
。
。
。
c++:
。
。
。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
using namespace std;
typedef long long ll;
struct phone {
string name[2];
string sex;
string number[5];
string company;
int num;
}ph[10001];
ll place;
ll st[10001];
void quicksort(ll left, ll right);//快速排序函数,对通讯录中的联系人以其汉字拼音顺序排序
int smallfind(string s);//基础搜索函数,搜索该电话簿中所有符合条件的联系人
int RepetName(int low);//查找姓名相同的联系人,询问用户要对哪一个操作
void finds(string n);//搜索功能函数
void modify1(string n);//修改功能第一分支函数
void modify2(string k);//修改功能第三分支函数
void modify3(string k);//修改功能第四分支函数
void increase(string n, string k);//添加联系人功能函数
void cut(string n);//删除联系人功能函数
void cutall();//一键删除函数
void see();//一览电话簿功能函数
void work();//工作函数,包含除main函数以外的所有函数
void goodbye();//结束界面
int readfile();//读取文件函数
void savefile();//保存文件函数
int main() {
//ios::sync_with_stdio(false);
system("color E1");
cout << '\n' << '\n' << '\n';
cout << " " << "*通讯录*" << '\n' << endl;
cout << " o-------------------------------------------$--------------------------------------------o" << endl;
cout << " " << "|此通讯录为基础通讯录,仅支持查找,修改,增加,删除以及一览电话簿等功能,剩余功能正在开发中|" << endl;
cout << " " << "| |" << endl;
cout << " " << "| 其中在修改功能里可以对联系人做出许多调整;修改,增加均支持备注和多个电话号绑定同一人 |" << endl;
cout << " " << "| |" << endl;
cout << " " << "| 若有多个联系人名字相同,建议添加备注,该通讯录支持备注查找联系人 |" << endl;
cout << " " << "| |" << endl;
cout << " " << "| |" << endl;
cout << " " << "| |" << endl;
cout << " " << "| 一览电话簿请按 0 _____________ |" << 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;
cout << " " << "| |" << endl;
cout << " " << "| 作者:ssc |" << endl;
cout << " 0-------------------------------------------$--------------------------------------------0" << endl;
place = readfile();
work();
}
void goodbye() {
savefile();
system("color 0F");
cout << '\n' << '\n' << '\n' << " \033[46m*******************感谢使用!*******************\033[0m" << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(200);
cout << " \033[45m制作人————————ssc\033[0m" << '\n';
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(200);
cout << " \033[44m取材于————————《课本》\033[0m" << '\n';
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(200);
cout << " \033[41m取材于————————《c++从入门到入土》\033[0m" << '\n';
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(200);
cout << " \033[42m取材于————————《算法与程序设计寄础》\033[0m" << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << " \033[43m取材于————————《zyb》\033[0m" << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
cout << '\n';
Sleep(100);
system("color F4");
for (float y = 1.3; y > -1.3; y -= 0.12) {
cout << " ";
for (float x = -1.65; x < 1.65; x += 0.06) {
float a = x * x + y * y - 1;
putchar(a * a * a - x * x * y * y * y <= 0.0 ? '*' : ' ');
}
putchar('\n');
Sleep(100);
}
cout << '\n';
Sleep(200);
cout << '\n';
Sleep(200);
cout << " *******************下次再见!*******************" << '\n';
}
void work() {
while (true) {
cout << '\n' << "一览电话簿请按 0,查找联系人请按 1,修改联系人请按 2" << '\n';
cout << "增加联系人请按 3,删除联系人请按 4,关闭通讯录请按 5";
cout << '\n' << "请输入指令: ";
string name_;
string number_;
string working;
getline(cin, working);
if ((working > "5" || working < "0" || working.length() >= 2) && working.length() > 1) {
cout << "请输入正确的操作" << endl;
continue;
}
int wor = (int)working[0] - '0';
switch (wor) {
case 0: {
see();
break;
}
case 1: {//查找
cout << "请输入要查找的联系人名称或备注或电话号码: ";
getline(cin, name_);
finds(name_);
break;
}
case 2: {//修改
int d = 0;
while (1) {
cout << '\n' << "如果想为一个联系人添加备注请按0;";
cout << '\n' << "寻找要修改或补充信息的联系人的话请按1;" << "如果想为一个联系人增加一个号码请按2;" << '\n' << '\n';
if (d == 1) cout << '\n' << "如果不想修改请按3;" << '\n' << '\n';
cout << "请输入您的选择: ";
string u;
getline(cin, u);
if (u == "0") {
cout << '\n' << "请输入要添加的联系人的名字或电话号码: ";
getline(cin, name_);
modify3(name_);
break;
}
else if (u == "1") {
cout << '\n' << "请输入要修改的联系人原名称或备注或原号码: ";
getline(cin, name_);
modify1(name_);
break;
}
else if (u == "2") {
cout << '\n' << "请输入要增加号码的联系人姓名或已有电话号: ";
getline(cin, name_);
modify2(name_);
break;
}
else if (u == "3") return;
else {
cout << '\n' << "您的输入错误,请重新输入: ";
d = 1;
}
}
savefile();
break;
}
case 3: {//增加
cout << '\n' << "请输入要增加的联系人名称: ";
getline(cin, name_);
cout << '\n' << "请输入要增加的联系人号码: ";
getline(cin, number_);
increase(name_, number_);
savefile();
break;
}
case 4: {//删除
while (1) {
cout <<'\n'<< "您是想删除所有联系人还是指定联系人?" << '\n';
cout << '\n'<<"删除所有请按1,删除指定请按2: ";
string pl;
getline(cin, pl);
if (pl == "1") {
cutall();
break;
}
else if (pl == "2") {
cout << "请输入要删除的联系人名称或电话号码或备注: ";
getline(cin, name_);
cut(name_);
break;
}
else {
cout << "输入错误!请重新输入!" << '\n' << '\n';
continue;
}
}
savefile();
break;
}
case 5: {//退出
goodbye();
return;
}
}
}
}
ll readfile() {
ll number = 0;
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "r+");
if (fp == NULL) {
return 0;
}
while (fread(&ph[number++], sizeof(struct phone), 1, fp));
fclose(fp);
if (number >= 1) return number - 1;
else return 0;
}
void savefile() {
FILE* fp = NULL;
fp = fopen("PhoNum.txt", "w+");
if (fp == NULL) {
return;
}
for (int i = 0; i < place; i++) {
fwrite(&ph[i], sizeof(struct phone), 1, fp);
}
fclose(fp);
}
void quicksort(ll left, ll right) {//快排
ll p;
if (left < right) {
p = left;
ll index = p + 1;
for (ll i = index; i <= right; i++) {
if (ph[i].name[0] > ph[p].name[0]) {
phone t = ph[i];
ph[i] = ph[index];
ph[index] = t;
index++;
}
}
phone t = ph[p];
ph[p] = ph[index - 1];
ph[index - 1] = t;
p = index - 1;
quicksort(left, p - 1);
quicksort(p + 1, right);
}
}
int smallfind(string s) {
int sum = 0;
for (int i = 0; i < place; i++) {
if (ph[i].name[0] == s || ph[i].name[1] == s || ph[i].number[0] == s || ph[i].number[1] == s || ph[i].number[2] == s || ph[i].number[3] == s || ph[i].number[4] == s) {//查找一个联系人时支持对其姓名或备注或电话的查找
st[sum++] = i;
}
else continue;
}
if (sum > 0)
return sum;
cout << "没有该联系人!" << '\n' << endl;
return -1;
}
int RepetName(int low) {
cout << '\n' << "当前名称的联系人共有" << low << "个: " << '\n' << '\n';
for (int i = 0; i < low; i++) {
cout << '\n' << "姓名: " << ph[st[i]].name[0] << '\n';
if (ph[st[i]].sex != "")
cout << "性别: " << ph[st[i]].sex << '\n';
if (ph[st[i]].name[1] != "")
cout << "备注: " << ph[st[i]].name[1] << '\n';
for (int j = 0; j < ph[i].num; j++) {
cout << "电话: " << ph[st[i]].number[j] << '\n';
}
if (ph[st[i]].company != "")
cout << "公司: " << ph[st[i]].company << '\n';
cout << '\n';
}
cout << "请问要修改第几个联系人:";
string g;
getline(cin, g);//输入·用getline,这样支持空格的写入
char gh[2];//以下是string类和char类的转化,用于计算ASCII码
g.copy(gh, 1, 0);
gh[1] = '\0';
low = st[gh[0] - '0' - 1];//重新赋予low新的含义,即要操作的位置
return low;
}
void finds(string n) {
if (place == 0) cout << "电话簿里没有号码!" << endl;
int low = smallfind(n);
if (low == -1) return;
for (int i = 0; i < low; i++) {
cout << '\n' << "姓名: " << ph[st[i]].name[0] << '\n';
if (ph[st[i]].sex != "")
cout << "性别: " << ph[st[i]].sex << '\n';
if (ph[st[i]].name[1] != "")
cout << "备注: " << ph[st[i]].name[1] << '\n';
for (int j = 0; j < ph[st[i]].num; j++) {
cout << "电话: " << ph[st[i]].number[j] << '\n';
}
if (ph[st[i]].company != "")
cout << "公司: " << ph[st[i]].company << '\n';
cout << '\n';
}
memset(st, 0, sizeof(ll) * 10001);//每次用完都要清空
return;
}
void modify1(string n) {
int low = smallfind(n);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low = st[0];
cout << '\n' << "当前联系人的信息为: " << '\n';
cout << '\n' << "姓名: " << ph[low].name[0] << '\n';
if (ph[low].sex != "")
cout << "性别: " << ph[low].sex << '\n';
if (ph[low].name[1] != "")
cout << "备注: " << ph[low].name[1] << '\n';
for (int j = 0; j < ph[low].num; j++) {
cout << "电话: " << ph[low].number[j] << '\n';
}
if (ph[low].company != "")
cout << "公司: " << ph[low].company << '\n';
cout << '\n';
while (1) {
cout << '\n' << "如果您要修改姓名或备注请按1,修改号码请按2,修改性别和公司请按3: ";
string t;
getline(cin, t);
string na;
string num;
if (t == "1") {
int i = 0;
while (1) {
cout << '\n' << "修改姓名请按1,修改备注请按2: ";
if (i == 1) cout << '\n' << "放弃修改请按0: ";
string h;
getline(cin, h);
if (i == 1) if (h == "0") return;
if (h == "1") {
cout << "请输入要修改的名称: ";
getline(cin, na);
ph[low].name[0] = na;
break;
}
else if (h == "2") {
cout << "请输入要修改的备注: ";
getline(cin, na);
ph[low].name[1] = na;
break;
}
else {
cout << '\n' << "输入错误!请重新输入!" << '\n';
i = 1;
}
}
break;
}
else if (t == "2") {
while (1) {
string o;
if (ph[low].num >= 1) {
cout << '\n' << "该联系人共有" << ph[low].num << "个电话,请问要修改哪一个: ";
getline(cin, o);
}
if (o > "5" || o < "1") {
cout << '\n' << "输入错误!!" << '\n';
continue;
}
cout << '\n' << "请输入要修改的电话: ";
getline(cin, num);
char lowo[2];
o.copy(lowo, 1, 0);
*(lowo + 1) = '\0';
ph[low].number[lowo[0] - 1 - '0'] = num;
break;
}
break;
}
else if (t == "3") {
while (1) {
cout << '\n' << "修改性别请按1,修改公司请按2: ";
string df;
getline(cin, df);
if (df == "1") {
cout << "请输入要修改的性别: ";
string fg;
getline(cin, fg);
ph[low].sex = fg;
cout << '\n' << "修改成功!" << '\n' << endl;
break;
}
else if (df == "2") {
cout << "请输入要修改的公司: ";
string fg;
getline(cin, fg);
ph[low].company = fg;
cout << '\n' << "修改成功!" << '\n' << endl;
break;
}
else {
cout << '\n' << "您的输入错误!" << '\n';
}
}
break;
}
else {
cout << '\n' << "输入错误,请重新输入!" << '\n';
}
}
cout << '\n' << "修改后的信息为: " << '\n';
cout << '\n' << "姓名: " << ph[low].name[0] << '\n';
if (ph[low].sex != "")
cout << "性别: " << ph[low].sex << '\n';
if (ph[low].name[1] != "")
cout << "备注: " << ph[low].name[1] << '\n';
for (int j = 0; j < ph[low].num; j++) {
cout << "电话: " << ph[low].number[j] << '\n';
}
if (ph[low].company != "")
cout << "公司: " << ph[low].company << '\n';
cout << '\n';
if (place > 1) quicksort(0, place - 1);
memset(st, 0, sizeof(ll) * 10001);
}
void modify2(string k) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
if (ph[low].num >= 4) {
cout << '\n' << "该联系人可添加的号码已达上限5个!" << '\n' << '\n';
return;
}
cout << '\n' << "请输入您要为该联系人添加的新号码: ";
string y;
getline(cin, y);
ph[low].number[ph[low].num] = y;
ph[low].num++;
cout << '\n' << "添加成功!" << '\n';
cout << '\n' << "修改后的信息为: " << '\n';
cout << '\n' << "姓名:" << ph[low].name[0] << '\n';
if (ph[low].sex != "")
cout << "性别: " << ph[low].sex << '\n';
if (ph[low].name[1] != "")
cout << "备注: " << ph[low].name[1] << '\n';
for (int j = 0; j < ph[low].num; j++) {
cout << "电话: " << ph[low].number[j] << '\n';
}
if (ph[low].company != "")
cout << "公司: " << ph[low].company << '\n';
cout << '\n';
memset(st, 0, sizeof(ll) * 10001);
return;
}
void modify3(string k) {
int low = smallfind(k);
if (low == -1) return;
if (low > 1) {
low = RepetName(low);
}
else low--;
cout << '\n' << "请输入要添加的备注: ";
string pl;
getline(cin, pl);
ph[low].name[1] = pl;
cout << '\n' << "添加成功!" << '\n';
cout << '\n' << "修改后的信息为: " << '\n';
cout << '\n' << "姓名: " << ph[low].name[0] << '\n';
if (ph[low].sex != "")
cout << "性别: " << ph[low].sex << '\n';
if (ph[low].name[1] != "")
cout << "备注: " << ph[low].name[1] << '\n';
for (int j = 0; j < ph[low].num; j++) {
cout << "电话: " << ph[low].number[j] << '\n';
}
if (ph[low].company != "")
cout << "公司: " << ph[low].company << '\n';
cout << '\n';
memset(st, 0, sizeof(ll) * 10001);
return;
}
void increase(string n, string k) {
ph[place].name[0] = n;
ph[place].number[0] = k;
ph[place].num++;
place++;
cout << '\n' << "添加成功!" << '\n' << '\n';
while (1) {
cout << "您是否要添加该联系人的备注或其它电话号码等信息?需要请按1,不需要请按2: ";
string h;
getline(cin, h);
if (h == "1") {
modify1(n);
break;
}
else if (h == "2") {
if (place > 1) quicksort(0, place - 1);//添加完毕后重新排序
return;
}
else {
cout << '\n' << "您的输入错误,请重新输入!" << '\n' << '\n';
}
}
return;
}
void cut(string n) {
if (place == 0) {
cout << "电话簿里没有号码可以删除!" << endl;
return;
}
int klj = 0;
while (1) {
if (klj == 1) {
cout << '\n' << "您是否要重新输入联系人名称以继续删除?" << '\n';
cout << "继续删除请按1,退出删除请按0: ";
string op;
getline(cin, op);
if (op != "1") {
break;
}
cout << '\n' << "请输入要删除的联系人的名字或备注或号码: ";
getline(cin, n);
}
int low = smallfind(n);
if (low > 1) {
low = RepetName(low);
}
else if (low == -1) {
cout << "未找到该联系人!您的输入有误或没有该联系人!" << endl;
klj = 1;
continue;
}
else low--;
ph[low].name[0] = "";
ph[low].name[1] = "";
ph[low].company = "";
ph[low].sex = "";
ph[low].num = 0;
for (int j = 0; j < 5; j++) {
ph[low].number[j] = "";
}
if (place > 1) quicksort(0, place);//删除之后重新排序
place--;
cout << '\n' << "已删除该联系人" << endl;
memset(st, 0, sizeof(ll) * 10001);
break;
}
return;
}
void cutall() {
cout << '\n' << "您确定删除吗?确定请按1,不确定请按2: ";
string plt;
getline(cin, plt);
if (plt == "1") {
FILE* pss = NULL;
pss = fopen("PhoNum.txt", "w+");
fclose(pss);
memset(ph, 0, sizeof(ph));
place = 0;
cout << "删除成功!" << '\n';
}
else {
cout << '\n' << "取消删除!" << '\n';
}
return;
}
void see() {
if (place == 0) {
cout << "您没有联系人!" << endl;
return;
}
cout << '\n' << "您的电话表为: " << '\n';
for (int i = 0; i < place; i++) {
cout << '\n' << "姓名: " << ph[i].name[0] << '\n';
if (ph[i].sex != "")
cout << "性别: " << ph[i].sex << '\n';
if (ph[i].name[1] != "")
cout << "备注: " << ph[i].name[1] << '\n';
for (int j = 0; j < ph[i].num; j++) {
cout << "电话: " << ph[i].number[j] << '\n';
}
if (ph[i].company != "")
cout << "公司: " << ph[i].company << '\n';
cout << '\n';
}
cout << "已展示全部联系人" << '\n' << endl;
}
这是一个报告书:点击这里
没啦~
希望我的代码能帮上你的忙
求三连(跪)