學生成績管理系統帶保存
⑴ c語言學生成績管理系統,為什麼我的數據保存之後不能讀取呢
把你的後兩個函數用我的替換一下:
你讀取不出來的原因,你沒有在保存的文件裡面寫入一共有多少個信息,你在讀取函數那裡的讀取的studentacount的值是0,所以沒有讀。另外,既然你讀取是rb,保存也應該對應的wb啊。
void
StoreFile(struct
STUDENT
wstudent[])
{
FILE
*fp;
fp=fopen("d:\\student.txt","wb");
if(fp
==
NULL)
{
printf("沒有此文件!");
}
fwrite(&studentacount,sizeof(int),1,fp);
fwrite(wstudent,sizeof(struct
STUDENT),studentacount,fp);
fclose(fp);
printf("保存成功!\n");
};
void
OpenFile(struct
STUDENT
wstudent[])
{
FILE
*fp;
fp=fopen("d:\\student.txt","rb");
if(fp
==
NULL)
{
printf("沒有此文件!");
}
fread(&studentacount,sizeof(int),1,fp);
fread(wstudent,sizeof(struct
STUDENT),studentacount,fp);
fclose(fp);
printf("打開成功!\n");
};
⑵ 學生成績管理系統的源代碼 但是其中缺少了 排序,插入,保存文件和讀文件的函數 求大神幫忙補充!!!!
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定義臨時指針*/
temp=head->next; /*將原表的頭指針所指的下一個結點作頭指針*/
head->next=NULL; /*第一個結點為新表的頭結點*/
while(temp!=NULL) /*當原表不為空時,進行排序*/
{
t=temp; /*取原表的頭結點*/
temp=temp->next; /*原表頭結點指針後移*/
p1=head; /*設定移動指針p1,從頭指針開始*/
p2=head; /*設定移動指針p2做為p1的前驅,初值為頭指針*/
while(t->average<p1->average&&p1!=NULL) /*作成績平均分比較*/
{
p2=p1; /*待排序點值小,則新表指針後移*/
p1=p1->next;
}
if(p1==p2) /*p1==p2,說明待排序點值大,應排在首位*/
{
t->next=p1; /*待排序點的後繼為p*/
head=t; /*新頭結點為待排序點*/
}
else /*待排序點應插入在中間某個位置p2和p1之間,如p為空則是尾部*/
{
t->next=p1; /*t的後繼是p1*/
p2->next=t; /*p2的後繼是t*/
}
}
p1=head; /*已排好序的頭指針賦給p1,准備填寫名次*/
while(p1!=NULL) /*當p1不為空時,進行下列操作*/
{
i++; /*結點序號*/
p1->order=i; /*將結點序號賦值給名次*/
p1=p1->next; /*指針後移*/
}
printf("排序成功 Sorting is sucessful.\n"); /*排序成功*/
return (head);
}
/*插入記錄函數*/
STUDENT *insert(STUDENT *head,STUDENT *mynew)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一個結點*/
p0=mynew; /*p0指向要插入的結點*/
printf("\nPlease enter a mynew record.\n"); /*提示輸入記錄信息*/
printf("輸入學號Enter the num:");
scanf("%s",mynew->num);
printf("輸入名字Enter the name:");
scanf("%s",mynew->name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新記錄的總分,初值為0*/
for(i=0;i<3;i++)
{
do{
printf("成績score%d:",i+1);
scanf("%d",&mynew->score[i]);
if(mynew->score[i]>100||mynew->score[i]<0)
printf("數據錯誤Data error,please enter again.\n");
}while(mynew->score[i]>100||mynew->score[i]<0);
sum1=sum1+mynew->score[i]; /*累加各門成績*/
}
mynew->sum=sum1; /*將總分存入新記錄中*/
mynew->average=(float)sum1/3;
mynew->order=0;
if(head==NULL) /*原來的鏈表是空表*/
{head=p0;p0->next=NULL;} /*使p0指向的結點作為頭結點*/
else
{while((p0->average<p1->average)&&(p1->next!=NULL))
{p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*p1後移一個結點*/
}
if(p0->average>=p1->average)
{if(head==p1)head=p0; /*插到原來第一個結點之前*/
else p2->next=p0; /*插到p2指向的結點之後*/
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;} /*插到最後的結點之後*/
}
n=n+1; /*結點數加1*/
head=sort(head); /*調用排序的函數,將學生成績重新排序*/
printf("\n學生Student %s 已被更新have been inserted.\n",mynew->name);
printf("不要忘了保存Don't forget to save the mynewfile.\n");
return(head);
}
/*保存數據到文件函數*/
void save(STUDENT *head)
{FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10];
printf("輸出文件例如:c:\\score Enter outfile name,forexample c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL) /*為輸出打開一個二進制文件,為只寫方式*/
{
printf("打不開文件Cannot open the file\n");
return; /*若打不開則返回菜單*/
}
printf("\n保存中...Saving the file......\n");
p=head; /*移動指針從頭指針開始*/
while(p!=NULL) /*如p不為空*/
{
fwrite(p,LEN,1,fp); /*寫入一條記錄*/
p=p->next; /*指針後移*/
}
fclose(fp); /*關閉文件*/
printf("保存成功....Save the filesuccessfully!\n");
}
/* 從文件讀數據函數*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定義記錄指針變數*/
FILE *fp; /* 定義指向文件的指針*/
char infile[10];
printf("倒入文件例如:c:\\score Enter infile name,for examplec:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL) /*打開一個二進制文件,為只讀方式*/
{
printf("打不開文件Can not open the file.\n");
return(head);
}
printf("\n尋找文件...Loading the file!\n");
p1=(STUDENT *)malloc(LEN); /*開辟一個新單元*/
if(!p1)
{
printf("內存溢出!Out of memory!\n");
return(head);
}
head=p1; /*申請到空間,將其作為頭指針*/
while(!feof(fp)) /*循環讀數據直到文件尾結束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果沒讀到數據,跳出循環*/
p1->next=(STUDENT *)malloc(LEN); /*為下一個結點開辟空間*/
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*指針後移,新讀入數據鏈到當前表尾*/
}
p2->next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp);
printf("\n你成功的從文件中讀取了數據!\nYou have success to read data fromthe file!\n");
return (head);
}
⑶ 我寫了一個學生成績管理系統,C語言,學生的信息可以順利保存到文件,但登錄注冊的用戶信息不能保存為文件
tbhzx
com可以免費下載到
⑷ 菜鳥做一個學生成績管理系統,已經把學生信息保存在文本中,如何根據輸入學號,查找某一學生的信息。謝謝
我給你改了兩個錯誤現在可以運行了,不知道還有沒有其他邏輯錯誤,自己進一步修改吧。
第一個,你在排序那個程序里一個for循環不加,這個錯誤有些幼稚,不像能寫出這種程序的人該犯的。
第二個錯誤,main主函數里if判斷語句判等的時候用了賦值號,應該改成==
建議:你要學會調試,這種編譯不過調試一下子就可以找到是排序函數的哪句話出錯了。調試用F9標記,F5調試F10安步走,F11進入內層函數
#include<iostream>
#include<string>
using namespace std;
struct student //定義一個學生結構體
{
string name;
string sex;
int num;
int math;
int english;
int chinese;
int sum; //個人總分
float pingjun; //個人平均分
};
student stu[3];
int n; //全局變數
void input(student *p, int n) //輸入模塊
{
int i;
double SUM,PINGJUN;
p=&stu[0];
for(i=0;i<n; i++, p++)
{
cout<<"請依次輸入第"<<i+1<<"個學生的姓名,性別,學號,數學分數,英語分數語文分數"<<endl;
cin>>(*p).name;
cin>>(*p).sex;
cin>>(*p).num;
cin>>(*p).math;
cin>>(*p).english;
cin>>(*p).chinese;
(*p).sum=(*p).math+(*p).english+(*p).chinese; //求個人總分
(*p).pingjun=((*p).math+(*p).english+(*p).chinese)/3; //個人平均分
SUM=SUM+(*p).sum; //班級總分
PINGJUN=SUM/3; //班級平均分
} cout<<"班級總分"<<SUM<<endl;
cout<<"班級平均分"<<PINGJUN<<endl;
}
void output(student *p, int n) //輸出學生信息
{
for(int i=0;i<n;i++,p++)
{
cout<<"第"<<i+1<<"個學生的信息"<<"\n";
cout<<"姓名"<<p[i].name<<"\n";
cout<<"性別"<<p[i].sex<<"\n";
cout<<"數學分數"<<p[i].math<<"\n";
cout<<"英語分數"<<p[i].english<<"\n";
cout<<"語文分數"<<p[i].chinese<<"\n";
cout<<"個人總分"<<p[i].sum<<"\n";
cout<<"個人平均分"<<p[i].pingjun<<"\n";
}
}
void paixu(student *p, int n) //排序模塊
{
int i, j, t;
string g;
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i; j++)
{
if(p[j].sum<p[j+1].sum)
{
g=p[j].name; p[j].name=p[j+1].name; p[j+1].name=g;
g=p[j].sex; p[j].sex=p[j+1].sex; p[j+1].sex=g;
t=p[j].math; p[j].math=p[j+1].math; p[j+1].math=t;
t=p[j].english;p[j].english=p[j+1].english;p[j+1].english=t;
t=p[j].chinese; p[j].chinese=p[j+1].chinese; p[j+1].chinese=t;
t=p[j].sum; p[j].sum=p[j+1].sum; p[j+1].sum=t;
}
}
}
}
void chaozhao(student *p,int n) //查找模塊
{
int xh;
while(n==0)
{
cout<<"沒有記錄,請先輸入學生信息"<<endl;
break;
}
if(n!=0)
{
cout<<"輸入您要查找的學生學號"<<endl;
cin>>xh; //輸入學號
}
if(xh==p[n].num)
{
cout<<"姓名"<<p[n].name<<"\t";
cout<<"性別"<<p[n].sex<<"\t";
cout<<"學號"<<p[n].num<<"\t";
cout<<"數學分數"<<p[n].math<<"\t";
cout<<"英語分數"<<p[n].english<<"\t";
cout<<"語文分數"<<p[n].chinese<<"\t";
cout<<"總分"<<p[n].sum<<"\t";
}
else
cout<<"沒有找到您要查找的學生"<<endl;
}
void main() //主函數
{
student *q=&stu[0];
paixu(q,3);
int i;
cout<<"*……………………管理系統……………………*"<<endl;
cout<<"請選擇你需要的操作:"<<endl;
cout<<"(1)輸入學生信息"<<endl;
cout<<"(2)按學號查找"<<endl;
cout<<"(3)顯示所有學生信息"<<endl;
cin>>i;
if(i==1)
input(q,3);
if(i==2)
chaozhao(q,3);
if(i==3)
output(q,3);
}
⑸ c++編寫學生成績管理系統能保存錄入的數據
這個問題不是已經發過了么?!
#pragmaonce
#include"Type.h"
#include"Student.h"
classStudentMgr
{
public:
StudentMgr(){}
~StudentMgr()
{
stuVecIteriter=_simpleMemory.begin();
for(;iter!=_simpleMemory.end();++iter)
{
free(*iter);
}
}
staticStudentMgr*GetInstance()
{
if(_studentMgr!=NULL)
{
return_studentMgr;
}
_studentMgr=newStudentMgr();
assert(_studentMgr!=NULL);
return_studentMgr;
}
voidInputStudentInfo();
Student*CreateStucent(stringnum,intmath,inten,intcn,intchem);
boolAddStucent(constStudent*pStudent);
voidInitVector();
boolSort();
intGetAverage(enume_SubjectNamesubject);
voidPrintTopStucent();
voidPrintTopStucent(e_SubjectNamesubject);
voidPrientAverage();
private:
vector<Student*>_simpleMemory;
map<string,Student*>_StuMap;
vector<stuMapPair>_TopVec;
vector<stuMapPair>_MathVec;
vector<stuMapPair>_EnVec;
vector<stuMapPair>_CnVec;
vector<stuMapPair>_ChemVec;
vector<stuMapPair>_subVec[SUBNAME_LEN];
staticStudentMgr*_studentMgr;
};
#include"stdafx.h"
#include"Student.h"
#include"StudentMgr.h"
bool(*g_CmpFun[SUBNAME_LEN])(stuMapPaira,stuMapPairb)={
MathCmp,
EnCmp,
ChCmp,
ChemCmp,
};
Student*StudentMgr::CreateStucent(stringnum,intmath,inten,intcn,intchem)
{
//plz,carethememory!
Student*_student=newStudent(num,math,en,cn,chem);
if(_student==NULL)
{
cout<<"memoryerror!failtocreatenewstucent!"<<endl;
}
else
{
_simpleMemory.push_back(_student);
AddStucent(_student);
}
return_student;
}
voidStudentMgr::PrintTopStucent()
{
cout<<"Toponeinformation:"<<endl;
vector<stuMapPair>::iteratoriter=_TopVec.begin();
if(iter!=_TopVec.end())
{
Student*pStudent=iter->second;
if(pStudent!=NULL)
{
cout<<" num:"<<pStudent->GetNum();
cout<<" Math:"<<pStudent->GetMath();
cout<<" EN:"<<pStudent->GetEN();
cout<<" CN:"<<pStudent->GetCN();
cout<<" Chem:"<<pStudent->GetChem();
cout<<" Total:"<<pStudent->GetTotalScore()<<endl;
}
}
else
{
cout<<"Thereisnonstudentinformation!"<<endl;
}
}
voidStudentMgr::PrintTopStucent(e_SubjectNamesubject)
{
cout<<"Toponeinformationof"<<Subject_name[subject]<<endl;
vector<stuMapPair>::iteratoriter=_subVec[subject].begin();
if(iter!=_subVec[subject].end())
{
Student*pStudent=iter->second;
if(pStudent!=NULL)
{
cout<<" num:"<<pStudent->GetNum();
cout<<" Math:"<<pStudent->GetMath();
cout<<" EN:"<<pStudent->GetEN();
cout<<" CN:"<<pStudent->GetCN();
cout<<" Chem:"<<pStudent->GetChem();
cout<<" Total:"<<pStudent->GetTotalScore()<<endl;
}
}
else
{
cout<<"Thereisnonstudentinformation!"<<endl;
}
}
intStudentMgr::GetAverage(enume_SubjectNamesubject)
{
intsubTotal=0;
stuMapIteriter=_StuMap.begin();
for(;iter!=_StuMap.end();++iter)
{
subTotal+=iter->second->GetScore(subject);
}
returnsubTotal/_StuMap.size();
}
voidStudentMgr::PrientAverage()
{
intaverate=0;
for(inti=0;i<SUBNAME_LEN;++i)
{
averate=GetAverage((enume_SubjectName)i);
cout<<"the"<<Subject_name[i]<<"'saverateis:"<<averate<<endl;
}
}
voidStudentMgr::InputStudentInfo()
{
cout<<"Plz,!e.num,math,en,ch,chem"<<endl;
charc='0';
while(true)
{
structs_SimpDatadata={0};
if(scanf_s("%s%d%d%d%d",data.num,MAX_NUM_LEN,&data.math,&data.en,&data.cn,&data.chem)!=EOF)
{
CreateStucent(data.num,data.math,data.en,data.cn,data.chem);
}
cout<<"'c'continue"<<endl;
cin>>c;
if(c!='c')
{
break;
}
}
}
boolStudentMgr::Sort()
{
std::sort(_TopVec.begin(),_TopVec.end(),TopCmp);
for(inti=0;i<SUBNAME_LEN;++i)
{
std::sort(_subVec[i].begin(),_subVec[i].end(),g_CmpFun[i]);
}
returntrue;
}
voidStudentMgr::InitVector()
{
inti=0;
_TopVec.clear();
for(i=0;i<SUBNAME_LEN;++i)
{
_subVec[i].clear();
}
stuMapIteriter=_StuMap.begin();
for(;iter!=_StuMap.end();++iter)
{
_TopVec.push_back(*iter);
for(i=0;i<SUBNAME_LEN;++i)
{
_subVec[i].push_back(*iter);
}
}
}
boolStudentMgr::AddStucent(constStudent*pStudent)
{
stuMapPair_pair=stuMapPair(pStudent->GetNum(),const_cast<Student*>(pStudent));
_StuMap.insert(_pair);
returntrue;
}
源碼地址:http://www.iu8s.com/forum.php?mod=viewthread&tid=18&extra=page%3D1
如果需要源碼可以留下郵箱,我直接發你郵箱裡面。
⑹ c語言學生管理系統用文件保存
/**********************************************
*File Name:StuHead.h *
*Created:07/11/28 *
*Author:Wen He *
*Description:此文件的指責是程序的頭文件描述 *
**********************************************/
/*引入頭文件*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100 /*定義學生人數*/
#define MAXSUB 4 /*定義課程數目*/
int length; /*定義學生的實際人數*/
/*定義學生結構體*/
typedef struct tagStudent_t
{
char no[11]; /*學號*/
char name[20]; /*姓名*/
int score[MAXSUB];/*各科成績*/
int sum; /*總分*/
float average; /*平均分*/
}Student;
/*函數聲明*/
char menu_select();
void input(Student stuArray[]);
void output(Student stuArr[]);
void search(Student stuAray[]);
int searchByNo(Student stuArr[]);
void searchByName(Student stuArr[]);
void update(Student stuArray[]);
void delete(Student stuArray[]);
----------------------以上是頭文件
/**********************************************
*File Name:stuMain.c *
*Created:07/11/28 *
*Author:Wen He *
*Description:此程序的指責為程序的入口,主函數 *
***********************************************/
#include "stuHead.h"
void main()
{
Student stus[MAXSIZE];
while(1)
{
switch(menu_select())
{
case '1':
input(stus);
break;
case '2':
update(stus);
printf("按任意鍵繼續…");
fflush(stdin);
getchar();
break;
case '3':
search(stus);
printf("按任意鍵繼續…");
fflush(stdin);
getchar();
break;
case '4':
delete(stus);
printf("按任意鍵繼續…");
fflush(stdin);
getchar();
break;
case '5':
output(stus);
printf("按任意鍵繼續…");
fflush(stdin);
getchar();
break;
case '0':
printf("\n 謝謝使用!\n");
exit(0);
}
}
}
以上是MAIN
下面是主程序
/**********************************************
*File Name:stuFun.c *
*Created:07/11/28 *
*Author:Wen He *
*Description:此程序的指責為各函數的定義 *
***********************************************/
#include "stuHead.h"
/**********************************************
*Function Name:menu_select
*Description:菜單選擇
*Date:07/11/28
*parameter:無
*Author:Wen He
***********************************************/
char menu_select()
{
char MenuItem;
printf("\n ");
printf(" | *********學生成績管理系統********* | \n");
printf(" | ---------------------------------- | \n");
printf(" | 主菜單項 | \n");
printf(" | ---------------------------------- | \n");
printf(" | 1 --- 錄入學生信息 | \n");
printf(" | 2 --- 修改學生信息 | \n");
printf(" | 3 --- 查詢學生信息 | \n");
printf(" | 4 --- 刪除學生成績 | \n");
printf(" | 5 --- 顯示學生信息 | \n");
printf(" | 6 --- 統計學生成績 | \n");
printf(" | 0 --- 退出系統 | \n");
do
{
printf("\n 請輸入選項(0-5):");
fflush(stdin);
scanf("%c",&MenuItem);
getchar();
}while(MenuItem<'0'||MenuItem>'5');
return MenuItem;
}
/**********************************************
*Function Name:input
*Description:輸入學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void input(Student stuArray[])
{
int i,j,k;
char cContinue;
int flag=1;
fflush(stdin);
for(i=length;i<MAXSIZE-1;i++)
{
printf("請輸入第%d名學生的學號:",i+1);
scanf("%s",&stuArray[i].no);
if(i>0)
{
for(k=0;k<length;k++)
if(strcmp(stuArray[k].no,stuArray[i].no)==0)
break;
if(k<length)
{
i--;
printf("學號不能重復,請重新輸入!");
continue;
}
}
printf("請輸入姓名:");
scanf("%s",&stuArray[i].name);
for(j=0;j<MAXSUB;j++)
{
printf("請輸入第%d門成績:",j+1);
scanf("%d",&stuArray[i].score[j]);
if(stuArray[i].score[j]>100||stuArray[i].score[j]<0)
{
printf("錯誤數據,請重新輸入!");
j--;
}
}
stuArray[i].sum=0;
for(j=0;j<MAXSUB;j++)
stuArray[i].sum+=stuArray[i].score[j];
stuArray[i].average=(float)stuArray[i].sum/MAXSUB;
length++;
do
{
flag=1;
fflush(stdin);
printf("需要繼續錄入嗎?(Y/N)");
scanf("%c",&cContinue);
getchar();
switch(cContinue)
{
case 'Y':
case 'y':
flag=0;
break;
case 'N':
case 'n':
return;
}
}while(flag);
}
}
/**********************************************
*Function Name:output
*Description:輸出學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void output(Student stuArray[])
{
int i,j;
printf("| 學號 | 姓名 | 成績1 | 成績2 | 成績3 | 成績4 | 總分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
for(i=0;i<length;i++)
{
printf("|%-6s|%-14s|", stuArray[i].no,stuArray[i].name);
for(j=0;j<MAXSUB;j++)
printf("%7d|", stuArray[i].score[j]);
printf("%7d%7.2f\n",stuArray[i].sum, stuArray[i].average); /*輸出數組中當前學生的信息*/
}
}
/**********************************************
*Function Name:search
*Description:查詢學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void search(Student stuArray[])
{
char menuItem;
printf("\n\n\n"); /*輸出三個空行*/
/*---------輸出菜單界面開始-----------*/
printf(" | --------------------------------------------|\n");
printf(" | 查詢子菜單項 |\n");
printf(" | --------------------------------------------|\n");
printf(" | 1---學號查詢 |\n");
printf(" | 2---姓名查詢 |\n");
printf(" | 0---返回主菜單 |\n");
printf(" | --------------------------------------------|\n");
/*----------菜單界面輸出結束-----------*/
do
{
printf("\n 請輸入菜單項數字(0~2):");
fflush(stdin);
scanf("%c",&menuItem);
getchar();
}while(menuItem<'0'||menuItem>'2');
switch(menuItem)
{
case '1':
searchByNo(stuArray);
break;
case '2':
searchByName(stuArray);
break;
}
return;
}
/**********************************************
*Function Name:searchByNo
*Description:按學號查詢學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
int searchByNo(Student stuArray[])
{
char no[20];
int i;
printf("\n請輸入學生的學號:");
scanf("%s",no);
for(i=0;i<length;i++)
if(strcmp(stuArray[i].no,no)==0)
break;
if(i==length)
printf("您輸入的學號不存在!\n");
else
{
printf("| 學號 | 姓名 | 成績1 | 成績2 | 成績3 | 成績4 | 總分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stuArray[i].no,stuArray[i].name,
stuArray[i].score[0], stuArray[i].score[1], stuArray[i].score[2], stuArray[i].score[3],
stuArray[i].sum, stuArray[i].average); /*輸出數組中當前學生的信息*/
}
return i;
}
/**********************************************
*Function Name:searchByName
*Description:按姓名查詢學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void searchByName(Student stuArray[])
{
Student stu[10];
char searchName[20];
int i,j,k;
printf("\n請輸入要查詢學生的姓名:");
scanf("%s",searchName);
for(i=0,j=0;i<length;i++)
if(strcmp(stuArray[i].name,searchName)==0)
{
strcpy(stu[j].no,stuArray[i].no);
strcpy(stu[j].name,searchName);
for(k=0;k<4;k++)
stu[j].score[k]=stuArray[i].score[k];
stu[j].sum=stuArray[i].sum;
stu[j].average=stuArray[i].average;
j++;
}
if(j==0)
printf("您輸入的姓名不存在!\n");
else
{
printf("| 學號 | 姓名 | 成績1 | 成績2 | 成績3 | 成績4 | 總分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
for(i=0;i<j;i++)
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stu[i].no,stu[i].name,
stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3],
stu[i].sum, stu[i].average); /*輸出數組中當前學生的信息*/
}
}
/**********************************************
*Function Name:update
*Description:修改學生信息
*parameter:stuArray[MAXSIZE]
*Date:07/11/28
*Author:Wen He
***********************************************/
void update(Student stuArray[])
{
char answer;
int i,j;
i=searchByNo(stuArray);
if(i<length)
{
do
{
printf("您要修改的是以上記錄嗎?(Y/N)");
fflush(stdin);
scanf("%c",&answer);
getchar();
}while(answer!='Y'&&answer!='N'&&answer!='y'&&answer!='n');
if(answer=='Y'||answer=='y')
{
printf("請輸入姓名:");
scanf("%s",stuArray[i].name);
stuArray[i].sum=0;
for(j=0;j<MAXSUB;j++)
{
printf("請輸入第%d門課程的成績:",j+1);
scanf("%d",&stuArray[i].score[j]);
stuArray[i].sum+=stuArray[i].score[j];
}
stuArray[i].average=(float)stuArray[i].sum/MAXSUB;
printf("您修改後的信息如下:\n");
printf("| 學號 | 姓名 | 成績1 | 成績2 | 成績3 | 成績4 | 總分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stuArray[i].no,stuArray[i].name,
stuArray[i].score[0], stuArray[i].score[1], stuArray[i].score[2], stuArray[i].score[3],
stuArray[i].sum, stuArray[i].average); /*輸出數組中當前學生的信息*/
}
}
}
/**********************************************
*Function Name:delete
*Description:刪除學生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void delete(Student stuArray[])
{
char answer;
int i,j;
i=searchByNo(stuArray);
if(i<length)
{
do
{
printf("您要刪除的是以上記錄嗎?(Y/N)");
fflush(stdin);
scanf("%c",&answer);
getchar();
}while(answer!='Y'&&answer!='N'&&answer!='y'&&answer!='n');
if(answer=='Y'||answer=='y')
{
for(j=i;j<=length-1;j++)
stuArray[j]=stuArray[j+1];
printf("刪除成功!");
length--;
}
}
}
⑺ 如何用c語言製作一個學生信息管理系統,要求以文件形式保存
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//鏈表結點結構體聲明
typedef struct subjects
{
char name[20];
float score;
}sub;
typedef struct student
{
int num;
char name[20];
sub subject[3];
struct student* next;
}stu,*pstu;
#define SIZE sizeof(stu)
//函數申明
pstu LoadInfo();
void PrintMenu();
pstu AddStu(pstu );
pstu DeleStu(pstu );
pstu RwrStu(pstu );
void FindStu(pstu , char );
void Count(pstu ,char * ,float ,float );
void Rank(pstu ,char * );
void SaveQuit(pstu );
//創建菜單,進入選擇循環
while(1)
{
PrintMenu();
printf("請輸入您的選擇編號:");
scanf("%d",&n);
getchar();
switch(n)
{
case 1:
{
system("cls");
j=0;
while(4!=j)
{
printf("歡迎進入信息管理版塊! ");
printf("