‘壹’ 如何在Excel中制作 同学通讯录
输入数据,该合并的单元格合并下,等等
‘贰’ 如何制作班级通讯录
/*通讯录中每个同学的信息包含以下内容:学号(id)、姓名(name)、电话号码(tel)。如果需要更多其他信息,请自行添加。
? 程序主菜单包含以下几个功能:
(1) 添加记录:通过键盘输入信息,添加一条通讯录记录。
(2) 删除记录:通过键盘输入学号,删除该学号的记录。
(3) 输出记录:输出通讯录全部记录。
(4) 按姓名查找:通过键盘输入姓名,输出该同学的所有信息。
(5) 保存记录:把通讯录中所有的记录保存到文件中。
(6) 清空记录:删除通讯录中的全部记录,并删除文件。
(7) 退出
提示:
? 程序启动时应判断是否存在记录文件,如果存在,则读取每条记录到链表中。
? 用户选择并完成主菜单某功能后,除了退出程序,应该返回主菜单。
? 添加一条记录时,插入到链表的尾部。
? 查找、删除记录时,如果该记录不存在,则应该输出不存在的提示。
? 添加记录、删除记录时不需要写文件。
? 保存记录时,用覆盖写文件的方法。(或者先删除原文件,再保存全部记录信息)
? 各个功能模块写成函数,由主函数调用。*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# define SIZE sizeof(struct student)
struct student
{
int num;
char name[20];
int telephone;
struct student * next;
};
struct student * Create_stud();
struct student * Insert_stud_node(struct student * head,struct student * stud);
struct student * Delete_stud_node(struct student * head,int num);
void Print_stud_node(struct student * head);
struct student * Find_stud_node(struct student * head,char name[20]);
int main()
{
// FILE * fp;
struct student * head;
struct student * p;
int choice,num,telephone;
char name[20];
do
{
printf("请输入功能选项:\n");
printf("1:创建链表 2:插入节点 3:删除节点 4:输出链表 5:查找 6:保存记录 0:退出 \n");
scanf("%d",&choice);
switch(choice)
{
case 1:
head=Create_stud();
break;
case 2:
printf("Input num,name and score:\n");
p=(struct student *)malloc(SIZE);
scanf("%d%s%d",&num,name,&telephone);
p->num = num;
strcpy(p->name,name);
p->telephone = telephone;
head=Insert_stud_node(head,p);
break;
case 3:
printf("Input num:\n");
scanf("%d",&num);//这里很容易出错,如果他说不能读入内存的话,一般就是少些了取地址符
head = Delete_stud_node(head,num);
break;
case 4:
Print_stud_node(head);
break;
case 5:
printf("nput name:\n");
scanf("%s",&name);
p = Find_stud_node(head,name);
printf("%8d%10s%12d",p->num ,p->name,p->telephone );
break;
/* case 6:
if((fp = fopen("fi.txt","w"))==NULL)
{
printf("File open error!\n");
exit(0);
}
for(p = head;p!=NULL;p = p->next)
{
fwrite(student,Size,1,fp);
fclose(fp);
}
fclose(fp);*/
}
}while(choice!=0);
return 0;
}
struct student * Create_stud()
{
struct student * head;
struct student * p1;
int num;
char name[20];
int telephone;
head = NULL;
printf("please input the students'records:\n");
printf("num name telephone:\n");
scanf("%d%s%d",&num,name,&telephone);
while(num!=0)
{
p1 = (struct student *)malloc(SIZE);
p1->num = num;
strcpy(p1->name,name);
p1->telephone = telephone;
head=Insert_stud_node(head,p1);
scanf("%d%s%d",&num,name,&telephone);
}
return head;
}
struct student * Insert_stud_node(struct student * head,struct student * stud)
{
struct student * p2;
struct student * p3;
p2 = head;
if(head==NULL)
{
head = stud ;//注意这里是把stud这个指针的值赋值给head如果把他俩的位置颠倒程序就会运行出错
head->next = NULL;
}
else
{
while(p2->next !=NULL&&p2->num < stud->num)
{
p3 = p2;
p2 = p2->next;
}
if(stud->num <= p2->num)
{
if(head==p2)
head=stud;
else
p3->next = stud;
stud->next = p2;
}
else
{
p2->next = stud;
stud->next = NULL;
}
}
return head;
}
struct student * Delete_stud_node(struct student * head,int num)
{
struct student * p1;
struct student * p2;
while(head!=NULL && head->num==num )
{
p2 = head;
head = head->next;
free(p2);
}
if(head == NULL)
return NULL;
p1 = head;
p2 = head->next;
while(p2->next!=NULL)
{
if(p2->num == num)
{
p1->next = p2->next ;
free(p2);
}
else
{
p1 = p1->next;
p2 = p2->next;
}
}
return head;
}
struct student * Find_stud_node(struct student * head, char name[20])
{
struct student * p2;
//struct student * p3;
struct student * p1;
if(head==NULL)
printf("NO Record!\n");
else
{
p2 = head;
while(p2 != NULL && strcmp( p2->name, name )/*&&p2->next != NULL*/)
{
p2 = p2->next;
}
if( !strcmp( p2->name, name ) )
p1 = p2;
else
printf("Can't find the Record!\n");
}
return p1;
}
//如果他说错误少了;在某某的前面,一般错误就是少了个大括号"{}"这是常见的错误
void Print_stud_node(struct student * head)
{
struct student * p;
if(head==NULL)
{
printf("No Records\n");
return;
}
p = head;
printf("The students'recods is\n");
printf("num name score\n");
for(p;p;p = p->next)
printf("%8d%20s%6d\n",p->num,p->name,p->telephone);
}