『壹』 如何在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);
}