導航:首頁 > 源碼編譯 > 學生檔案管理系統演算法

學生檔案管理系統演算法

發布時間:2022-09-07 15:05:38

❶ 求一C語言設計

#include <stdio.h>
#include <stdlib.h>
#include<string.h>

#define MENU_NUM 7
#define N 3

typedef struct s1
{
char no[11]; /*學號由10個字元組成*/
char name[15]; /*學生姓名*/
float score[N]; /*各門課成績*/
float sum; /*總分*/
float average; /*平均分*/
int order; /*名次*/
struct s1 *next; /*指向後繼結點的指針*/
}STUDENT; /*定義結構體類型*/

STUDENT * head=NULL;
void InputData( STUDENT * ptr );
void PrintMenu( );
int Menu_Select( );
void Init( );
void create( );
void print( ) ;
void Delete( );
void append();
void computer();

main()
{
int key;
while(1) {
key=Menu_Select();
switch(key)
{
case 0: Init();
//初試化鏈表。也就是若鏈表不為空則釋放鏈表中所有數據,將head置為空(NULL)
break;
case 1: create();
//創建鏈表,輸入數據
break;
case 2: Delete();
//刪除一個指定學號的記錄數據
break;
case 3: print();
//列印鏈表中所有數據
break;
case 4: computer();
//計算鏈表中所有人的總分和平均分
break;
case 5: append();
//追加一個數據到鏈表的尾部
break;
case 6: Init();
//釋放鏈表
exit(0);
}
};
}

void PrintMenu( )
{
int i;
char * menu[]={
"0. Init list",
"1. Enter list",
"2. Delete a record from list",
"3. Print list",
"4. Compute the score",
"5. Insert record to list",
"6. Quit"
};

printf("\n\n");
for (i=0;i<MENU_NUM;i++)
printf("%s\n",menu[i]);
printf("\nEnter your choice(0-6):");
}

int Menu_Select( )
{
int key;

PrintMenu( );
scanf("%d",&key);
return key;
}

void Init( ) //初始化單鏈表。也就是釋放鏈表中的所有數據
{
STUDENT *p,*ptr;//定義兩個臨時指針變數p,ptr
p=head;ptr=head;//將兩個臨時變數指向頭指針head ;
while(ptr!=NULL)
{
ptr=ptr->next;//ptr指向下一個結構數據
free(p);//釋放p所指向的結構數據的內存
p=ptr;//將p指向ptr所指向的數據
}
head=NULL;//將head指向NULL
}

void create( ) //創建單鏈表
{
STUDENT *pt, *pth=NULL; //定義兩個指針變數:pt指向即將申請新的數據內存,pth指向當前數據
while(1)
{
pt=(STUDENT *)malloc(sizeof(STUDENT));//讓pt指向新申請的內存空間
InputData(pt);//輸入數據,存放到pt所指向的結構數據。注意讓pt的next指向NULL
if (strcmp(pt->no,"@")==0)
{
free(pt);//釋放pt所指向的內存空間
break;//退出循環
}
else if (head==NULL)
{
pth=pt;
head=pt;//將頭指針head和pth指向pt
}
else
{

pth->next=pt; //將pth的next指向pt;
pth=pt; //將pth指向pt;
}
};
}

void print( ) //列印單鏈表中所有數據
{ int i=0;
STUDENT *p;//第一個指針p
p=head;//將p指向head

printf("\n");
printf("******************************STUDENT******************************\n");
printf("|rec|no | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|---|----------|----------------|----|----|----|------|-----|-----|\n");

//列印表頭
while (p!=NULL)
{
printf("|%3d|%10s|%-16s|%4.1f|%4.1f|%4.1f|%6.2f|%5.1f|%5d|\n",
++i,p->no,p->name,p->score[0],p->score[1],p->score[2],
p->sum,p->average,p->order); //列印p所指向的結構中的所有數據。注意列印數據間的分隔線
p=p->next;//將p指向p的下一個結構數據
}
printf("********************************END********************************\n");//列印表尾
}

void Delete( ) //刪除一個記錄
{
STUDENT *p,*pth;//定義兩個指針p,pth
char no[11];//定義一個整數no(用來存儲輸入的學號)
printf("intput delete no\n");
scanf("%s",no);//用輸入語句輸入一個學號存儲到no中
p=head;pth=head;//將p和pth都指向頭指針
if (strcmp(p->no,no)==0) //也就是若頭指針指向的數據需要刪除
{
head=head->next;//將head指針指向head的下一個數據;
free(p);//釋放p所指向的數據
}
else
{
p=p->next;//將p指向p的下一個數據
while ( p!=NULL)
{
if (strcmp(p->no,no)==0) //找到了要刪除的數據
{
pth->next=p->next;//將pth的next指向p的next
free(p);//釋放p
break;//退出循環
}
else
{
pth=pth->next;//將pth指向pth的next 或 將pth指向p
p=p->next;//將p指向p的next
}
}
}
}

void append()
{
STUDENT *p,*pth;//定義兩個指針變數p,pth

pth=head;//將pth指向head
while ( pth->next!=NULL)
{
pth=pth->next;//ptr指向ptr的next
}

p=(STUDENT *)malloc(sizeof(STUDENT));//將p指向新申請的內存空間
InputData(p);p->next=NULL;//數據數據存儲到p所指向的內存空間,注意將p的next置為NULL
pth->next=p;//將ptr的next指向p
}
void InputData( STUDENT *ptr )
{ int i;
printf("enter no:");
scanf("%s",ptr->no);
if (strcmp(ptr->no,"@")==0 ) return;

printf("enter name:");
scanf("%s",ptr->name);

for(i=0;i<3;i++)
{
printf("shuru chengji\n");
scanf("%f",&ptr->score[i]);
}

ptr->sum=0;
ptr->average=0;
ptr->order=0;
ptr->next=NULL;
}
void computer()
{
STUDENT *p;
p=head;
for(;p;p=p->next)
{
p->sum=p->score[0]+p->score[1]+p->score[2];
p->average=(p->score[0]+p->score[1]+p->score[2])/3;
}
}

❷ 高手們,C語言編學生檔案管理,幫忙下

# include<iostream.h>
# include<string.h>
# include<stdio.h>
# include<stdlib.h>
# include<fstream.h>
//*****定義一個學生原子的的數據結構*****//
struct stuatom
{
char *name;
int id;
char sex;
float math, eng, comp, totll, aver;
void show();
void setup();
};

//*********定義一系列對學生的操作**********//
class student
{
private:
stuatom ob[100];
int stulen;
public:
student();
void input();
void order();
void save();
void Query();
void read();
void add();
void del();

};

//********對學生數據的初始化(類的構造函數)**********//
student::student()
{
//用for循環對全部數組中的數據初始化
for(int i=0;i<100;i++)
{
ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0;
ob[i].id =0;
ob[i].sex =' ';
ob[i].name =NULL;
}
this->stulen =0;
}

//********輸入學生的數據,並判斷是否在規定數據域內*******//
void stuatom::setup()
{
char n[20]; char s;
int b;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
do {
cout<<" 學號: ";
cin>>b;
if(b>1020||b<1001)
cout<<"Bad data input!!"<<endl<<endl;
}while (b<1001||b>1020);

id=b;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
do{
name=new char[strlen(n)+1];
cout<<" 姓名: ";
cin>>n;
if( strlen(n)>6 || strlen(n)<4 )
cout<<"Bad data input!!"<<endl<<endl;
}while ( strlen(n)>6 && strlen(n)<4 );

strcpy(name,n);
cout<<" 性別(m/f):" ;
cin>>s;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (s!='m' && s!='f')
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<" 性別(m/f):";
cin>>s;
}

sex=s;
float m, e, co;
cout<<" 數學: ";
cin>>m;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (m<0 || m>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<" 數學: ";
cin>>m;
}

math=m;
cout<<" 英語: ";
cin>>e;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (e<0 || e>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<" 英語: ";
cin>>e;
}

eng=e;
cout<<" 計算機: ";
cin>>co;

//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (co<0 || co>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<" 計算機: ";
cin>>co;
}

comp=co;
totll=math+eng+comp;
aver=(math+eng+comp)/3;
}

//*******按照規定格式把該學生的數據顯示在屏幕上******//
void stuatom::show()
{
cout.setf(ios::left);
cout.width(6);
cout<<""<<id<<" ";
cout.width(8);
cout<<name;
cout.width(10);
cout<<sex;
cout.width(9);
cout<<math;
cout.width(9);
cout<<eng;
cout.width(11);
cout<<comp;
cout.width(10);
cout<<totll<<aver<<endl;
}

//**************輸入學生的數據***********************//
void student::input()
{
int n;
cout<<endl<<"輸入將要錄入的學生數目: ";
cin>>n;
int j;

//通過循環輸入要求輸入學生個數的學生的數據。
for(j=0; j<n; j++)
{
cout<<" 輸入學生信息 "<<j<<endl;
ob[j].setup();
}

this->stulen=n; //學生個數賦值

//學生數據顯示格式
system("cls");
cout<<endl<<"----------------------------- 學生信息表 ------------------------------------"<<endl;
cout<<endl<<" 學號 姓名 性別 數學 英語 計算機 總分 平均分"<<endl;

//通過循環輸出所有學生數據。
for(j=0; j<n; j++)
{
ob[j].show();
}

cout<<endl;
cout<<" 是否保存? (Y/N): ";
char Y;
cin>>Y;
system("cls");
}

//**************按照一定格式顯示所要查詢學生的信息。**************//
void student::Query()
{
int x , i;
cout<<endl<<" 輸入要查詢學生的學號: ";
cin>>x;
cout<<endl<<" 學號 姓名 性別 數學 英語 計算機 總分 平均分"<<endl;
for(i=0;i<=this->stulen ;i++)
{ if (x==ob[i].id)
{
cout.setf(ios::left);
cout.width(6);
cout<<""<<ob[i].id<<" ";
cout.width(8);
cout<<ob[i].name;
cout.width(10);
cout<<ob[i].sex;
cout.width(9);
cout<<ob[i].math;
cout.width(9);
cout<<ob[i].eng;
cout.width(11);
cout<<ob[i].comp;
cout.width(10);
cout<<ob[i].totll<<ob[i].aver<<endl;
}
}
getchar();
}
//*******************保存學生數據**************************//
void student::save()
{
int i;
ofstream outfile;
outfile.open("list.txt",ios::trunc);
if(!outfile)
{
cout<<"Cannot open output file!\n,";
}

//通過循環把所有的學生數據保存在list.txt里邊。
for(i=0; i<this->stulen; i++)
{
outfile<<ob[i].id<<" "<<ob[i].name<<" "<<ob[i].sex<<" "<<
ob[i].math<<" "<<ob[i].eng<<" "<<ob[i].comp<<" "<<ob[i].totll<<" "<<ob[i].aver<<endl;
}
outfile.close();
}

//*************顯示所有學生數據*********************//
void student::read()
{
int i;
system("cls");
cout<<endl<<"----------------------------- 學生信息表 ------------------------------------"<<endl;
cout<<endl<<" 學號 姓名 性別 數學 英語 計算機 總分 平均分"<<endl;

for(i=0; i<this->stulen; i++)
{
ob[i].show();
}
getchar();
}
//*******************一個學生的數據****************//
void student::add()
{
int i, d=this->stulen ;
cout<<"輸入要添加學生的信息:"<<endl;
ob[d].setup();
cout<<endl<<"----------------------------- 學生信息表 ------------------------------------"<<endl;
cout<<endl<<" 學號 姓名 性別 數學 英語 計算機 總分 平均分"<<endl;

for(i=0; i<=d; i++)
{
ob[i].show();
}

ofstream fout("list.txt",ios::app);

if(!fout)
{
cout<<"Cannot open output file!\n,";
}

//把添加的學生數據添加到list.txt里邊去。
fout<<ob[d].id<<" "<<ob[d].name<<" "<<ob[d].sex<<" "<<
ob[d].math<<" "<<ob[d].eng<<" "<<ob[d].comp<<" "<<ob[d].totll<<" "<<ob[d].aver<<endl;

fout.close();
getchar();
}

//*********************刪除指定名字學生的數據*******************//
void student::del()
{
int i,p; char x[8];
cout<<" 輸入要刪除學生名字:"<<endl;
cin>>x;

//通過for循環查找要刪除學生的姓名
for(i=0; i<stulen; i++)
{
if(strcmp(ob[i].name,x)==0)
{
p=i;
cout<<endl<<"學號 姓名 性別 數學 英語 計算機 總成績 平均成績"<<endl;
cout<<ob[i].id<<" "<<ob[i].name<<" "<<ob[i].sex<<" "<<ob[i].math<<" "<<ob[i].eng<<" "<<ob[i].comp<<" "<<ob[i].totll<<" "<<ob[i].aver<<endl;
break;
}
else
continue;
}

cout<<endl<<"----------------------------- 學生信息表 ------------------------------------"<<endl;
cout<<endl<<" 學號 姓名 性別 數學 英語 計算機 總分 平均分"<<endl;

//刪除了之後,應該把後面的數據往前移,把要刪除的數據覆蓋,並且學生長度減1
stulen--;
for(i;i<stulen;i++)
{
ob[i]=ob[i+1];
}
this->read ();

cout<<" 刪除成功!"<<endl;
getchar();
}
//***********把學生成績排序******************//
void student::order()
{
int k,j;
float t; char n[20];

//排序演算法
for(j = 0; j<=(2-1); j++)
{
for(k=1; k<=(2-j); k++)
{
if(ob[k].totll < ob[k + 1].totll)
{
t = ob[k].totll;
ob[k].totll = ob[k+1].totll;
ob[k+1].totll = t;
strcpy(n, ob[k].name);
strcpy(ob[k].name, ob[k+1].name);
strcpy(ob[k+1].name, n);
}

cout<<" 成績排名:"<<endl;
cout<<" 姓名 總成績 名次"<<endl;
for(k=0; k<=stulen; k++)
{
cout<<" ";
cout.setf(ios::left);
cout.width(9);
cout<<ob[k].name;
cout.width(9);
cout<<ob[k].totll<<k<<endl;
}
getchar();
}
}
}

//********************選擇菜單。*****************//
void menu()
{
cout<<"\n\n";
cout<<"------------------ 學生成績系統 -----------------"<<endl<<endl;
cout<<"\t\t1.錄入與保存學生信息.\n";
cout<<"\t\t2.讀取學生信息.\n";
cout<<"\t\t3.刪除學生信息.\n";
cout<<"\t\t4.追加學生信息.\n";
cout<<"\t\t5.查詢學生信息.\n";
cout<<"\t\t6.顯示成績名次.\n";
cout<<"\t\t7.退出系統......\n\n\n";
cout<<"\t\t請選擇功能項: ";
}

//---------------------------------------------------------------------------------------
void main()
{
student a;
while(1)
{

int SEL;
system("cls");
menu();
cin>>SEL;
switch(SEL)
{
case 1:
system("cls"); a.input();a.save();break;
case 2:
system("cls"); a.read(); break;
case 3:
system("cls"); a.del(); break;
case 4:
system("cls"); a.add();break;
case 5:
system("cls"); a.Query();break;
case 6:
system("cls"); a.order();break;
case 7:
cout<<endl<<" 按任意鍵退出.... "<<endl;
getchar();
exit(0);
default:
cout<<"Bad input!!\n";
break;
}
}
}

❸ 選題一:學生檔案管理 1.題目描述 編寫一個程序來管理學生檔案,系統能實現以下功能: 輸入信息:學

這里有一個問題
要在指定的位置插入學生信息
不知道這個位置是如何定義的?

這樣的程序一般都是使用鏈表來完成的
而如果要進行排序的話我個人更喜歡使用雙向鏈表來完成
不過題目要求使用單鏈表(沒有規定死?那還是用雙鏈表吧)

程序的代碼量說大其實並不大
不過對於普通的那種作業來說代碼量就稍顯多了點
如果不想自己寫這個代碼的話
支付寶60元我幫你寫好了

❹ 求C語言學生檔案管理界面的源代碼

簡短的代碼 原創 花了2小時搞的#include "stdafx.h"
#include "stdio.h"
#include "string.h"int main(int argc, char* argv[])
{
struct days
{
int year;
int mon;
int day;
};
struct max
{
int num;
char name[20];
float cpp;
float data;
float english;
struct days mon;
}stu[100]={0,"",0,0,0,0,0,0};
int a,b,c,yanz=0;
char name[50];
FILE *fp;
printf("****************************ZX學生管理系統1.0測試版*****************************\n");
loop:printf("1.通過學號查找信息\n2.通過姓名查找信息\n3.添加學生信息\n4.刪除學生信息\n5.文件操作\n請輸入操作代碼(1~6):");
scanf("%d",&a);
switch(a)
{
case 1:
printf("請輸入學生學號:");
scanf("%d",&c);
for(b=0;b<100;b++)
if(stu[b].num==c)
printf("學號:%d\n姓名:%s\nC++:%f分\n數據結構:%f分\n英語:%f分\n平均分%f\n出生日期:%d年%d月%d日\n\n",stu[b].num,stu[b].name,stu[b].cpp,stu[b].data,stu[b].english,(stu[b].cpp+stu[b].data+stu[b].english)/3,stu[b].mon.year,stu[b].mon.mon,stu[b].mon.day);
break;
case 2:
printf("請輸入學生姓名:");
scanf("%s",&name);
for(b=0;b<100;b++)
if((strcmp(stu[b].name,name))==0 && stu[b].num!=0)
printf("學號:%d\n姓名:%s\nC++:%f分\n數據結構:%f分\n英語:%f分\n平均分%f\n出生日期:%d年%d月%d日\n\n",stu[b].num,stu[b].name,stu[b].cpp,stu[b].data,stu[b].english,(stu[b].cpp+stu[b].data+stu[b].english)/3,stu[b].mon.year,stu[b].mon.mon,stu[b].mon.day);
break;
case 3:
for(b=0;b<100;b++)
{
if(stu[b].num==0)
{printf("請輸入新學生的學號:");<br> scanf("%d",&stu[b].num);<br> printf("請輸入新學生的姓名:");<br> scanf("%s",&stu[b].name);<br> printf("請輸入新學生的C++分:");<br> scanf("%f",&stu[b].cpp);<br> printf("請輸入新學生的數據結構分:");<br> scanf("%f",&stu[b].data);<br> printf("請輸入新學生的英語分數:");<br> scanf("%f",&stu[b].english);<br> printf("請輸入新學生的出生日期(****,**,**):");<br> scanf("%d,%d,%d",&stu[b].mon.year,&stu[b].mon.mon,&stu[b].mon.day);<br> break;}
}
if(b>=99) printf("空間已滿!\n");
break;
case 4:
printf("請輸入要刪除的那個學生學號:");
scanf("%d",&c);
for(b=0;b<100;b++)
if(stu[b].num==c)
{
stu[b].num=NULL;
printf("刪除成功!\n");
yanz=1;
}
if(yanz==0) printf("找不到學號為%d學生的信息!",c);
break;
case 5:
printf("1.保存信息文件\n2.新建文件\n3.讀取文件\n請輸入操作代碼:");
scanf("%d",&c);
if(c==1)
{
printf("請輸入輸入文件路徑:");
scanf("%s",&name);
if((fp=fopen(name,"ab"))!=0)
{
for(b=0;b<100;b++)
if(stu[b].num!=0)fwrite(&stu[b],sizeof(struct max),1,fp);
fclose(fp);
}
else printf("保存文件失敗,可能文件被保護或磁碟寫滿!\n");
}
else if(c==2)
{
printf("請輸入輸入文件名:");
scanf("%s",&name);
fp=fopen(name,"wb");
fclose(fp);
}
else if(c==3)
{
printf("請輸入輸入文件路徑:");
scanf("%s",&name);
if((fp=fopen(name,"rb"))!=0)
{
for(b=0;b<100;b++)
fread(&stu[b],sizeof(struct max),1,fp);
fclose(fp);
}
else printf("讀取文件失敗,可能文件不存在或被保護!\n");
}
else printf("輸入錯誤!\n");
}
goto loop;
return 0;
}

❺ 2、學生檔案管理系統(至少包括:學號,姓名,身份證號碼,家庭地址)急求 謝謝

唉,曾經我也這樣,csdn上有許多,可以下載的,不是學生管理系統的也可以改一下。

❻ 用C語言設計學生檔案管理

/*用C語言設計學生檔案管理

1. 題目描述
編寫一個程序來管理學生檔案,系統能實現以下功能:
輸入信息:學生信息的輸入;
修改信息:對學生信息進行添加、刪除與修改;
查詢:能夠根據學號或姓名查詢某個學生的信息;
輸出:輸出所有學生信息或查詢學生信息的結果。
2. 設計提示
1)先確定學生檔案管理的數據結構。如每個學生信息:學號、姓名、性別、年齡、地址 ……等,每個數據項各用什麼數據類型;
2)劃分實現學生檔案管理的功能模塊:如主菜單、輸入數據、修改、查詢、輸出等功能,並確定各功能模塊的實現演算法。
3)畫出各模塊的流程圖或S-R圖;
4)選擇C語言的技術:普通數組、結構體數組、函數、指針、單鏈表或文件等。
5)編寫程序代碼。*/

#include<stdio.h>
#include<stdlib.h>
#include<string>

typedef struct student{
char ID[10];
char name[10];
char sex[3];
int age;
char addr[30];
struct student *next;

}stu;

void Input(stu *&head)
{
stu *temp,*current;

temp=(stu *)malloc(sizeof(stu));
printf("輸入學生信息:\n");
printf("學號\t姓名\t性別\t年齡\t地址\t\n");
fflush(stdin);
scanf("%s%s%s%d%s",temp->ID,temp->name,temp->sex,&temp->age,temp->addr);

temp->next=NULL;
if(head==NULL)
{head=(stu *)malloc(sizeof(stu));head->next=temp;}
else
{
current=head->next;
while(current->next)
current=current->next;

current->next=temp;}
printf("添加成功\n");
system("pause");
}
void FindByID(stu *&head)
{

if(head==NULL)
{printf("數據為空\n");
system("pause");return ;}
else
{stu *current =head->next;
bool flag=0;
char a[10];
printf("輸入要查詢的學號:\n");
fflush(stdin);
scanf("%s",a);
do
{
if(strcmp(current->ID,a)==0)
{flag=1;break;}
current=current->next;

}while(current!=NULL);

if(flag)
{
printf("學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr);
system("pause");
}
else
{
printf("沒有找到\n");
system("pause");
}
}
}
void FindByName(stu *&head)
{

if(head==NULL)
{printf("數據為空\n");
system("pause");return ;}
else
{
stu *current =head->next;
bool flag=0;
char a[10];
printf("輸入要查詢的姓名:\n");
fflush(stdin);
scanf("%s",a);
do
{
if(strcmp(current->name,a)==0)
{flag=1;break;}
current=current->next;

}while(current!=NULL);

if(flag)
{
printf("學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr);
system("pause");
}
else
{
printf("沒有找到\n");
system("pause");
}
}
}
void Delete(stu *&head)
{

if(head==NULL)
{printf("數據為空\n");
system("pause");return ;}
else
{ stu *current =head->next;
stu *prev=NULL;
char a[10];
printf("輸入要刪除的學號:\n");
fflush(stdin);
scanf("%s",a);
while(current!=NULL)
{
if(strcmp(current->ID,a)==0)break;
prev=current;
current=current->next;

}
if(prev==NULL)
{head->next=current->next;free(current);}
else
{prev->next=current->next;
free(current);}
printf("刪除成功\n");
system("pause");
}
}
void Show(stu *&head)
{
stu *current =head->next;

if(current==NULL)
{printf("數據為空\n");
system("pause");return ;}
printf("學號\t姓名\t性別\t年齡\t地址\t\n");
while(current!=NULL)
{
printf("%s\t%s\t%s\t%d\t%s\n",current->ID,current->name,current->sex,current->age,current->addr);
current=current->next;
}
system("pause");
}
void Modify(stu *&head)
{

if(head==NULL)
{printf("數據為空\n");
system("pause");return ;}
bool flag=0;
char a[10];
printf("輸入要查詢的學號:\n");
fflush(stdin);
scanf("%s",a);
stu *current=head->next;
do
{
if(strcmp(current->ID,a)==0)
{flag=1;break;}
current=current->next;

}while(current!=NULL);

if(flag)
{
printf("學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n",current->ID,current->name,current->sex,current->age,current->addr);
printf("請重新輸入該學生信息:\n");
printf("學號\t姓名\t性別\t年齡\t地址\t\n");
scanf("%s%s%s%d%s",current->ID,current->name,current->sex,¤t->age,current->addr);
printf("修改成功\n");
printf("pause");

}
else
{
printf("沒有找到\n");
system("pause");
}

}

void Print()
{
system("cls");
printf(" 請選擇功能(按0退出)\n");
printf(" 1------添加學生\n");
printf(" 2------通過學號查詢學生\n");
printf(" 3------通過姓名查詢學生\n");
printf(" 4------刪除學生\n");
printf(" 5------修改學生\n");
printf(" 6------顯示所有學生\n");

}
int main()
{
char ch;
stu *head=NULL;

do
{
Print();

fflush(stdin);
ch=getchar();
//system("cls");
switch(ch)
{
case '1':Input(head);break;
case '2':FindByID(head);break;
case '3':FindByName(head);break;
case '4':Delete(head);break;
case '5':Modify(head);break;
case '6':Show(head);break;

}
}while(ch!='0');

}

❼ C語言程序設計--班級檔案管理系統

給,已經編譯運行確認了:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define N 10
int M=0;
struct student
{
char num[13];
char name[20];
char sex;
char address[30];
int age;
};

typedef struct LB
{
struct student XINXI;
struct LB *next;
}LB_1,*LB_2;

void CAIDANG()
{
printf(" \t \t \t (歡迎使用本班級檔案管理系統)\t\t\t\t\n");
printf("★*★*★*★*★*★*★*★*★*★ 歡迎進入我們的系統 ★*★*★*★*★*★*★*★*★*★\n\n");

printf("1.錄入學生資料\t\t\t\t\t4.查詢學生信息\n\n");
printf("2.修改學生信息\t\t\t\t\t5.刪除學生信息\n\n");
printf("3.保存學生信息\t\t\t\t\t0.退出檔案系統\n\n");
printf(" \n");
printf("★*★*★*★*★*★*★*★*★*★ 歡迎進入本系統 ★*★*★*★*★*★*★*★*★*★\n");
}
/*文本顏色*/
void color()
{
textbackground(8);
textcolor(9);
clrscr();
}
void Wrong()
{
printf("\n對不起您的輸入錯誤!\n");
}

void SORRY()
{
printf("\n對不起該同學現沒有任何信息!\n");
}

void printe(LB_1 *p)/* 本函數用於輸出英文 */
{
printf(" %-2s %s\t %s\t%s\t %d\t \n",p->XINXI.num,p->XINXI.name,p->XINXI.sex,p->XINXI.address,p->XINXI.age);
}
/* 該函數用於定位鏈表中符合要求的接點,並返回該指針 */
LB_1 *Locate(LB_2 l,char findmess[],char nameornum[])
{
LB_1 *r;
if(strcmp(nameornum,"num")==0) /* 按學號查詢 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->XINXI.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查詢 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->XINXI.name,findmess)==0)
return r;
r=r->next;
}
} return 0;
}
/*以下是增加學生信息的函數*/
void TIANJIA(LB_2 l)
{
LB_1 *p,*r,*s;
char num[13];
r=l; s=l->next;
while(r->next!=NULL) /*些處循環一直到最後*/
r=r->next;
while(1)
{
printf(" 請輸入添加的學生學號(輸入'0'返回上一級菜單:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->XINXI.num,num)==0)
{
printf("(必看提示):學號為'%s'的學生已有信息,若要修改請你輸入'2 修改'!\n",num);
printe(s);
printf("\n");
return;
}
s=s->next;
} p=(LB_1 *)malloc(sizeof(LB_1));
strcpy(p->XINXI.num,num);
printf(" 請你輸入學號:");
scanf("%s",p->XINXI.num);
getchar();
printf(" 請你輸入姓名:");
scanf("%s",p->XINXI.name);
getchar();
printf(" 請你輸入性別:");
scanf("%s",p->XINXI.sex);
getchar();
printf(" 請你輸入地址:");
scanf("%s",p->XINXI.address);
getchar();

printf(" 請你輸入年齡:");
scanf("%d",&p->XINXI.age);
getchar();

/* 下面是把指針變數轉到鏈表的下一個結點中以便循環的時候使用 */
p->next=NULL;
r->next=p;
r=p; M=1;
}
}
/*以下是刪除學生信息的函數*/
void SHANCHU(LB_2 l)
{
int sel;
LB_1 *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n******(必看提示):對不起,現文件中沒有信息:所以您不能查詢!\n");
return;
}
printf("\n <必看提示> <以學號刪除請輸入1\n> <以姓名刪除請輸入2\n> PLEASE:");
scanf("%d",&sel);
if(sel==1)
{
printf("請輸入要刪除的學生的學號PLEASE:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n*******(必看提示):該學生的信息已完全刪除成功!\n");
M=1;
}
else
SORRY();
}
else if(sel==2)
{
printf("請輸入要刪除的學生的姓名PLEASE:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{ r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n******(必看提示):該學生信息已成功刪除!\n");
M=1;
}
else
SORRY();
}
else
Wrong();
}

/*以下是查詢學生信息*/
void CHAXIONG(LB_2 l)
{ int sel;
char findmess[20];
LB_1 *p;
if(!l->next)
{ printf("\n******(必看提示):對不起,現文件中沒有信息:所以您不能查詢!\n");
return;
}
printf("\n以學號查詢請輸入1:\n以姓名查詢請輸入2:\n以性別查詢請輸入3:\n以性別查詢請輸入4:\n PLEASE:");
scanf("%d",&sel);
if(sel==1)/*輸入學號查詢*/
{
printf("請你輸入要查找的學號:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ printf("\t\t\t\t查找結果\n");
printf(" 學號:%s\n姓名:%s\n性別:%s\n地址:%s\n年齡:%d\n",p->XINXI.num,p->XINXI.name,p->XINXI.sex,p->XINXI.address,p->XINXI.age);
}
else
SORRY();
}
if(sel==2) /* 輸入姓名查詢 */
{
printf("請你輸入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{ printf("\t\t\t\t查找結果\n");
printf(" 學號:%s\n姓名:%s\n性別:%s\n地址:%s\n年齡:%d\n",p->XINXI.num,p->XINXI.name,p->XINXI.sex,p->XINXI.address,p->XINXI.age);
}
else
SORRY();
}

else
Wrong();
}
/*以下是修改學生信息的函數*/
void XIUGEI(LB_2 l)
{
LB_1 *p;
long int i,j;
char findmess[20];
if(!l->next)
{ printf("\n(必看提示):對不起,現文件中沒有信息:所以您不能查詢!\n");
return;
}
for(i=1;i<=2;i++)
{
printf("\n\n\n\n\n");
printf("請輸入密碼:");
scanf("%s",&j);
if(j==2007)break;
else
{if(j!=2007)
return(CAIDANG());
}
}
printf("請你輸入要修改的學生學號:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ printf("請你輸入新學號(原來是%s):",p->XINXI.num);
scanf("%s",p->XINXI.num);
printf("請你輸入新姓名(原來是%s):",p->XINXI.name);
scanf("%s",p->XINXI.name);
printf("請你輸入新性別(原來是%s):",p->XINXI.sex);
scanf("%s",p->XINXI.sex);
printf("請你輸入新地址(原來是%s):",p->XINXI.address);
scanf("%s",p->XINXI.address);
printf("請你輸入新年齡(原來是%d):",p->XINXI.age);
scanf("%s",p->XINXI.age);
getchar();
M=1;
}
else
SORRY();
}

/*保存在文件中*/
void BAOCONG(LB_2 l)
{
FILE* fp;
LB_1 *p;
int flag=1,count=0;
fp=fopen("c:\\lyg","wr");
if(fp==NULL)
{
printf("\n=====>提示:重新打開文件時發生錯誤!\n");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(LB_1),1,fp)==1)
{ p=p->next;
count++;
}
else
{ flag=0;
break;
}
}
if(flag)
{ printf("\n 提示;正在保存文件 共保存了%d條信息\n",count);M=0;
}
fclose(fp);
}
/*以下是主函數*/
void main()
{
LB_2 l;/* 連表 */
FILE *fp; /* 文件指針 */
int sel;long i,j,d;
char ch;
char jian;
int count=0;
LB_1 *p,*r;

color();
clrscr();
l=(LB_1*)malloc(sizeof(LB_1));
l->next=NULL;
r=l;
fp=fopen("C:\\lyg","rb");
if(fp==NULL)
{
printf("\t\t\t\t\n\n");
printf("\n");
printf(" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"
" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"
" Welcome to come to our system!!! \n"
" You can only inquire your own messages! If you want to see about other \n"
" students' messages,you need first to send inquirment to them,asking for \n"
" agreement,then you can visit his/her messages! \n"
" Have a good time! now you can come in!!! \n"
" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"
" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"
" 注意:系統啟動碼為 : ILOVEMYSCHOOLVERYMUCH !!! \n"
" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n"
" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\n");
printf("歡迎使用,本系統中現沒有任何記錄,您要先創建文件請按以下操做進行PLEASE:\n");
printf("\n 提示:文件還不存在,是否創建?(y/n)請做選擇--\n");
printf("\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
{fp=fopen("C:\\lyg","wb");
clrscr();
}
{for(i=1;i<=2;i++)
{
printf("\n\n\n\n\n");
printf("請輸入密碼:");
scanf("%ld",&j);
if(j==2007)break;
else
{if(j!=2007)return;
}
}
}

exit(0);clrscr();
}
while(!feof(fp))
{
p=(LB_1*)malloc(sizeof(LB_1));
if(fread(p,sizeof(LB_1),1,fp)) /* 將文件的內容放入鏈表中 */
{
p->next=NULL;
r->next=p;
r=p; /*把該結點放入鏈表中*/
count++;
}
}
fclose(fp); /* 關閉文件 */
while(1)
{
CAIDANG();
printf("請你選擇操作:");
scanf("%d",&sel);
clrscr();
printf("\n\n\n");
if(sel==0)
{
if(M==1)
{ getchar();
printf("\n(必看提示):鏈表中的信息已經改動,如果確認把改動保存在文件中請做選擇(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
BAOCONG(l);
}
break;clrscr();
}
switch(sel)
{
case 1: TIANJIA(l);break;
case 4: CHAXIONG(l);break;
case 3: BAOCONG(l);break;
case 2: XIUGEI(l);break;
case 5: SHANCHU(l);break;
default: getchar();break;
}
} end:
getchar();
}

❽ 求c++學生檔案管理系統 急!!

/*
這是本人剛學習C++不久時寫的一個學生信息管理系統,基本功能沒問題,至於演算法,可能有些不是很好的地方。
*/

/*下面分幾個文件,你把文件分別保存,最後打開「學生信息管理系統.cpp」直接編譯、連接。此程序在VC6.0環境下測試通過。
*/
//文件「學生信息管理系統.cpp」
#include<iostream>
#include<fstream>
#include"common.h"
#include"信息錄入.cpp"
#include"信息查詢.cpp"
#include"信息排序.cpp"
#include"信息修改.cpp"
#include"信息刪除.cpp"
using namespace std;

int main()
{
int a;
h1: cout<<" —*—*—學生信息管理系統—*—*—"<<endl<<endl;
cout<<"1----學生基本信息錄入 2----學生信息查詢"<<endl;
cout<<"3----學生信息排序 4----學生信息修改"<<endl;
cout<<"5----學生信息刪除 0----退出"<<endl;
ifstream infile("record_n.txt",ios::in);
infile>>record_n; //讀取record_n,獲知文件student.dat中保存有幾個學生的數據
infile.close();
h2: cout<<"已經記錄有"<<record_n<<"個學生的數據,請選擇:";
cin>>a;
switch(a)
{
case 0:return 0;break;
case 1:info_input();break;
case 2:info_inquire();break;
case 3:info_sort();break;
case 4:info_update();break;
case 5:info_delete();break;
default:cout<<"Error!"<<endl<<endl;goto h2;
}
cout<<endl;
goto h1;
return 0;
}

//文件「信息修改.cpp」
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;

/*————————————信息修改函數——————————————*/
void info_update()
{
int i,j,answer,num;
student stud1[n],stud2[n];
cout<<"請輸入要修改的學生學號(返回請輸入0):";
cin>>num;
if(num==0)goto h0;
else
{
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
if(record_n==0)cout<<"Error!\n沒有記錄"<<endl;
else
{
for(i=0;i<record_n;i++) //讀取所有數據到一個數組
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
}
/*進行對比,找到相應學號*/
infile.close();
for(i=0;i<record_n;i++)
{
if(num==stud1[i].num) //判斷,如果符合查詢條件則輸出到屏幕
{
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(16)<<stud1[i].phone<<" 來自省份:"<<setw(16)<<stud1[i].address<<endl<<endl;
j=i; //記錄要修改學號的序號
}
}
for(i=0;i<record_n;i++) //此句和下一句if語句是判斷有無該學號,無則提示
{
if(num==stud1[i].num)break;
}
if(i>=record_n)
{
cout<<"Error!\n未找到該學號,";
goto h0;
}

for(i=0;i<j;i++)
stud2[i]=stud1[i];
for(i=j+1;i<record_n;i++)
stud2[i]=stud1[i];
cout<<"請按照姓名、性別、出生年、月、電話號碼、省份的順序輸入學生新信息(若要修改學號請刪除該記錄後重新錄入新信息):"<<endl;
/*將對應學號的信息和其他學號信息記錄到stud2[],清空原文件後寫入文件*/
stud2[j].num=stud1[j].num;
cin>>stud2[j].name>>stud2[j].sex>>stud2[j].birthday.year>>stud2[j].birthday.month>>stud2[j].phone>>stud2[j].address;
ha: cout<<"是否確定修改該記錄?確定輸入1,返回輸入0"<<endl;
cin>>answer;
if(answer==0)goto h0;
if(answer!=0&&answer!=1)
{
cout<<"Error!"<<endl;
goto ha;
}
if(answer==1)
{
fstream iofile("student.dat",ios::out|ios::binary);
if(!iofile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
for(i=0;i<record_n;i++)
{
iofile.write((char *)&stud2[i],sizeof(stud2[i]));
}
iofile.close();
cout<<"該學生信息修改完畢!"<<endl;
}
}
h0: cout<<endl;
}

//文件「信息刪除.cpp」
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;

/*————————————信息刪除函數——————————————*/
void info_delete()
{
int i,j,answer,num;
student stud1[n],stud2[n];
cout<<"返回請輸入0,刪除全部學生信息請輸入-1"<<endl;
cout<<"請輸入要刪除的學生學號:";
cin>>num;
if(num==-1)
{
ofstream outfile("record_n.txt",ios::out);
if(!outfile)
{
cerr<<"Open file error!"<<endl;
abort();
}
outfile<<0; //數據個數恢復為0
outfile.close();
fstream iofile("student.dat",ios::out|ios::binary);
if(!iofile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
iofile.close();
cout<<"學生信息已經全部刪除"<<endl;

}
else
{
if(num==0)goto h0;
else
{
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
if(record_n==0)cout<<"Error!\n沒有記錄"<<endl;
else
{
for(i=0;i<record_n;i++) //讀取所有數據到一個數組
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
}
infile.close();
/*進行對比,找到相應學號*/
for(i=0;i<record_n;i++)
{
if(num==stud1[i].num) //判斷,如果符合查詢條件則輸出到屏幕
{
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(16)<<stud1[i].phone<<" 來自省份:"<<setw(16)<<stud1[i].address<<endl<<endl;
j=i; //記錄要刪除學號的序號
}
}
for(i=0;i<record_n;i++) //此句和下一句if語句是判斷有無該學號,無則提示
{
if(num==stud1[i].num)break;
}
if(i>=record_n)
{
cout<<"Error!\n未找到該學號,";
goto h0;
}
ha: cout<<"是否確定刪除該記錄?確定輸入1,返回輸入0"<<endl;
cin>>answer;
if(answer==0)goto h0;
if(answer!=0&&answer!=1)
{
cout<<"Error!"<<endl;
goto ha;
}
if(answer==1)
{
/*將對應學號去掉後,剩餘學生信息用stud2[]記錄,清空原文件,再寫入文件*/
for(i=0;i<j;i++)
stud2[i]=stud1[i];
for(i=j;i<record_n-1;i++)
stud2[i]=stud1[i+1];
ofstream outfile("record_n.txt",ios::out);
if(!outfile)
{
cerr<<"Open file error!"<<endl;
abort();
}
outfile<<record_n-1; //記錄數據個數
outfile.close();
fstream iofile("student.dat",ios::out|ios::binary);
if(!iofile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
for(i=0;i<record_n-1;i++)
{
iofile.write((char *)&stud2[i],sizeof(stud2[i]));
}
iofile.close();
cout<<"該學號已經刪除"<<endl;
}
}
}
h0: cout<<endl;
}

//文件「信息排序.cpp」
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;

/*————————————信息排序函數————————————*/
void info_sort()
{
int i;
cout<<endl<<"1—按學號排序,2—按出生年月排序,0—返回"<<endl;
h3: cout<<"請選擇:";
cin>>i;
switch(i)
{
case 0:goto h7;
case 1:sort_num();break;
case 2:sort_day();break;
default:cout<<"Error!"<<endl<<endl;goto h3;
}
h7: cout<<endl;
}

/*—————按照學號排序函數—————*/
void sort_num()
{
int i,j;
student stud1[n],t;
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
if(record_n==0)cout<<"Error!\n沒有記錄"<<endl;
else
{
for(i=0;i<record_n;i++)
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
}
for(i=0;i<record_n-1;i++) //用起泡法對所有學號進行排序
{
for(j=0;j<record_n-i-1;j++)
{
if(stud1[j].num>stud1[j+1].num)
{
t=stud1[j];
stud1[j]=stud1[j+1];
stud1[j+1]=t;
}
}
}
infile.close();
/*將排序好的數據寫入文件*/
ofstream outfile("student.dat",ios::out|ios::binary);
if(!outfile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
for(i=0;i<record_n;i++)
{
outfile.write((char *)&stud1[i],sizeof(stud1[i]));
}
outfile.close();
cout<<"排序完成";
cout<<endl;
}

/*————按照出生年月排序函數————*/
void sort_day()
{
int i,j;
student stud1[n],t;
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
if(record_n==0)cout<<"Error!\n沒有記錄"<<endl;
else
{
for(i=0;i<record_n;i++)
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
}
/*以下對學生的出生年月進行排序*/

for(i=0;i<record_n-1;i++) //用起泡法對學生出生年份進行排序
{
for(j=0;j<record_n-i-1;j++)
{
if(stud1[j].birthday.year>stud1[j+1].birthday.year)
{
t=stud1[j];
stud1[j]=stud1[j+1];
stud1[j+1]=t;
}
}
}
for(i=0;i<record_n-1;i++) //用起泡法對出生年份相同的學生的出生月份進行排序
{
for(j=0;j<record_n-i-1;j++)
{
if(stud1[j].birthday.year==stud1[j+1].birthday.year)
{
if(stud1[j].birthday.month>stud1[j+1].birthday.month)
{
t=stud1[j];
stud1[j]=stud1[j+1];
stud1[j+1]=t;
}
}
}
}
infile.close();
/*將排序好的數據寫入文件*/
ofstream outfile("student.dat",ios::out|ios::binary);
if(!outfile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
for(i=0;i<record_n;i++)
{
outfile.write((char *)&stud1[i],sizeof(stud1[i]));
}
outfile.close();
cout<<endl<<"排序完成"<<endl;
}

//文件「信息錄入.cpp」
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;

/*——————信息錄入函數——————*/
void info_input()
{
int i=0,j;
student stud1[n];
student *p,*p1;
p=stud+i;
p1=stud1+record_n;
ifstream infile("student.dat",ios::binary);
if(record_n==0)cout<<endl;
else
{
if(!infile)
{
cerr<<"Open file error!"<<endl;
exit(1);
}
for(i=0;i<record_n;i++) //for語句讀取記錄到一個數組,便於進行比較,使輸入學號不重復
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
infile.close();
cout<<endl;
}
cout<<"請按以下順序輸入學生信息:學號、姓名、性別、出生年、月、電話號碼、省份";
cout<<endl<<"如果要終止錄入學生信息,請輸入0,然後回車"<<endl<<endl;

for(i=0;i<n;i++,p++,p1++)
{
cout<<"請輸入第"<<record_n+i+1<<"個學生的信息:";
cin>>p->num;
p1->num=p->num;
if(p->num==0)break;
for(j=0;j<record_n+i;j++)
{
if(p->num==stud1[j].num)
{
cout<<"Error!\n輸入的學號與已有記錄重復!"<<endl;
goto hi;
}
}
cin>>p->name>>p->sex;
cin>>p->birthday.year>>p->birthday.month;
cin>>p->phone>>p->address;
ofstream outfile("student.dat",ios::app|ios::binary);
if(!outfile)
{
cerr<<"Open file error!"<<endl;
abort();
}
outfile.write((char *)&stud[i],sizeof(stud[i]));
outfile.close();
fstream iofile("record_n.txt",ios::out);
if(!iofile)
{
cerr<<"Open file error!"<<endl;
abort();
}
iofile<<record_n+i+1; //記錄數據個數
iofile.close();
}
hi: cout<<endl;

}

//文件「信息查詢.cpp」
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;

/*——————————————信息查詢函數————————————*/

void info_inquire()
{
int i;
h6: cout<<endl<<"1—按學號查詢, 2—按姓名查詢, 3—按性別查詢,"<<endl;
cout<<"4—輸出全部學生信息, 0—返回"<<endl;
h3: cout<<"請選擇:";
cin>>i;
switch(i)
{
case 0:goto h7;
case 1:acc_num();break;
case 2:acc_name();break;
case 3:acc_sex();break;
case 4:output_all();break;
default:cout<<"Error!"<<endl<<endl;goto h3;
}
goto h6;
h7: cout<<endl;
}
/*————按照學號查詢函數—————*/
void acc_num()
{
int i;
int num;
student stud1[n];
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
goto h5;
}
h4: cout<<"請輸入要查詢的學生的學號(返回請輸入0):"<<endl;
cin>>num;
if(num==0)
{
infile.close();
goto h5;
}
for(i=0;i<record_n;i++) //for語句讀取記錄到一個數組
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
infile.close();
for(i=0;i<record_n;i++)
{
if(num==stud1[i].num) //判斷,如果符合查詢條件則輸出到屏幕
{
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(16)<<stud1[i].phone<<" 來自省份:"<<setw(16)<<stud1[i].address<<endl<<endl;
}

}
for(i=0;i<record_n;i++) //此句和下一句if語句是判斷有無該學號,無則提示
{
if(num==stud1[i].num)break;
}
if(i>=record_n)cout<<"Error!\n未找到該學號,";
goto h4;
h5: cout<<endl;
}

/*————按照姓名查詢函數—————*/
void acc_name()
{
int i;
char name[20];
student stud1[n];
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
goto h5;
}
h4: cout<<"請輸入要查詢的學生的姓名(返回請輸入0):"<<endl;
cin>>name;
if(strcmp(name,"0")==0)
{
infile.close();
goto h5;
}
for(i=0;i<record_n;i++)
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
infile.close();
for(i=0;i<record_n;i++)
{
if(strcmp(name,stud1[i].name)==0)
{
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(15)<<stud1[i].phone<<" 來自省份:"<<setw(15)<<stud1[i].address<<endl<<endl;
}
}
for(i=0;i<record_n;i++) //此句和下一句if語句是判斷有無該姓名,無則提示
{
if(strcmp(name,stud1[i].name)==0)break;
}
if(i>=record_n)cout<<"Error!\n未找到該姓名,";
goto h4;
h5: cout<<endl;
}

/*————按照性別查詢函數—————*/
void acc_sex()
{
int i;
char sex[5];
student stud1[n];
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
goto h5;
}
h4: cout<<"請輸入要查詢的學生的性別(返回請輸入0):"<<endl;
cin>>sex;
if(strcmp(sex,"0")==0)
{
infile.close();
goto h5;
}
for(i=0;i<record_n;i++)
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
}
infile.close();
for(i=0;i<record_n;i++)
{
if(strcmp(sex,stud1[i].sex)==0)
{
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(15)<<stud1[i].phone<<" 來自省份:"<<setw(15)<<stud1[i].address<<endl<<endl;
}
}
for(i=0;i<record_n;i++) //此句和下一句if語句是判斷有無該性別的學生記錄,無則提示
{
if(strcmp(sex,stud1[i].sex)==0)break;
}
if(i>=record_n)cout<<"Error!\n未找到該性別的學生記錄,";
goto h4;
h5: cout<<endl;
}

/*————輸出全部學生信息—————*/
void output_all()
{
int i;
student stud1[n];
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cerr<<"Open file error!"<<endl;
goto h0;
}
if(record_n==0)cout<<"Error!\n沒有記錄"<<endl;
else
{
for(i=0;i<record_n;i++)
{
infile.read((char *)&stud1[i],sizeof(stud1[i]));
cout<<"第"<<i+1<<"個學生數據:"<<endl;
cout<<"學號:"<<setw(20)<<stud1[i].num<<" 姓名:"<<setw(20)<<stud1[i].name<<endl;
cout<<"性別:"<<setw(20)<<stud1[i].sex<<" 出生年月:"<<setw(10)<<stud1[i].birthday.year<<"年"<<stud1[i].birthday.month<<"月 "<<endl;
cout<<"電話號碼:"<<setw(15)<<stud1[i].phone<<" 來自省份:"<<setw(15)<<stud1[i].address<<endl<<endl;
}
}
infile.close();
h0: cout<<endl;
}

//文件「common.h」
/*—————————定義類—————————定義類——————*/
struct Day //定義結構體類型Day
{
int year;
int month;
};

class student //定義類student
{
public:
int num;
char name[20];
char sex[5];
Day birthday;
char phone[15];
char address[15];
};

/*—————全局變數、函數聲明————全局變數、函數聲明—————*/

const int n=200; //n=200,表示最多可記錄200個學生的數據,可以修改,以適應需要
int record_n=0; //記錄數據個數,初始化為0
student stud[n];
void info_input(); //信息錄入函數
void info_inquire(),acc_num(),acc_name(),acc_sex(),output_all();//信息查詢函數
void info_sort(),sort_num(),sort_day(); //信息排序函數
void info_update(); //信息修改函數
void info_delete(); //信息刪除函數

閱讀全文

與學生檔案管理系統演算法相關的資料

熱點內容
噴油螺桿製冷壓縮機 瀏覽:579
python員工信息登記表 瀏覽:377
高中美術pdf 瀏覽:161
java實現排列 瀏覽:513
javavector的用法 瀏覽:982
osi實現加密的三層 瀏覽:233
大眾寶來原廠中控如何安裝app 瀏覽:916
linux內核根文件系統 瀏覽:243
3d的命令面板不見了 瀏覽:526
武漢理工大學伺服器ip地址 瀏覽:149
亞馬遜雲伺服器登錄 瀏覽:525
安卓手機如何進行文件處理 瀏覽:71
mysql執行系統命令 瀏覽:930
php支持curlhttps 瀏覽:143
新預演算法責任 瀏覽:444
伺服器如何處理5萬人同時在線 瀏覽:251
哈夫曼編碼數據壓縮 瀏覽:426
鎖定伺服器是什麼意思 瀏覽:385
場景檢測演算法 瀏覽:617
解壓手機軟體觸屏 瀏覽:350