1. C++ c語言程序設計 題目:學生成績統計
//按你要求來的 不過只輸入了3組數,你可以自己改
#include<stdio.h>
#include<string.h>
#define max 100
typedef struct
{
char name[max];// 姓名
int num;//學號
int eng;//英語成績
int pro;//程序設計成績
int maths;/敬山/數學成績
}student;
void input(student s[],int n)//扒畝輸入以及求總分
{
int sum=0;
for(int i=0;i<n;i++)
{
printf("輸入第%d個學生的姓名:\n",i+1);gets(s[i].name);
printf("輸入第%d個學生的學號:\n",i+1);scanf("%d",&s[i].num);
printf("輸入第%d個學生的英語成績:\n",i+1);scanf("%d",&s[i].eng);
printf("輸入第%d個學生的程序設計成績:\n",i+1);scanf("%d",&s[i].pro);
printf("輸入第%d個學生的數學成績:\n",i+1);scanf("%d",&s[i].maths);
sum=s[i].eng+s[i].pro+s[i].maths;
printf("總分為:%d\n",sum);
fflush(stdin);
}
}
void sumscore(student s[],int n)//單科成績總和
{
int sum_eng=0,sum_pro=0,sum_maths=0;
for(int i=0;i<n;i++)
{
sum_eng+=s[i].eng;
sum_pro+=s[i].pro;
sum_maths+=s[i].maths;
}
printf("英語春稿森總成績為:%d\n",sum_eng);
printf("程序設計總成績為:%d\n",sum_pro);
printf("數學總成績為:%d\n",sum_maths);
}
void searchst(student s[],int n)//查找學生
{
char e[max];int number;
printf("輸入要查詢的姓名:\n");gets(e);
printf("輸入要查詢的學號:\n");scanf("%d",&number);
for(int i=0;i<n;i++)
if(!strcmp(s[i].name,e)&&number==s[i].num)
{
printf("英語成績:%d\n程序設計成績:%d\n數學成績:%d\n",s[i].eng,s[i].pro,s[i].maths);
printf("總成績為:%d\n",s[i].eng+s[i].pro+s[i].maths);
return;
}
printf("查無此人!");
}
void main()
{
student s[3];int n=3;//這里只用了3個測試,30個太誇張了,可以改成30組數....
input(s,n);
printf("\n");
sumscore(s,n);
printf("\n");
searchst(s,n);
printf("\n");
}
2. 利用C語言,建立一個五個學生的信息登記表,要求有學號、姓名、和三門課的成績
絕對能用,VC6.0運行調試可以用,試試就知道了,給點分啊
# include<stdio.h>
#include <string.h>
int presentnum ;
typedef struct student
{
int MATH;
int C;
int ENGLISH;
int TOTAL;
} stu;
char putinstuinfo(stu info[])
{
int i;
char fenshu=0;
for(i=1;i<=5;i++)
{
printf("%s%d%s\n","輸入第",i,"個學生信息(科目之間相差一個tab鍵):");
printf("%s\t%s\t%s\t\n","MATH","C","ENGLISH");
scanf("%d %d %d",&info[i-1].MATH,&info[i-1].C,&info[i-1].ENGLISH);
info[i-1].TOTAL=info[i-1].MATH+info[i-1].C+info[i-1].ENGLISH;
}
printf("%s\n","輸入@,回車保存學生信息");
while(getchar()!='@')
{
printf("%s\n","輸入@,回車保存學生信息");
printf("請保存信息\n");
}
return '@';
}
void sequencetotal(stu info[],int totls[])
{
int i,j,temptotal,tempxiabiao;
for(i=0;i<5;i++)
{
totls[i]=i;
}
for(i=0;i<5;i++)
for(j=0;j<5-i-1;j++)
if(info[j].TOTAL<info[j+1].TOTAL)
{
temptotal=info[j].TOTAL;
info[j].TOTAL=info[j+1].TOTAL;
info[j+1].TOTAL=temptotal;
tempxiabiao=totls[j];
totls[j]=totls[j+1];
totls[j+1]=tempxiabiao;
}
}
int main(void)
{
char getnum;
stu info[5];
stu tempinfo[5];
int i;
int totls[5];
memset(&totls,0,sizeof(totls));
memset(&info,0,sizeof(info));
presentnum=1;
menu:
printf("%s\n","(1):信息輸入(INPUT)");
printf("%s\n","(2):顯示信帶漏息(DISPLAY)");
printf("%s\n","(3):總分統計(COUNT)");
printf("%s\n","(4):總分排序(SORT)");
printf("%s\n","(5):查詢(QUERY)");
printf("%s\n","(@):返哪前回主菜單");
while(1)
{
printf("%s\t","輸入命令數字:");
getnum=getchar();
printf("\n");
switch(getnum)
{
case '1':
printf("%s\n","錄入信息");
printf("\n");
if(putinstuinfo(info)=='@')
{
printf("保存信息成功\n");
goto menu;
}
break;
case '2':
printf("%s\n","顯示信息");
printf("\n");
printf("%s\t%s\t%s\t\n","MATH","C","ENGLISH");
printf("%d\t%d\t%d\t\n",info[presentnum-1].MATH,info[presentnum-1].C,info[presentnum-1].ENGLISH);
break;
case '3':
printf("%s\n","總分統計");
printf("\n");
for(i=0;i<5;i++)
{
printf("%s%d%s\t%d\n","第",i+1,"學生總分:",info[i].TOTAL);
}
break;
case '4':
printf("%s\n","蠢緩爛總分排序");
printf("\n");
memcpy(tempinfo,info,sizeof(info));
sequencetotal(info,totls);
memcpy(info,tempinfo,sizeof(tempinfo));
printf("%s\t\t%s\t%s\t%s\t\t%s\n","名稱","MATH","C","ENGLISH","TOTAL");
for(i=0;i<5;i++)
{
printf("%s%d%s\t%d\t%d\t%d\t\t%d\t\n","學生",totls[i]+1,"成績",info[totls[i]].MATH,info[totls[i]].C,info[totls[i]].ENGLISH,info[totls[i]].TOTAL);
}
break;
case '5':
printf("%s\n","查詢學生信息");
printf("\n");
printf("%s\t","輸入學生序號:");
scanf("%d",&presentnum);
printf("%s\t%s\t%s\t%s\n","MATH","C","ENGLISH","TOTAL");
printf("%d\t%d\t%d\t%d\t\n",info[presentnum-1].MATH,info[presentnum-1].C,info[presentnum-1].ENGLISH,info[presentnum-1].TOTAL);
break;
case '@':
goto menu;
break;
default:
break;
}
}
}
3. C語言課程設計學生成績統計
# include <iostream>
# include <fstream>
# include <string.h>
#include <conio.h>//用getch();
using namespace std;
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌Student類﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class Student
{
public:
char name[20];
char Id[20];
int MTnum; //數學課程得分
int ENnum; //英語課程得分
int PHnum; //物理課程得分
int sum; //總分
Student * Next;
void Input()
{
cout<<"\t\t請輸入學生的姓名:"; cin>>name;
cout<<"\t\t請輸入學生的學號:"; cin>>Id;
cout<<"\t\t請輸入數學課程的成績:"; cin>>MTnum;
cout<<"\t\t請輸入英語課程的成績:"; cin>>ENnum;
cout<<"\t\t請輸入物理課程的成績:"; cin>>PHnum;
sum=MTnum+ENnum+PHnum;
}
void ReadFile(istream & in)
{
in>>name>>Id>>MTnum>>ENnum>>PHnum>>sum;
}
void Show()
{
cout<<"姓名:"<<name<<endl<<"學號:"<<Id<<endl<<"C++:"<<MTnum<<endl
<<"數學:"<<ENnum<<endl<<"外語:"<<PHnum<<endl<<"總成
績:"<<sum<<endl<<endl<<endl;
}
};
//﹌﹌﹌﹌﹌﹌﹌﹌﹌Studentmassage類﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class Studentmassage
{
public:
Studentmassage();
~Studentmassage();
void ShowMenu();
void Find();
void Save();
void ModifyItem();
void RemoveItem();
void Swap(Student *,Student *);
void Sort();
//void Unpass();
int ListCount();
//void Average();
void Display()
{
for(Student * p=Head->Next;p!=End;p=p->Next)
p->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
void AddItem()
{
End->Input();
End->Next=new Student;
End=End->Next;
cout<<"添加成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
private:
Student * Head,* End;
ifstream in;
ofstream out;
Student *FindItem(char * name)
{
for(Student * p=Head;p->Next!=End;p=p->Next)//匹配成功則返回上一個指針,
不成功就返回空
if(!strcmp(p->Next->name,name))return p;
return NULL;
}
Student *FindID(char * Id)
{
for(Student * p=Head;p->Next!=End;p=p->Next)//匹配成功則返回上一個指針,
不成功就返回空
if(!strcmp(p->Next->Id,Id))return p;
return NULL;
}
};
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌構造函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::Studentmassage()
{
Head=new Student;
Head->Next=new Student;
End=Head->Next;
in.open("sort.txt");
if(!in)
cout<<"這是一個新系統,無學生信息。請先輸入。"<<endl;
else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new Student;
End=End->Next;
}
in.close();
cout<<"\t\t讀取學生信息成功!"<<endl;
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析構函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::~Studentmassage()
{
Save();
for(Student * temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete temp;
}
delete Head,End;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌菜單﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ShowMenu()
{
cout<<"〓〓〓〓〓〓〓〓〓〓 ☆ 學 生 成 績 管 理 系 統 ☆ 〓〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓★★★★★ ★★★★★★★ ★★★★★〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 1.增加學生成績 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 2.顯示學生成績 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 3.排序統計成績 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 4.查找學生成績 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 5.刪除學生成績 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 6.修改學生信息 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 0.安全退出系統 ☆ ★〓〓〓〓〓〓〓〓
〓"<<endl;
cout<<"\n\t\t\n\t\t請選擇:";
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Find()
{
char name[20] ,Id[10];
int x;
Student * p=NULL;
cout<<"\n\t\t*********************************\n";
cout<<"\t\t※ 1.按學生的姓名查找\n\t\t※ 2.按學生學號查找";
cout<<"\n\t\t*********************************\n請選擇:";
cin>>x;
switch(x)
{
case 1:{cout<<"\t\t請輸入要查找的學生的姓名:";cin>>name;
if(p=FindItem(name))
{
p->Next->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到該姓名的學生!"<<'\n'<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}break;
case 2:
{
cout<<"\t\t請輸入要查找的學生的學號:";cin>>Id;
if(p=FindID(Id))
{
p->Next->Show();
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到該學好的學生!"<<'\n'<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}break;
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌修改信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ModifyItem() //修改信息
{
char name[20];
Student * p=NULL;
cout<<"\t\t請輸入要修改的人的姓名:";cin>>name;
if(p=FindItem(name))
{
cout<<"\t\t已找到學生的信息,請輸入新的信息!"<<endl;
p->Next->Input();
cout<<"修改成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌刪除信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::RemoveItem() // 刪除信息
{
char name[20];
Student * p=NULL,*temp=NULL;
cout<<"\t\t請輸入要刪除的學生的姓名:"<<endl;cin>>name;
if(p=FindItem(name))
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t刪除成功!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
else
{
cout<<"\t\t沒有找到!"<<endl;
cout<<"輸入任意字元!繼續……";
getch();
}
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Swap(Student *p1, Student *p2)//交換兩個combox變數的數據域
{
Student *temp=new Student;
strcpy(temp->name,p1->name);
strcpy(temp->Id,p1->Id);
temp->MTnum=p1->MTnum;
temp->ENnum=p1->ENnum;
temp->PHnum=p1->PHnum;
temp->sum=p1->sum;
strcpy(p1->name,p2->name);
strcpy(p1->Id,p2->Id);
p1->MTnum=p2->MTnum;
p1->ENnum=p2->ENnum;
p1->PHnum=p2->PHnum;
p1->sum=p2->sum;
strcpy(p2->name,temp->name);
strcpy(p2->Id,temp->Id);
p2->MTnum=temp->MTnum;
p2->ENnum=temp->ENnum;
p2->PHnum=temp->PHnum;
p2->sum=temp->sum;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int Studentmassage::ListCount()//統計當前鏈表的記錄總數,返回一個整數
{
if(! Head)
return 0;
int n=0;
for(Student * p=Head->Next;p!=End;p=p->Next)
{
n++;
}
return n;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Sort()//對當前鏈表進行排序
{
cout <<"Sorting..."<<endl;
Student *p=NULL,*p1=NULL,*k=NULL;
int n=Studentmassage::ListCount();
if(n<2)
return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->sum>k->sum)
{
Studentmassage::Swap(p,k);
}
}
cout <<"排序完成!"<<endl;
getch();
return;
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Save()
{
out.open("sort.txt");
for(Student *p=Head->Next;p!=End;p=p->Next)
out<<p->name<<"\t"<<p->Id<<"\t"<<p->MTnum<<"\t"
<<p->ENnum<<"\t"<<p->PHnum<<"\t"<<p->sum<<'\n';
out.close();
}
//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌主函數﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int main()
{
int x,i=0;
bool quit=false;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t ◎"<<endl;
cout<<"\t\t◎★★★★【 歡迎進入學生成績管理系統 】★★★★◎"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t ◎"<<endl;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§\n"<<endl;;
Studentmassage Grade;
cout<<"按任意鍵開始……";
getch();
while(!quit)
{
system("cls");
Grade.ShowMenu();
cin>>x;
switch(x)
{
case 0:quit=true;break;
case 1:Grade.AddItem();break;
case 2:Grade.Display();break;
case 3:Grade.Sort();break;
case 4:Grade.Find();break;
case 5:Grade.RemoveItem();break;
case 6:Grade.ModifyItem();break;
}
}
return 0;
}
4. 怎麼用C語言編一個學生成績記錄簿
#include<stdio.h>
#include<並畢stdlib.h>
#include<string.h>
typedef struct
{
char id[15];
char name[10];
int score;
} StudentInfo;
typedef struct
{
StudentInfo arr[100];
int length;
} SeqList;
FILE *fp;
char *filePath = "C:/StudentInfo.txt";
void initSeqList(SeqList *L)
{
L->length = 0;
}
void insertSeqList(SeqList *L, int i, StudentInfo info)å
{
int j;
for(j = L->length; j > i; j--)
L->arr[j] = L->arr[j-1];
L->arr[j] = info;
L->length++;
}
void printStudentInfo(StudentInfo info)
{
printf("%s\t%s\t%d\n", info.id, info.name, info.score);
}
void printSeqListWithSeqNo(SeqList L)
{
for(int i = 0; i < L.length; i++)
{
printf("%d\t", i+1);
printStudentInfo(L.arr[i]);
}
}
void printSeqList(SeqList L)
{
for(int i = 0; i < L.length; i++)
printStudentInfo(L.arr[i]);
}
int queryInfoById(SeqList L, char *id)
{
for(int i = 0; i < L.length; i++)
if(strcmp(id, L.arr[i].id)==0)
return i;
return -1;
}
int queryInfoByName(SeqList L, char *name)
{
for(int i = 0; i < L.length; i++)
if(strcmp(name, L.arr[i].name)==0)
return i;
return -1;
}
void save2File(SeqList L)
{
fp = fopen(filePath, "w");
for (int i = 0; i < L.length; i++)
fprintf(fp, "%s\t%s\t%d\n", L.arr[i].id, L.arr[i].name, L.arr[i].score);
}
void showMenu(SeqList L);
void addInfo(SeqList L)
{
StudentInfo info;
int index;
do {
printf("請輸入學號:");
scanf("%s"緩蠢, info.id);
index = queryInfoById(L, info.id);
if (index != -1)
{
printf("輸入的學擾蔽陪號已存在。\n");
printStudentInfo(L.arr[index]);
}
} while(index != -1);
do {
printf("請輸入姓名:");
scanf("%s", info.name);
index = queryInfoByName(L, info.name);
if(index != -1)
{
printf("輸入的姓名已存在。\n");
printStudentInfo(L.arr[index]);
}
} while(index != -1);
printf("請輸入成績:");
scanf("%d", &info.score);
L.arr[L.length] = info;
L.length++;
save2File(L);
}
void editInfo(SeqList L)
{
StudentInfo info;
char choice;
printf("1. 按學號修改\n2. 按姓名修改\n3. 返回上一層\n");
while((choice=getchar())=='\n');
int index;
if(choice == '1' || choice == '2')
{
if(choice == '1')
{
printf("請輸入學號:");
scanf("%s", info.id);
index = queryInfoById(L, info.id);
} else {
printf("請輸入姓名:");
scanf("%s", info.name);
index = queryInfoByName(L, info.name);
}
if(index != -1)
printStudentInfo(L.arr[index]);
else {
printf("%s 為 %s 的學生不存在\n", choice==1?"學號":"姓名", choice==1?info.id:info.name);
editInfo(L);
return;
}
printf("成績改為:");
scanf("%d", &L.arr[index].score);
save2File(L);
}else if(choice == '3')
showMenu(L);
else {
printf("選擇有誤,請重新選擇\n");
editInfo(L);
return;
}
}
void insertSort(SeqList *L)
{
for(int j = 1; j < L->length; j++)
{
StudentInfo key = L->arr[j];
int i = j - 1;
while(i >= 0 && L->arr[i].score < key.score)
{
L->arr[i+1] = L->arr[i];
i--;
}
L->arr[i+1] = key;
}
}
void statisticInfo(SeqList L)
{
// 顯示 60 分以下、60~79、80~89、90 分以上各分數段的學生信息
SeqList sectionListArr[4];
for (int i = 0; i < 4; i++)
initSeqList(§ionListArr[i]);
float sum = 0, average, passedRate;
for (int i = 0; i < L.length; i++)
{
int score = L.arr[i].score;
sum += score;
if(score < 60)
insertSeqList(§ionListArr[0], sectionListArr[0].length, L.arr[i]);
else if(score >= 60 && score < 80)
insertSeqList(§ionListArr[1], sectionListArr[1].length, L.arr[i]);
else if(score >= 80 && score < 90)
insertSeqList(§ionListArr[2], sectionListArr[2].length, L.arr[i]);
else insertSeqList(§ionListArr[3], sectionListArr[3].length, L.arr[i]);
}
average = sum/L.length;
passedRate = (L.length-sectionListArr[0].length)*100.0/L.length;
insertSort(&L);
printf("60 分以下的學生:\n");
printSeqList(sectionListArr[0]);
printf("\n60 ~ 79 分的學生:\n");
printSeqList(sectionListArr[1]);
printf("\n80 ~ 89 分的學生:\n");
printSeqList(sectionListArr[2]);
printf("\n90 分以上的學生:\n");
printSeqList(sectionListArr[3]);
printf("\n及格率:%.1f %%\n平均分:%.1f\n", passedRate, average);
printf("按順序從高到低排序:\n");
insertSort(&L);
printSeqListWithSeqNo(L);
printf("\n最高分:\n");
printStudentInfo(L.arr[0]);
printf("\n最低分:\n");
printStudentInfo(L.arr[L.length-1]);
}
void queryInfo(SeqList L)
{
char choice;
printf("1. 按學號查詢\n2. 按姓名查詢\n3. 返回上層\n");
while((choice=getchar())=='\n');
int index;
if (choice == '1')
{
char id[15];
printf("請輸入學號:");
scanf("%s", id);
index = queryInfoById(L, id);
} else if(choice == '2') {
char name[10];
printf("請輸入姓名:");
scanf("%s", name);
index = queryInfoByName(L,name);
} else if(choice == '3') {
showMenu(L);
return;
} else {
printf("選擇有誤,請重新選擇\n");
queryInfo(L);
return;
}
if(index == -1)
printf("沒有查詢到結果\n");
else
printStudentInfo(L.arr[index]);
}
void showMenu(SeqList L)
{
char choice;
printf("\n1. 查詢\n2. 添加成績\n3. 修改成績\n4. 統計分析\n5. 退出\n");
while((choice = getchar()) == '\n');
switch(choice)
{
case '1': queryInfo(L); break;
case '2': addInfo(L); break;
case '3': editInfo(L); break;
case '4': statisticInfo(L); break;
case '5': exit(0);
}
}
int main(void)
{
StudentInfo temp;
SeqList *L = (SeqList*)malloc(sizeof(SeqList));
do {
initSeqList(L);
fp = fopen(filePath, "r");
int i = 0;
while(fscanf(fp, "%s%s%d", temp.id, temp.name, &temp.score) != EOF)
insertSeqList(L, i++, temp);
showMenu(*L);
fclose(fp);
}while(1);
return 0;
}
5. 用C語言數組寫一個學生基本信息表,包括學號,姓名,年齡,成績。有5個學生。
#include<stdio.h>橘數
#defineN5
typedefstructStudent
{
intnumber;
charname[64];
intage;
floatgrade;
}STUDENT;
intmain()
{
inti;
STUDENT歲喚stud[N]={
{10001,"張三",18,85.5},
{10002,"李四",19,88.5},
{10003,"王五",20,90.8},
{10004,"小明",21,60.0},
{10005,"小紅",18,75.5}
};
for(i=0;i<N;i++)
printf("學號=%d 姓名=%s 年齡=%d 成績=%.2f ",
stud[i].number,stud[i].name,stud[i].age,stud[i].grade);
return0;
}
運行結果:
學號=10001 姓名=張三 年齡=18 成績=85.50
學號=10002 姓名=李乎伍凱四 年齡=19 成績=88.50
學號=10003 姓名=王五 年齡=20 成績=90.80
學號=10004 姓名=小明 年齡=21 成績=60.00
學號=10005 姓名=小紅 年齡=18 成績=75.50
6. c語言 統計各個分數段的學生人數
#include <stdio.h> //使用printf函數要包含的頭文件void main(void) //主函數
{
int n;
int x1=0,x2=0,x3=0,x4=0,x5=0;
printf("請輸入學生的成績1~100:\n");
scanf("%d",&n);
while(n!=-1)
{
if(1<=n&&n<=59)
{
x1+=1;
}
else if(60<=n&&n<=69)
{
x2+=1;
}
else if(70<=n&&n<=79)
{
x3+=1;
}
else if(80<=n&&n<=89)
{
x4+=1;
}
else
{
x5=+1;
}
scanf("%d",&n);
}
printf("1~59分數段的人數為:%d\n",x1);
printf("60~69分數段的人數為:%d\n",x2);
printf("70~79分數段的人數為:%d\n",x3);
printf("80~89分數段的人數為:%d\n",x4);
printf("90~100分數段的人數為:%d\n",x5);
}
7. c語言建立一個學生c語言成績統計表
這個,一開始學習c語言的樣例,網上下載