資源簡介
Visual C++6.0下可運行,功能包含著 對一個有N個學生的班級,通過該系統實現對該班級學生的基本信息進行錄入、顯示、修改、刪除、保存等操作的管理。
1)本系統采用一個包含N個數據的結構體數組,每個數據的結構包括:學號、姓名、性別、年齡、備注。
(2)本系統顯示這樣的菜單:
請選擇系統功能項:
a 學生基本信息錄入
b 學生基本信息顯示
c 學生基本信息保存
d 學生基本信息刪除
e 學生基本信息修改(要求先輸入密碼)
f 學生基本信息查詢
1)按學號查詢
2)按姓名查詢
3)按性別查詢
4)按年齡查詢
g. 退出系統
(3)執行一個具體的功能之后,程序將重新顯示菜單。
(4)將學生基本信息保存到文件中。
(5)進入系統之前要先輸入密碼。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#define?N?29
#define?MAX_NAME?29
#define?MAX_ADDRESS?29
#define?MAX_PASSWORD?29
typedef?struct?person
{
char?name[MAX_NAME];
char?sex;
long?num;
int?age;
char?address[MAX_ADDRESS];
}Person;
typedef?struct?link
{
Person?per;
struct?link?*next;
}link;
void?Password();
void?Zailu();
int?Menu();
int?Menu2();
void?Append();
void?Show();
void?Search();
void?Delete();
void?Update();
void?Sort();
void?Save();
void?Input(Person?*p);
void?Printf(Person?*p);
void?Printf2(Person?*p);
void?SortName();
void?SortNumber();
void?Query(int?flag);
void?Number_Query();
void?Name_Query();
void?Sex_Query();
void?Age_Query();
int?Menu_Query();
struct?link?*head=NULL;
void?main()
{
Password();
while(1)
{
switch(Menu())
{
case?1:
Zailu();
break;
case?2:
Append();
break;
case?3:
Search();
break;
case?4:
Delete();
break;
case?5:
Update();
break;
case?6:
Sort();
break;
case?7:
Show();
break;
case?8:
Save();
break;
case?9:
printf(“謝謝使用!歡迎下次再來......\n“);
exit(0);
default:
printf(“error\n“);
break;
}
}
}
void?Password()
{
char?password[MAX_PASSWORD]pw[9]=“920“;
int?flag=0ij;
j=strlen(pw);
printf(“請輸入密碼:“);
while(flag==0)
{
for(i=0;i {
password[i]=getch();
printf(“*“);
}
password[i]=‘\0‘;
if(strcmp(passwordpw)==0)
{
printf(“\n歡迎歡迎,熱烈歡迎......\n“);
getch();
flag=1;
}
else
printf(“密碼錯誤,請重新輸入:“);
}
}
void?Zailu()
{
FILE?*fp;
struct?link?*p=head*p1=NULL;
fp=fopen(“dangan.txt““r“);
while(!feof(fp))
{
p1=(struct?link?*)malloc(sizeof(struct?link));
p1->next=NULL;
if(head==NULL)
head=p1;
else
p->next=p1;
p=p1;
fscanf(fp“%s?%c?%ld“p->per.name&p->per.sex&p->per.num);
fscanf(fp“%d%s“&p->per.age&p->per.address);
}
fclose(fp);
printf(“讀取文件成功!按任意鍵繼續....“);
getch();
}
void?Append()
{
struct?link?*p=NULL*pr=head;
char?ch;
p=(struct?link?*)malloc(sizeof(struct?link));
p->next=NULL;
if(head==NULL)
head=p;
else
{
while(pr->next!=NULL)
{
pr=pr->next;
}
pr->next=p;
}
Input(&(p->per));
printf(“是否繼續添加(Y繼續,N返回菜單)“);
scanf(“?%c“&ch);
if(ch==‘Y‘?||?ch==‘y‘)
Append();
}
void?Show()
{
struct?link?*p=head;
int?i=0;
if(head!=NULL)
printf(“姓名????????性別???????學號??????????年齡?????地址\n“);
while(p!=NULL)
{
i++;
Printf2(&(p->per));
p=p->next;
}
if(i==0)
printf(“沒有該學生\n“);
printf(“\n按任意鍵繼續.....“);
getch();
}
void?Delete()
{
int?flag=0;
char?ch;
????char?mingzi[N];
struct?link?*p=head*pr=head;
puts(“請輸入要刪除的學生姓名:“);
scanf(“%s“&mingzi);
printf(“確定要刪除嗎?(Y是,N否)“);
scanf(“?%c“&ch);
if(ch==‘y‘?||?ch==‘Y‘?)
{
while(p!=NULL)
{
if(strcmp(p->per.namemingzi)==0)
{
Printf(&(p->per
- 上一篇:合一算法演示
- 下一篇:STC單片機原理圖庫和PCB庫
評論
共有 條評論