本文目錄一覽:
- 1、C語言成績管理系統
- 2、用C語言編程實現一個簡單的學生成績管理系統
- 3、用C語言編寫一個學生成績管理系統
- 4、用C語言編寫一個簡單的成績管理系統
- 5、c語言成績管理系統
- 6、C語言 學生成績管理系統?
C語言成績管理系統
#include “stdio.h”
struct stu{
int sid,score;
char g;
};
void scorein(struct stu *p,int n){
int i,t;
for(i=0;in;i++){
scanf(“%d%d”,p[i].sid,p[i].score);
p[i].g = (t=p[i].score)89 t101 ? ‘A’ : t79 t90 ? ‘B’ : t69 t80 ? ‘C’ : t59 t70 ? ‘D’ : ‘E’;
}
}
int sum(struct stu *p,int n){
int s=0;
while(n–)
s+=p++-score;
return s;
}
void dssort(struct stu *p,int n){
int i,j,k;
struct stu t;
printf(“\nSTUID\tSCORE\tCLASS\n=====================\n”);
for(i=0;in;i++){
for(k=i,j=k+1;jn;j++)
if(p[k].scorep[j].score)
k=j;
if(k!=i)
t=p[k],p[k]=p[i],p[i]=t;
printf(“%d\t%d\t%c\n”,p[i].sid,p[i].score,p[i].g);
}
}
void idsort(struct stu *p,int n){
int i,j,k;
struct stu t;
printf(“\nSTUID\tSCORE\tCLASS\n=====================\n”);
for(i=0;in;i++){
for(k=i,j=k+1;jn;j++)
if(p[k].sidp[j].sid)
k=j;
if(k!=i)
t=p[k],p[k]=p[i],p[i]=t;
printf(“%d\t%d\t%c\n”,p[i].sid,p[i].score,p[i].g);
}
}
void query(struct stu *p,int n){
int id;
printf(“\nPlease enter ID(int)…\n”);
scanf(“%d”,id);
while(id-p-sid n)
p++,n–;
if(n=0){
printf(“STUID\tSCORE\tCLASS\n=====================\n”);
printf(“%d\t%d\t%c\n\n”,p-sid,p-score,p-g);
}
else
printf(“No find!\n\n”);
}
void level(struct stu *p,int n){
int d[5],i;
char s[5][7]={“優秀”,”良好”,”中等”,”及格”,”不及格”};
printf(“統計信息如下:\n”);
for(i=0;i5;d[i++]=0);
for(i=0;in;i++,d[p++-g-‘A’]++);
for(i=0;i5;i++)
printf(“%6s:\t%d\t%.2f%%\n”,s[i],d[i],d[i]/(n+0.0)*100);
}
void outinfo(struct stu *p,int n){
int i;
printf(“\nSTUID\tSCORE\n=============\n”);
for(i=0;in;i++)
printf(“%d\t%d\n”,p[i].sid,p[i].score);
}
int main(int argc,char *argv[]){
int n,s;
struct stu a[30];
printf(“Please enter n(int 0n31)…\n”);
if(scanf(“%d”,n)!=1 || n1 || n30){
printf(“Input error, exit…\n”);
return 0;
}
scorein(a,n);//輸入
dssort(a,n);//分數降序
idsort(a,n);//學號升序
query(a,n);//查詢
level(a,n);//等級和百分比
outinfo(a,n);//輸出各位學生信息
printf(“總分: %d”,s=sum(a,n));
printf(” 平均分: %.2f\n”,s/(n+0.0));
return 0;
}
運行樣例:
用C語言編程實現一個簡單的學生成績管理系統
#include stdio.h
#include stdlib.h
#include string.h
#includememory.h
typedef struct student
{
char num[16];
char name[20];
float score[4];
struct student *next;
} stu;
stu *head; // 鏈頭指針
stu* create() // 創建鏈表,從文件讀取信息
{
printf(“Reading student information:\n”);
stu *p=NULL; // 指針,指向個待插入的結點
stu *q=NULL; // 指針,用於在其後插入結點
head = NULL; // 一開始鏈表為空
FILE * r =fopen(“input.dat”,”r”);
p = (stu*)malloc(sizeof(stu));
while(fscanf(r,”%s%s%f%f%f”,p-num,p-name,p-score[0],p-score[1],p-score[2])!=EOF)
{
p-score[3]=(p-score[0]+p-score[1]+p-score[2])/3.0;
fprintf(stdout,”%s\t%s\t%g\t%g\t%g\t%.2f\n”,p-num,p-name,p-score[0],p-score[1],p-score[2],p-score[3]);
p-next=NULL;
if (head == NULL) // head為空,要插入第一個
{
head = p;
} // 結點,讓頭指針指向結點p
else
{ // 否則不是頭結點,應將p結點
q-next = p; // 插入到q結點的後面
}
q = p; // q指向當前最後一個結點
p = (stu*)malloc(sizeof(stu));
}
fclose(r);
if (head != NULL)
{
q-next = NULL; // 讓q所指的最後一個結點的指針域為空說明這已是鏈尾了
}
return head; // 返回頭指針
}
void sort(stu **head,int n)
{
FILE *w=NULL;
if(n==0)
{
w = fopen(“sortByMath.dat”,”w”);
}
else if(n==1)
{
w = fopen(“sortByEnglish.dat”,”w”);
}
else if(n==2)
{
w = fopen(“sortByComputer.dat”,”w”);
}
else if(n==3)
{
w = fopen(“sortByAvg.dat”,”w”);
}
stu *q,*t,*p;
stu * new_head = new stu;
new_head-next=*head;
p=new_head;
t=NULL;
while(t!=new_head-next)
{
p=new_head;
q=p-next;
while(q-next!=t)
{
if((p-next-score[n]) (q-next-score[n]))
{
p-next=q-next;
q-next=q-next-next;
p-next-next=q;
}
p=p-next;
q=p-next;
}
t=q;
}
*head = new_head-next;
p = *head;
q = p-next;
printf(“學號\t姓名\t數學\t英語\t計算機\t平均成績\n”);
int grade = 1;
while(p!=NULL)
{
fprintf(w,”%s\t%s\t%g\t%g\t%g\t%.2f\t%d\n”,
p-num,p-name,p-score[0],p-score[1],p-score[2],p-score[3],grade);
fprintf(stdout,”%s\t%s\t%g\t%g\t%g\t%.2f\t%d\n”,
p-num,p-name,p-score[0],p-score[1],p-score[2],p-score[3],grade);
if(q!=NULL q-score[3] p-score[3]) grade += 1;
p=p-next;
if(q!=NULL) q=q-next;
}
printf(“\n”);
fclose(w);
}
void count(stu* head)
{
float cnt[4][8];
int i,j;
for(i=0;i4;i++)
{
for(j=0;j8;j++)
{
if(j!=2)cnt[i][j]=0;
else cnt[i][j]=100;
}
}
stu* r=head;
while(r!=NULL)
{
r=r-next;
}
}
int main( )
{
head=create();
printf(“Sorting by average score:\n”);
sort(head,3);
system(“pause”);
return 0;
}
用C語言編寫一個學生成績管理系統
// testzhidao4.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include stdio.h
#include stdlib.h
#include string.h
#include malloc.h
struct Student //學生結構體
{
char name[20]; //名字
char sex[10]; //性別
char zuanye[20]; //專業
char code[13]; //學號
char department[20]; //學院
char degree[20]; //學歷
};
struct node
{
struct Student data;
struct node *next;
};
//———————————————————————————
void print_menu(void) // 打印總菜單
{
printf(” |————————————————–|\n”);
printf(” | 總 菜 單 : |\n”);
printf(” |————————————————–|\n”);
printf(” | 1–增加一個學生信息 | 5–刪除一個學生信息 |\n”);
printf(” | 2–顯示一個學生信息 | 6–統計功能 |\n”);
printf(” | 3–顯示一個班級信息 | 7–結束 |\n”);
printf(” | 4–修改一個學生信息 | \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 |\n”);
printf(” |————————————————–|\n”);
}
void print_menu4(void ) //打印修改功能
{
printf(” |————————————————–|\n”);
printf(” | 修 改 功 能 : |\n”);
printf(” |————————————————–|\n”);
printf(” | 1–修改名字 | 5–修改學院 |\n”);
printf(” | 2–修改性別 | 6–修改專業 |\n”);
printf(” | 3–修改學號 | 7–不作修改 |\n”);
printf(” | 4–修改學歷 | \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 |\n”);
printf(” |————————————————–|\n”);
printf(“再次選擇選項 :”);
}
void print_static_function_menu(void) //打印統計功能
{
printf(” |————————————————–|\n”);
printf(” | 統 計 功 能 : |\n”);
printf(” |————————————————–|\n”);
printf(” | 1.男/女人數 | 3.一個專業人數 |\n”);
printf(” | 2.一個班級人數 | 4.結束 |\n”);
printf(” |————————————————–|\n”);
printf(“請選擇選項:\n”);
}
int compareCode(char a[],char b[]) //比較 判斷是否是同一個班級
{
for(int i=0;i9;i++)
if(a[i]!=b[i]) break;
if(i==9) return 1;
else return 0;
}
//————————————————————————————-
void main() //主函數從這裡開始
{
system(“color 3”);
printf(“\n\n\n”);
printf(” \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n”);
printf(” \3\3\3\3\3\3\3\3\3\3 學 生 證 管 理 程 序 \3\3\3\3\3\3\3\3\n”);
printf(” \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n”);
printf(” \3\3\3\3\3\3 作者: \3\3\3\3\3\3\3\n”);
printf(” \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n”);
int choice;
struct node *studentlist=(struct node*)malloc(sizeof(struct node)); //學生鏈表頭 //////////////////////////////////////////////////////////
studentlist-next=NULL;
struct node *temp=NULL;
struct node *p=(struct node*)malloc(sizeof(struct node));
char tempcode[13]; //臨時學號
char tempclass[11]; //臨時班級
char tempzuanye[20];//臨時專業
int count=0;
int choice6,count_male,count_female;
const int sizeStu=sizeof(struct Student);
struct Student data;
FILE *fp;
if((fp=fopen(“d:\\學生證管理程序.dat”,”rb”))==NULL)
{
fp=fopen(“d:\\學生證管理程序.dat”,”wb”);
}
fclose(fp);
fp=fopen(“d:\\學生證管理程序.dat”,”rb”);
while(fread(data,sizeStu,1,fp)==1)
{
p-data=data;
p-next=NULL;
if(studentlist==NULL)
studentlist=p;
else
{ temp=studentlist;
while(temp-next!=NULL){temp=temp-next;}
temp-next=p;
}
p=(struct node*)malloc(sizeof(struct node));
}
fclose(fp);
print_menu(); //打印菜單
scanf(“%d”,choice); //讀進選項
while(choice!=7) //未遇到結束鍵
{
switch(choice)
{
//—————————————————————-
//選項1,增加學生學生證信息
case 1: //輸入一個學生信息
p=(node*) malloc(sizeof(node));
printf(“\n請輸入姓名:”);
scanf(“%s”,p-data.name);
printf(“\n請輸入性別(男/女):”);
scanf(“%s”,p-data.sex);
printf(“\n請輸入學號(12位):”);
scanf(“%s”,p-data.code);
printf(“\n請輸入學制(本科生/研究生):”);
scanf(“%s”,p-data.degree);
printf(“\n請輸入學院:”);
scanf(“%s”,p-data.department);
printf(“\n請輸入專業:”);
scanf(“%s”,p-data.zuanye);
p-next=NULL;
//———————————————————-鏈表連接
if(studentlist==NULL) { studentlist=p; studentlist-next=NULL;}
else {
temp=studentlist;
while(temp-next!=NULL) ////////////////////
{
temp=temp-next;
}
temp-next=p;
p-next=NULL;
}
break;
//———————————————————————
//選項2,顯示給定學生學生證信息
case 2: printf(“\n請輸入學生學號(12位數):”);
scanf(“%s”,tempcode);
temp=studentlist;
while(temp!=NULL) //尋找響應的學生
{
if(strcmp(tempcode,temp-data.code)==0) break;
temp=temp-next;
}
if(temp==NULL) printf(“\n不能找到該學生信息.\n”);
else {
printf(“————————————————\n”);
printf(“姓名: %s\n”,temp-data.name);
printf(“性別: %s\n”,temp-data.sex);
printf(“學號: %s\n”,temp-data.code);
printf(“學歷: %s\n”,temp-data.degree);
printf(“學院: %s\n”,temp-data.department);
printf(“專業: %s\n”,temp-data.zuanye);
printf(“————————————————\n\n”);
}
break;
//—————————————————————–
//選項3,顯示給定班級的學生信息
case 3:printf(“\n請輸入班級號 :”); //輸入班級號
scanf(“%s”,tempclass);
while(strlen(tempclass)10) //班級號位數小於10時,重新輸入
{
printf(“錯誤的班級號,請重新輸入:”);
scanf(“%s”,tempclass);
}
count=0; //班級學生數
temp=studentlist;
while(temp!=NULL) //檢索鏈表,並打印相應學生的學生證信息
{
if(compareCode(tempclass,temp-data.code)) {//打印屬於這個班級的學生
printf(“———————————————–\n”);
printf(“姓名: %s\n”,temp-data.name);
printf(“性別: %s\n”,temp-data.sex);
printf(“學號: %s\n”,temp-data.code);
printf(“學歷: %s\n”,temp-data.degree);
printf(“學院: %s\n”,temp-data.department);
printf(“專業: %s\n”,temp-data.zuanye);
printf(“———————————————–\n”);
count++;
}
temp=temp-next;
}
if(count==0) printf(“該班級還未有成員.\n”);
break;
//——————————————————————-
//選項4,修改給定學生的信息
case 4: printf(“請輸入要作修改的學生證號:”);
scanf(“%s”,tempcode);
temp=studentlist;
while(temp!=NULL) //尋找響應的學生
{
if(strcmp(tempcode,temp-data.code)==0) break;
temp=temp-next;
}
if(temp==NULL) printf(“\n找不到相應學生的信息.\n”);//找不到相應的學生
else {
int choice2;
print_menu4();
scanf(“%d”,choice2);
while(choice2!=7)
{
switch(choice2)
{
case 1:printf(“修改名字:”); //修改名字
scanf(“%s”,temp-data.name);
break;
case 2:printf(“修改性別:”);//修改性別
scanf(“%s”,temp-data.sex);
break;
case 3:printf(“修改學號:”);//修改學號
scanf(“%s”,temp-data.code);
break;
case 4:printf(“修改學歷 :”); //修改學歷
scanf(“%s”,temp-data.degree);
break;
case 5:printf(“修改學院:”); //修改學院
scanf(“%s”,temp-data.department);
case 6:printf(“修改專業:”);//修改專業
scanf(“%s”,temp-data.zuanye);
break;
default: break;
}
printf(“請選擇選項:”);
scanf(“%d”,choice2); //再次選擇菜單選項
}
}
break;
//—————————————————————-
//選項5,刪除給定學號的學生
case 5: printf(“\n輸入學號 :”); //輸入學號
scanf(“%s”, tempcode);
temp=studentlist;
p=temp;
while(temp!=NULL) //尋找相應的學生
{
if(strcmp(tempcode,temp-data.code)==0) break;
p=temp;
temp=temp-next;
}
if(temp==NULL) printf(“\n找不到該學生信息.\n”); //找不到
else if(temp==studentlist) {studentlist=temp-next; free(temp);}
else {
p-next=temp-next;//找到時刪除
free(temp);
}
break;
//——————————————————————
//選項6,統計功能
case 6: print_static_function_menu();
scanf(“%d”,choice6);//選擇菜單選項
while(choice6!=4)
{
switch(choice6)
{
//選項1,統計男女個數
case 1:temp=studentlist;
count_male=0; //男生數
count_female=0; //女生數
while(temp!=NULL) //檢索鏈表查找
{
if(strcmp(temp-data.sex,”男”)==0) count_male++;
if(strcmp(temp-data.sex,”女”)==0) count_female++;
temp=temp-next;
}
printf(“男: %d\n”,count_male);
printf(“女: %d\n”,count_female);
break;
//選項2,統計給定班級的人數
case 2:printf(“請輸入班級號:”);
scanf(“%s”,tempclass); //給定班級
temp=studentlist;
count=0;
while(temp!=NULL) //檢索鏈表查找
{
if(compareCode(temp-data.code,tempclass)==1) count++;
temp=temp-next;
}
printf(“%s班級總人數為: %d\n”,tempclass,count);
break;
case 3:printf(“請輸入專業:”);
scanf(“%s”,tempzuanye); //給定專業
temp=studentlist;
count=0;
while(temp!=NULL) //檢索鏈表查找
{
if(strcmp(temp-data.zuanye,tempzuanye)==0) count++;
temp=temp-next;
}
printf(“%s專業總人數為: %d\n”,tempzuanye,count);
break;
//缺省項
default: break;
}
printf(“請選擇選項:”);
scanf(“%d”,choice6);
}
break;
//—————————————————————–
default:free(p); break;
}
if((fp=fopen(“d:\\學生證管理程序.dat”,”wb”))==NULL)
{
printf(“文件無法打開!”);
return;
}
p=studentlist;
while(p)
{
fwrite(p-data,sizeStu,1,fp);
p=p-next;
}
fclose(fp);
print_menu( );//打印菜單 進入循環
scanf(“%d”,choice);
}
}
用C語言編寫一個簡單的成績管理系統
(ps:沒有自己編譯過)
//我寫 C++比較多
#include stdio.h
#include stdlib.h
#include string.h
#include conio.h
#define TOTAL_STUD 1000
typedef struct stud {
char name[20];
int score;
} students[TOTAL_STUD],sorted[TOTAL_STUD];
void delstud (int i) {
students[i].name = “無效學生”;
students[i].score = -999;
return;
}
#define show(listname,i) printf(“%04d %s %d\n”,i,listname[i].name,listname[i].score);
int cmpfunc (const void * a, const void * b)
{
return ( *(stud*)a.score – *(stud*)b.score );
} // 本段代碼修改自此處
void run(int menu) {
switch (menu) {
case 1:
char uname[20];
int uid,uscore;
printf(“請輸入學生姓名:”);
scanf(“%s”,uname);
printf(“\n 請輸入學生學號:”);
scanf(“%d”,uid);
printf(“\n 請輸入學生成績:”);
scanf(“%d”,uscore);
students[uid].name = uname;
students[uid].score = uscore;
printf(“\n\n插入成功!\n\n”);
break;
case 2:
int delid;
printf(“要刪除誰?學號?”);
scanf(“%d”,delid);
delstud(delid);
break;
case 3:
for (int i = 0; i TOTAL_STUD; i++) {
strcpy(sorted[i].name,students[i].name);
sorted[i].score=students[i].score;
}
qsort(sorted,TOTAL_STUD,sizeof(stud),cmpfunc);
printf(“學號 姓名 分數\n”);
for (int i = 0; i TOTAL_STUD; i++) {
if (sorted[i].score -900) show(sorted,i);
}
break;
case 4:
for (int i = 0; i TOTAL_STUD; i++) {
if (students[i].score -900) show(students,i);
}
break;
case 5:
int delid;
printf(“要查詢誰?學號?”);
scanf(“%d”,delid);
show(students,delid);
break;
default:
printf(“– %d 無此功能。請重試。–“,menu);
}
return;
}
int main() {
int key = -1;
for (int i = 0; i TOTAL_STUD; i++) {
delstud(i);
}
while (key != 0) {
printf(“—成績管理系統 V0.9 —\n 請選擇:\n1 — 錄入\n2 — 刪除\n3 — 排序輸出\n4 — 不排序輸出\n5 — 查詢\n0 — 退出”);
key=getch()-48;
if (key0) run(key);
else {
printf(“謝謝使用!再見!”);
return 0;
}
}
return 0;
}
c語言成績管理系統
#includestdio.h
#includestdlib.h
#includestring.h
#define N 10
struct student
{
char num[5];
char name[20];
int score;
};
struct student stu[N] = { { “1”,”張三”,90 },{ “2”,”李四”,87 },{ “3”,”王五”,76 },{ “4”,”趙六”,67 },{ “5”,”劉七”,56 } };
int count = 5;
void insert(int i) //輸入學生具體信息的函數
{
printf(“第%d個學生的姓名:”, i + 1);
scanf(“%s”, stu[i].name);
printf(“\n”);
printf(“第%d個學生的分數:”, i + 1);
scanf(“%d”, stu[i].score);
printf(“\n”);
count++;
sprintf(stu[i].num,”%d”,count);
}
void input() //輸入數據的函數
{
system(“color 3e”);
void menu();
void insert(int i);
int i, j, k, l, r;
printf(“您想輸入幾個學生的信息? (1-%d) [ ]\b\b”, N – 5);
scanf(“%d”, j);
r = 5 + j;
for (i = 5; ir; i++)
{
printf(“\n輸入第%d個學生的信息。\n”, i + 1);
insert(i);
}
do
{
printf(“返回菜單請按1! [ ]\b\b”);
scanf(“%d”, k);
if (k == 1)
{
system(“cls”);
menu();
}
else
l = 0;
} while (l == 0);
}
void search() //查詢成績的函數
{
void menu();
void printf_one(int k);
struct student s;
int i, k, w0, w1, w2;
do
{
printf(“請選擇查找的類別: 1.姓名 2.學號 [ ]\b\b”);
scanf(“%d”, w1);
if (w11 || w12)
{
printf(“輸入錯誤!請重新輸入!\n”);
w2 = 1;
}
else
w2 = 0;
} while (w2 == 1);
if (w1 == 1) //按姓名查找
{
do
{
k = -1;
do
{
printf(“\n請輸入您想查找的學生的姓名!\nName:”);
scanf(“%s”, s.name);
for (i = 0; i5; i++)
if (strcmp(s.name, stu[i].name) == 0)
{
k = i;
s = stu[i];
}
if (k == -1) //沒有找到
{
int o;
printf(“\n\n沒有這個學生的信息!\n”);
printf(“What do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”, o);
if (o == 1)
{
system(“cls”);
search(); //繼續查找
}
else
{
system(“cls”);
menu(); //返回菜單
}
}
} while (k == -1);
system(“cls”);
printf_one(k); //查找到以後輸出這個學生的信息
printf(“\nWhat do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”, w0);
} while (w0 == 1);
system(“cls”);
menu(); //不在查找時返回菜單
}
else //按學號查找
{
do
{
k = -1;
do
{
printf(“\n請輸入您想查找的學生的學號!\nNum:”);
scanf(“%s”, s.num);
for (i = 0; i5; i++)
if (strcmp(s.num, stu[i].num) == 0) //找到了
{
k = i;
s = stu[i];
}
if (k == -1) //沒有找到
{
int o;
printf(“\n\n沒有這個學生的信息!\n”);
printf(“What do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”, o);
if (o == 1)
{
system(“cls”);
search(); // 繼續查找
}
else
{
system(“cls”);
menu(); //返回菜單
}
}
} while (k == -1);
system(“cls”);
printf_one(k); //找到後輸出這個學生的信息
printf(“\nWhat do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”, w0);
} while (w0 == 1);
system(“cls”);
menu(); //不在查找時返回菜單
}
}
void xiugai() //修改學生信息的函數
{
void menu();
void printf_one(int k);
void xiugai_2();
struct student s;
int i,n,k,w0=1,w1,w2=0,o;
do
{
k=-1;
do
{
printf(“\n請輸入您想要修改的學生的姓名!Name:”);
scanf(“%s”,s.name);
for(i=0;i5;i++)
if(strcmp(s.name,stu[i].name) == 0) //與其中一個學生匹配
{
k = i;
s = stu[i];
}
if(k == -1) // 沒有找到輸入的學生
{
printf(“\n\n沒有這個學生的信息!\n”);
printf(“What do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”,o);
if(o == 1)
{
system(“cls”);
//xiugai(); //繼續修改
}
else
{
system(“cls”);
menu(); //返回菜單
}
}
}while(k == -1);
system(“cls”);
printf(“修改這個學生的分數:”);
scanf(“%d”, stu[k].score);
printf(“\n”);
printf_one(k); //輸出這個學生的信息
printf(“\nWhat do you want to do?\n\t1.繼續 2.返回菜單 [ ]\b\b”);
scanf(“%d”, o);
if (o != 1)
{
system(“cls”);
menu(); //返回菜單
}
}while(1);
}
void printf_all() //輸出所有學生成績的函數
{
void menu();
system(“color 4e”);
int i, j, k;
for (i = 0; iN; i++)
{
printf(“學號:%s 姓名:%s 分數:%d\n”, stu[i].num, stu[i].name, stu[i].score);
}
do
{
printf(“返回菜單請按1 [ ]\b\b”);
scanf(“%d”, j);
if (j == 1)
{
system(“cls”);
menu();
}
else
{
k = 0;
}
} while (k == 0);
}
void printf_one(int k) //輸出某一個學生的信息的函數
{
printf(“學號: %s 姓名: %s 分數: %d”, stu[k].num, stu[k].name, stu[k].score);
}
void Exit() //退出系統的函數
{
exit(0);
}
void menu() //菜單函數
{
system(“color 2e”);
printf(“\n\t\t\t歡迎使用學生學籍管理系統!\n”);
printf(“\n”);
int n, m;
do
{
puts(“\t\t********************菜單*********************”);
puts(“\t\t*********************************************”);
puts(“\t\t**************學生學籍管理系統***************”);
puts(“\t\t*********************************************”);
puts(“\t\t*********************************************”);
puts(“\t\t******* 1–輸入數據 ****”);
puts(“\t\t******* 2–查詢成績 ****”);
puts(“\t\t******* 3–修改成績 ****”);
puts(“\t\t******* 4–輸出所有學生成績 ****”);
puts(“\t\t******* 5–統計及格和優秀的人數 ****”);
puts(“\t\t******* 6–輸出所有不及格學生的成績 **”);
puts(“\t\t******* 7–輸出所有優秀學生姓名和成績*”);
puts(“\t\t******* 8–退出系統 ****”);
puts(“\t\t*********************************************”);
printf(“請選擇服務種類(1~8): [ ]\b\b”);
scanf(“%d”, n);
if (n1 || n8)
{
system(“cls”);
printf(“選擇錯誤! 請重新選擇!\n”);
m = 1;
}
else
{
m = 0;
}
} while (m == 1);
switch (n)
{
case 1: system(“cls”); input(); break;
case 2: system(“cls”); search(); break;
case 3: system(“cls”); xiugai(); break;
case 4: system(“cls”); printf_all(); break;
// case 5: system(“cls”); tongji(); break;
// case 6: system(“cls”); printf_all_bujige() break;
// case 7: system(“cls”); printf_all_youxiu() break;
case 8: Exit(); break;
}
}
int main()
{
menu();
return 0;
}
C語言 學生成績管理系統?
附錄* 綜合實例——學生成績查詢系統
這是一個用c語言編寫的小軟件——學生成績查詢系統,同學們可以將其作為一個綜合實例,對其進行仔細的閱讀和研究,體驗編程處理問題的過程,加深對編程語言的理解,提高處理問題的綜合能力。
1、程序的功能:
1)可以根據用戶輸入的輸入、輸出文件名,讀入學生成績,完成數據的初始化。
2)可以查詢指定學生的成績,可以是指定科目的成績,也可以是全部科目的成績。
3)友好退出。
2、使用說明:
1)將輸入文件放到指定的目錄下(即../student/)
圖1
2)啟動管理程序student.exe
3)在程序的使用界面,首先輸入輸入文件名和輸出文件名,完成程序的初始化,操作如下圖所示
圖2
然後,按照按照提示,輸入學生姓名和需要程序的成績(此軟件暫時只設置了五成成績,同學們可以按照需要擴展)科目代碼,也可以輸入查詢所有成績的代碼。程序成績,如下圖所示
圖3
4)輸入代碼“q”退出程序。
3、程序代碼
#include
#include
#include
FILE *f1,*f2;
char file1[20],file2[20],name[200][20],name1[15];
int n,m,data[200][10];
void init(){
int i,j;
char ch=’ ‘;
printf(“%20c歡迎使用班級成績管理系統\n\n”,ch);
printf(“請輸入輸入和輸出文件名(中間用一個空格隔開):\n”);
scanf(“%s %s”,file1,file2);// 1)該條語句的功能是什麼?
f1=fopen(file1,”r”);
f2=fopen(file2,”w”);
fscanf(f1,”%d%d”,n,m); // 2)該條語句的功能是什麼?
for(i=1;i=n;i++)
{
fscanf(f1,”%s”,name[i]); // 3)該條語句的功能是什麼?
data[i][0]=0; // 4)該條語句的功能是什麼?沒有這條語句可不可以?
for(j=1;j=m;j++)
{
fscanf(f1,”%d”,data[i][j]);
data[i][0]+=data[i][j]; // 5)該條語句的功能是什麼?
}
}
fprintf(f2,”name\tyuwen\tshuxue\tyingyu\twuli\thuaxue\tzongfen\n “);
for(i=1;i=n;i++)
{
fprintf(f2,”%s\t”,name[i]);
for(j=1;j=m;j++)
fprintf(f2,”%d\t”,data[i][j]);
fprintf(f2,”%d\n”,data[i][0]);
}
fclose(f1);// 6)問什麼可以在這關閉輸入文件?
fclose(f2);
}
void search(char na[],char num){
int i=1,j;
while((i=n)(strcmp(na,name[i])!=0))i++;
if(i=n){
switch(num){
case ‘1’:printf(“%s的語文成績為%d!\n”,na,data[i][1]);break;
case ‘2’:printf(“%s的數學成績為%d!\n”,na,data[i][2]);break;
case ‘3’:printf(“%s的英語成績為%d!\n”,na,data[i][3]);break;
case ‘4’:printf(“%s的物理成績為%d!\n”,na,data[i][4]);break;
case ‘5’:printf(“%s的化學成績為%d!\n”,na,data[i][5]);break;
case ‘a’:
printf(“%s的各科成績為:\n”,name[i]);
printf(“語文\t數學\t英語\t物理\t化學\t總成績\n”);
for(j=1;j=m;j++)
printf(“%d\t”,data[i][j]);
printf(“%d\n”,data[i][0]);
break;
default: printf(“沒有這種查詢方式,請確認後再次輸入!\n”);
}
}
else printf(“查無此人,請確認後再次查詢!\n”);
printf(“\n\n”);
}
main(){
init();//數據初始化
printf(“數據初始化結束!\n\n”);
printf(“————————————————\n\n”);
char na[20];
char num;
while(1){ // 7)該條語句的功能是什麼?
//scanf(“%s%c%c”,na,num,num); // 8)此處的輸入可不可以用這條語句?
printf(“請輸入學生的姓名和要查詢成績的科目代碼(中間用一個空格隔開):\n(1 語文 2 數學 3 英語 4 物理 5 化學 a 所有科目成績 q 退出)\n”);
scanf(“%s”,na);
if(strcmp(na,”q”)==0)break; // 9)問什麼要用這條語句strcmp(na,”q”)==0?
scanf(“%c%c”,num,num); // 10)為什麼用了兩次num?
search(na,num);
printf(“————————————————\n\n”);
printf(“\n請輸入新的查詢:\n\n”);
}
system(“pause”);
}
這是我以前的一個程序,你改改吧,應該很好改
原創文章,作者:FVGI,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/145508.html