?? 學生成績管理系統(c語言)課程設計報告.txt
字號:
學生成績管理系統
要求是這樣的
1、用c語言編寫一個簡單的學生信息管理程序,能實現對學生信息的簡單管理。
2、具體要求:
建立一個4個學生的信息登記表,每個學生的信息包括:學號,姓名,和3門課程的成績(FOX,C,ENGLISH)。
程序運行時顯示一個簡單的菜單,例如:
(1):信息輸入(INPUT)
(2):總分統計(COUNT)
(3):總分排序(SORT)
(4):查詢(QUERY)
其中:
(1):對4個學生的信息進行輸入;
(2):對每個學生的3門課程統計總分;
(3):對4個學生的總分按降序排序并顯示出來;
(4):查詢輸入一個學號后,顯示出該學生的有關信息;
............
偶先寫了個...
#i nclude<iostream.h>
#i nclude<stdlib.h>
struct student
{
int num;
char name[20];
int foxscore;
int cscore;
int englishscore;
struct student *next;
};
void menu()
{
cout<<" welecome to my student grade management system"<<endl;
cout<<" please follow everyone step in the menu"<<endl;
cout<<" 1.input information"<<endl;
cout<<" 2.total scores"<<endl;
cout<<" 3.sort"<<endl;
cout<<" 4.query"<<endl;
cout<<" ***************************************************"<<endl;
}
struct student *creat(struct student *head) // 函數返回的是與節點相同類型的指針
{
struct student *p1,*p2;
p1=p2=(struct student*) malloc(sizeof(struct student)); // 申請新節點
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore; // 輸入節點的值
p1-> next = NULL; // 將新節點的指針置為空
while(p1->num>0)
{
if (head==NULL) head=p1; //空表,接入表頭
else p2->next=p1; // 非空表,接到表尾
p2 = p1;
p1=(struct student *)malloc(sizeof(struct student)); //申請下一個新節點
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore;
//輸入節點的值
}
return head; //返回鏈表的頭指針
}
void count(struct student *head)
{
struct student *temp;
temp=head; //取得鏈表的頭指針
while(temp!==NULL)
{
int m;
m=temp->foxscore+temp->cscore+temp->englishscore;
cout<<m<<endl;//輸出鏈表節點的值
temp=temp->next; //跟蹤鏈表增長
}
}
void sort(struct student *head)
{
struct student *tp;
tp=head;
int a[4];//定義總分數組
int i,j,k;
while(temp!==NULL)
{
a[i]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
i=i+1;
}
for(j=1;j<=3;j++)//冒泡法排序
for(k=1;k<=4-j;k++)
if(a[k]<a[k+1])
{
int t=a[k];a[k]=a[k+1];a[k+1]=t;
}
for(i=1;i<5;i++)
cout<<a[i]<<endl;
}
void query(struct student *head)
{
struct student *temper;
temper=head;
int number;
cin>>number;
for(int i=1;i<=4;i++)
{
if(number==temper->num)
{
cout<<" name is:"<<temper->name<<endl;
cout<<" fox score is:"<<temper->foxscore<<endl;
cout<<" c score is:"<<temper->cscore<<endl;
cout<<" English score is:"<<temper->englishscore<<endl;
cout<<" congratulation,syetem have found what you want to search"<<endl;
}
temper=temper->next;
}
}
void main()
{
menu();
cout<<" firstly,please input information:"<<endl;
struct student *head;
head=NULL; /* 建一個空表*/
head=creat(head); /* 創建單鏈表*/
cout<<" secondly,count the total score each student:"<<endl;
count(head);
cout<<" thirdly,sorting the total score:"<<endl;
sort(head);
cout<<" enter num that you can search each shtudent's information"<<endl;
query(head);
cout<<" thanks you for use my student grade management system"<<endl;
}
編譯時候都沒有錯....
debug輸入時候出現了錯誤....
調試運行后發現原來是while循環出了問題啊
修改后.........
#i nclude<iostream.h>
#i nclude<stdlib.h>
struct student
{
int num;
char name[20];
int foxscore;
int cscore;
int englishscore;
struct student *next;
};
void menu()
{
cout<<" welecome to my student grade management system"<<endl;
cout<<" please follow everyone step in the menu"<<endl;
cout<<" 1.input information"<<endl;
cout<<" 2.total scores"<<endl;
cout<<" 3.sort"<<endl;
cout<<" 4.query"<<endl;
cout<<" ***************************************************"<<endl;
}
struct student *creat(struct student *head) // 函數返回的是與節點相同類型的指針
{
struct student *p1,*p2;
p1=p2=(struct student*) malloc(sizeof(struct student)); // 申請新節點
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore; // 輸入節點的值
p1-> next = NULL; // 將新節點的指針置為空
for(int i=1;i<=4;i++)
{
if (head==NULL) head=p1; //空表,接入表頭
else p2->next=p1; // 非空表,接到表尾
p2 = p1;
p1=(struct student *)malloc(sizeof(struct student)); //申請下一個新節點
if(i<=3)
{
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore;
}
//輸入節點的值
}
return head; //返回鏈表的頭指針
}
void count(struct student *head)
{
struct student *temp;
temp=head; //取得鏈表的頭指針
for(int i=1;i<=4;i++)
{
int m;
m=temp->foxscore+temp->cscore+temp->englishscore;
cout<<m<<endl;//輸出鏈表節點的值
temp=temp->next; //跟蹤鏈表增長
}
}
void sort(struct student *head)
{
struct student *tp;
tp=head;
int a[4];//定義總分數組
int i,j,k;
a[1]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[2]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[3]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[4]=tp->foxscore+tp->cscore+tp->englishscore;
for(j=1;j<=3;j++)//冒泡法排序
for(k=1;k<=4-j;k++)
if(a[k]<a[k+1])
{
int t=a[k];a[k]=a[k+1];a[k+1]=t;
}
for(i=1;i<5;i++)
cout<<a[i]<<endl;
}
void query(struct student *head)
{
struct student *temper;
temper=head;
int number;
cin>>number;
for(int i=1;i<=4;i++)
{
if(number==temper->num)
{
cout<<" name is:"<<temper->name<<endl;
cout<<" fox score is:"<<temper->foxscore<<endl;
cout<<" c score is:"<<temper->cscore<<endl;
cout<<" English score is:"<<temper->englishscore<<endl;
cout<<" congratulation,syetem have found what you want to search"<<endl;
}
temper=temper->next;
}
}
void main()
{
menu();
cout<<" firstly,please input information:"<<endl;
struct student *head;
head=NULL; /* 建一個空表*/
head=creat(head); /* 創建單鏈表*/
cout<<" secondly,count the total score each student:"<<endl;
count(head);
cout<<" thirdly,sorting the total score:"<<endl;
sort(head);
cout<<" enter num that you can search each shtudent's information"<<endl;
query(head);
cout<<" thanks you for use my student grade management system"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -