1. 表头###
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/zswxy/CST2019-1 |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/2019TA/homework/10302 |
这个作业的目标 | 学习并掌握基本的git命令 |
其他参考文献 | 演示视频 清空数组的方法 |
2. 作业内容###
2.1 设计思路与问题#####
2.2 程序结果截图#####
2.3 程序代码#####
#include
#include
#include
void error();
int exist_people = 0, surplus_people = 50, k1, i, x, count = 0;
char name[50][9];
char code[51][3] = { '\0','\0','\0','1', '\0','\0', '2', '\0','\0', '3', '\0' ,'\0','4','\0','\0','5', '\0','\0','6','\0', '\0', '7','\0', '\0' ,'8','\0','\0' ,'9','\0', '\0',
'1','0','\0','1', '1','\0', '1', '2','\0', '1', '3' ,'\0','1','4','\0','1', '5','\0','1', '6','\0', '1', '7' ,'\0','1','8' ,'\0','1', '9','\0', '2','0','\0',
'2', '1','\0', '2', '2','\0', '2', '3','\0', '2', '4','\0', '2', '5','\0', '2', '6','\0', '2', '7','\0', '2', '8','\0', '2', '9','\0', '3', '0','\0',
'3', '1','\0', '3', '2','\0', '3', '3','\0', '3', '4','\0', '3', '5','\0', '3', '6','\0', '3', '7','\0', '3', '8','\0', '3', '9','\0', '4', '0','\0',
'4', '1','\0', '4', '2','\0', '4', '3','\0', '4', '4','\0', '4', '5','\0', '4', '6','\0', '4', '7','\0', '4', '8','\0', '4', '9','\0', '5', '0','\0' };
char telephone[50][12];
void delete()
{
if (exist_people == 0)
{
printf("不存在数据可以进行修改!!!");
system("pause");
}
else
{
printf("进行删除操作:");
printf("请输入对应编号进行删除:");
scanf("%d", &k1);
if (k1 < 1 || k1>50)
{
printf("处理编号超过阙值!!!");
system("pause");
}
else
{
if (telephone[k1][0] == '\0')
{
printf("无数据可以处理!!!");
system("pause");
}
else
{
for (i = 0; i < strlen(name[k1]); i++)
{
name[k1][i] = '\0';
}
for (i = 0; i < strlen(telephone[k1]); i++)
{
telephone[k1][i] = '\0';
}
exist_people--;
surplus_people++;
printf("已处理!!!");
system("pause");
}
}
}
}
void add()
{
if (surplus_people > 0)
{
printf("请输入添加位置:");
scanf("%d", &k1);
if (k1 < 1 || k1 > 50)
{
printf("处理编号超过阙值!!!");
system("pause");
}
else
{
if (telephone[k1][0] != '\0')
{
printf("此处已有数据!!");
system("pause");
}
else
{
printf("请输入联系人姓名:");
scanf("%s", name[k1]);
printf("请输入联系人电话:");
scanf("%s", telephone[k1]);
exist_people++;
surplus_people--;
}
}
}
else
{
printf("通讯录已满!!!");
system("pause");
}
}
void madify()
{
if (exist_people == 0)
{
printf("不存在数据可以进行修改!!!");
}
else
{
printf("修改操作:");
printf("请输入修改位置:");
scanf("%d", &x);
if (x > 51 || x < 1)
{
if (name[x][0] != '\0')
{
for (i = 0; i < strlen(name[x]); i++)
{
name[x][i] = '\0';
}
for (i = 0; i < strlen(telephone[x]); i++)
{
telephone[x][i] = '\0';
}
printf("已檫除原有信息,请重新键入:\n");
printf("请输入联系人姓名:");
scanf("%s", name[x]);
printf("请输入联系人电话:");
scanf("%s", telephone[x]);
}
else
{
printf("此处无数据!!!");
system("pause");
}
}
else
{
printf("处理编号超过阙值!!!");
system("pause");
}
}
}
void interface() //界面
{
printf("\n\n");
printf("========界面========\n");
printf("人数: %2d ", exist_people);
printf("| 剩余空间: %2d\n", surplus_people);
for (i = 1; i <= 50; i++)
{
if (telephone[i][0] != '\0')
{
printf("编号:%2s | 姓名:%2s | 电话:%11s \n", code[i], name[i], telephone[i]);
}
}
}
void operation()
{
printf("\n\n");
printf("1)添加 2)删除\n3)修改 4)退出程序\n请输入操作:");
scanf("%d", &x);
switch (x)
{
case 1:
add();
break;
case 2:
delete();
break;
case 3:
madify();
break;
case 4:
count = 1;
break;
default:
error();
break;
}
}
void error()
{
printf("\n\n");
printf("Error!!!\n错误指令,请重新输入\n");
operation();
}
int main()
{
while (1)
{
system("cls");
printf("========通讯录========");
interface();
operation();
if (count == 1)
break;
}
return 0;
}
2.4 gitee上传截图与链接#####
作业三四都在这个目录里面;
我的gitee
作业三四都在这个目录里面;
我的gitee