C语言学生成绩管理系统

c学生成绩管理系统

C语言学生成绩管理系统

想要它变成什么样,自己做一下修改就是了:

#include<iostream>

#include<fstream>

#include <windows.h>

#include<string>

#include <time.h>

#include<cstdlib>

#include<iomanip>

using namespace std;

int n=0;

#define M cout<<

#define N ;Sleep(80);

#define Y N M

#define NN cout<<"╭—————————————————————————————————————————————╮"<<endl;cout<<"∣ num ∣ name∣ age ∣ hig ∣ 语文 ∣ 数学 ∣ 英语 ∣ 平均 ∣ 总分 ∣ 评语 ∣ "<<endl;cout<<"├———-┼———-┼———┼———┼———-┼———-┼———-┼—————┼————┼———-┤"<<endl;cout<<"∣"<<setw(6)<<p1->num<<setw(3)<<"∣"<<setw(7)<<p1->name<<setw(2)<<"∣"<<setw(4)<<p1->age<<setw(4)<<"∣"<<setw(4)<<p1->hig<<setw(4)<<"∣"<<setw(5)<<p1->score[0]<<setw(4)<<"∣"<<setw(5)<<p1->score[1]<<setw(4)<<"∣"<<setw(5)<<p1->score[2]<<setw(4)<<"∣"<<setw(8)<<setprecision(3)<<p1->ave<<setw(4)<<"∣"<<setw(6)<<p1->sum<<setw(4)<<"∣"<<setw(7)<<p1->p_y<<setw(2)<<"∣"<<endl;cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ "<<endl;

////////////////////////////////////////////////////////////////////////////////////////////

////

////

////

////////////////////////////////////////////////////////////////////////////////////////////

class ji_ke_1_class

{

int num;

char name[20];

int age;

float hig;

int score[3];

float ave;

float sum;

char p_y[10];

public:

void set_date();

void display();

void creat();

void print();

void insert();

void exchange(ji_ke_1_class *p1,ji_ke_1_class *p2);

void sort(int j);

void index(int q,char aa[20]);

void del(int num);

void save();

void tongji();

void load();

class ji_ke_1_class *next;

};

ji_ke_1_class *head,*p1,*p2,*p;

void ji_ke_1_class::set_date ()

{

cout<<"学号_姓名_年龄_身高_"<<endl;

cin>>num>>name>>age>>hig;

cout<<"-----分数::语文_数学_英语_"<<endl<<" ";

for(int i=0;i<3;i++)

cin>>score[i] ;

}

void ji_ke_1_class::display()

{

ji_ke_1_class *p;

int i;

for( p=head , i=0 ; i<n ; i++ , p=p->next )

cout<<"∣"

<<setw(6)<<p->num

<<setw(3)<<"∣"

<<setw(7)<<p->name

<<setw(2)<<"∣"

<<setw(4)<<p->age

<<setw(4)<<"∣"

<<setw(4)<<p->hig

<<setw(4)<<"∣"

<<setw(5)<<p->score[0]

<<setw(4)<<"∣"

<<setw(5)<<p->score[1]

<<setw(4)<<"∣"

<<setw(5)<<p->score[2]

<<setw(4)<<"∣"

<<setw(8)<<setprecision(3)<<p->ave

<<setw(4)<<"∣"

<<setw(6)<<p->sum

<<setw(4)<<"∣"

<<setw(7)<<p->p_y

<<setw(2)<<"∣"

<<endl;

}

void ji_ke_1_class::print()

{

ji_ke_1_class *p0=head;

cout<<"╭—————————————————————————————————————————————╮"<<endl;

cout<<"∣ num ∣ name∣ age ∣ hig ∣ 语文 ∣ 数学 ∣ 英语 ∣ 平均 ∣ 总分 ∣ 评语 ∣ "<<endl;

cout<<"├———-┼———-┼———┼———┼———-┼———-┼———-┼—————┼————┼———-┤"<<endl;

p0->display();

cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ "<<endl;

}

void ji_ke_1_class::creat()

{

int m=0;

float total=0;

head=p2=p1=new ji_ke_1_class;

p1->set_date();

while(p1->num!=0)

{

n=n+1;

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

p1=new ji_ke_1_class;

p1->set_date ();

}

p2->next=0;

ji_ke_1_class *p=new ji_ke_1_class;

for(p=head ; m<n ; p=p->next )

{

total=total+p->score[0]+p->score[1]+p->score[2];

p->sum=total;

p->ave=total/3;

cout<<p->sum<<"--------__"<<p->ave<<endl;

if(p->ave>85) strcpy( p->p_y , "优秀" );

else if(p->ave>75) strcpy( p->p_y , "中等" );

else if(p->ave>60) strcpy( p->p_y , "及格" );

else strcpy( p->p_y , "不及格" );

total=0;

m+=1;

}

}

template<typename T1>

void exchang1(T1 &a,T1 &b)

{

int t;

t=a;

a=b;

b=t;

}

template<typename T2>

void exchang2(T2 &a,T2 &b)

{

float t;

t=a;

a=b;

b=t;

}

void ji_ke_1_class::exchange(ji_ke_1_class *p1,ji_ke_1_class *p2)

{

char t2[30],t1[10];

exchang1(p1->num,p2->num);

exchang1(p1->score[1],p2->score[1]);

exchang1(p1->score[0],p2->score[0]);

exchang1(p1->score[2],p2->score[2]);

exchang2(p1->hig,p2->hig);

exchang2(p1->ave,p2->ave);

exchang2(p1->sum,p2->sum);

strcpy(t2,p1->name);

strcpy(p1->name,p2->name);

strcpy(p2->name,t2);

strcpy(t1,p1->p_y );

strcpy(p1->p_y ,p2->p_y );

strcpy(p2->p_y ,t1);

}

void ji_ke_1_class::sort(int j)

{

ji_ke_1_class *p1,*p2;

int m,t;

cout<<endl;

for(p1=head , m=0 ; m<n-1 ; m++ , p1=p1->next)

for(p2=p1->next,t=m+1 ; t<n ; t++ , p2=p2->next)

{

if( (p1->num) > (p2->num) && j==1 ) exchange(p1,p2);

if( (p1->sum) < (p2->sum) && j==2 ) exchange(p1,p2);

}

print();

cout<<endl;

}

void ji_ke_1_class::del(int num)

{

ji_ke_1_class *p1,*p2;

if(head==0)

{

cout<<"\nlist null!\n";

goto end1;

}

p1=head;

while(num!=p1->num && p1->next!=0)

{

p2=p1;

p1=p1->next;

}

if(num==p1->num)

{

if(p1==head) head=p1->next;

else p2->next=p1->next;

cout<<"\n"<<"恭喜你--deleted the:"<<num<<endl<<endl;

n=n-1;

}

else cout<<num<<"抱歉--好像没有这个数吧!!\n"<<"\n\n";

end1: ;

}

void ji_ke_1_class::insert()

{

float total;

ji_ke_1_class *pt=new ji_ke_1_class;

ji_ke_1_class *p0,*p1,*p2;

pt=new ji_ke_1_class;

pt->set_date();

total=0;

int i;

for(i=0;i<3;i++)

total+=pt->score[i];

pt->sum=total;

pt->ave=total/3;

if(pt->ave>85) strcpy( pt->p_y , "优秀" );

else if(pt->ave>75) strcpy( pt->p_y , "中等" );

else if(pt->ave>60) strcpy( pt->p_y , "及格" );

else strcpy( pt->p_y , "不及格" );

p1=head;

p0=pt;

if(head==0)

{

head=p0;

p0->next=0;

}

else

{

while( (p0->num>p1->num)&&(p1->next!=0))

{

p2=p1;

p1=p1->next;

}

if(p0->num<=p1->num)

{

if(head==p1) head=p0;

else p2->next=p0;

p0->next=p1;

}

else

{

p1->next=p0;

p0->next=0;

}

}

n=n+1;

}

void ji_ke_1_class::index(int q,char aa[20])

{

ji_ke_1_class *p1=head;

int m=0,j=0;

int len,flag=1;

int a[4];

for( m=0 ; m<n ; p1=p1->next , m++ )

{

a[0]=0;a[1]=0;a[2]=0;a[3]=0;

flag=1;

a[0]=(int)( (p1->num)/1000 ); a[1]=(int)( (p1->num-a[0]*1000 )/100 );

a[2]=(int)( (p1->num-a[1]*100-a[0]*1000 )/10 ); a[3]=(int)( p1->num-a[1]*100-a[0]*1000-a[2]*10 );

for(int i=19 ; i>=0 ; i--)

{

if(aa[i]!=0)

len=i+1;

}

int m[4],k=0,y=0,x=0,d=0;

for(k=0;k<4;k++)

{

d=0;

y=(int)aa[k];

for(x=48;x<=57;x++)

{

d++;

if(x==y) m[k]=(d-1);

}

}

for(j=0 ; j<4 ; j++ )

{

if( a[j]!=m[j] )

flag=0;

}

if( flag==1 && q==1 )

{

NN

break;

}

if( p1->name[0]==aa[0] && p1->name[1]==aa[1] && p1->name[2]==aa[2] && q==2 )

{

NN

break;

}

}

if( m==n ) cout<<"no the student"<<endl;

}

int x[20];

string filename;

void ji_ke_1_class::save()

{

int d,d1=0;

int ii;

cout<<endl<<"请输入存储路径(建议存入当前文件中的data_save中)(例 ---绝对路径:C:\\\\文件名\\\\文件名\\\\数据名.dat \n "

<<" ---相对路径:save\\\\数据名.dat; )"

<<endl

<<"路径为:";

string cc;

cin>>cc;

cout<<" ╭——————————————╮"<<endl<<"正在保存 ";

for(ii=0;ii<15;ii++)

{

cout<<'\20';

Sleep(15);

}

ifstream file1("程序必用1.dat",ios::binary);

file1.read( (char *)&d , sizeof(d) );

d1=(int)d+1;

file1.close();

string filename0,name_file;

filename0=cc;

name_file=filename0.c_str();

ofstream file2("程序必用1.dat",ios::binary);

file2.write( (char *)&d1 , sizeof(d1) );

file2.close();

ofstream file3("程序必用2.dat", ios::app|ios::out );

file3<<name_file.c_str ()<<" ";

file3.close();

ofstream outfile(cc.c_str(),ios::binary);

if(!outfile)

{

cerr<<"!!!!!"<<endl;

abort();

}

outfile.write( (char *)&n , sizeof(n) );

ji_ke_1_class *p=head;

for(int i=0;i<n;i++,p=p->next)

outfile.write( (char *)p,sizeof(ji_ke_1_class));

outfile.close();

for(ii=0;ii<15;ii++)

{

cout<<'\20';

Sleep(15);

}

cout<<endl<<endl;

cout<<"-----已成功保存!!!!!!"<<endl<<endl;

}

void ji_ke_1_class::load()

{

int h1,h2;

string qq,name[20],name0[20];

ifstream file("程序必用1.dat",ios::binary);

if(!file)

{

cerr<<"open error!!"<<endl;

abort();

}

file.read( (char *)&h1, sizeof(h1) );

h2=int(h1);

cout<<"共有以下 "<<h2<<" 个文件"<<endl;

ifstream file0("程序必用2.dat",ios::in);

if(!file0)

{

cerr<<"open error!!"<<endl;

abort();

}

for(int e=0;e<h2;e++)

{

if(e%2==0) cout<<endl;

file0>>name[e];

name0[e]=name[e];

cout<<"第"<<e+1<<"个文件:"<<setw(16)<<(string)name0[e]<<" ; ";

}

file0.close();

cout<<endl;

loop3:

cout<<endl<<"请输入路径(例 ---绝对路径:C:\\\\文件名\\\\文件名\\\\数据名.dat ---相对路径:save\\\\数据名.dat;)"<<endl ;

cout<<"路径为:";

string ccc;

cin>>ccc;

cout<<" ╭——————————————╮"<<endl<<"正在读取 ";

int ii;

for(ii=0;ii<15;ii++)

{

cout<<'\20';

Sleep(15);

}

ifstream infile(ccc.c_str(),ios::binary);

int c;

ji_ke_1_class t[60],*pp[60];

if(!infile)

{

cout<<endl<<"无此文件; 1---重输 ; other---放弃";

cin>>c;

if(c==1) goto loop3;

else goto loop4;

}

int nn,nnn;

int i;

infile.read( (char *)&nn , sizeof(nn) );

nnn=(int)nn;

n=nnn;

infile.read( (char *)&t[0] , sizeof(ji_ke_1_class) );

head=(ji_ke_1_class *)&t[0];

for(i=1; i<nnn; i++)

{

infile.read( (char *)&t[i] , sizeof(ji_ke_1_class) );

pp[i]=(ji_ke_1_class *)&t[i];

if(i==1)

{

head->next=pp[1];

}

if(i!=1)

{

pp[i-1]->next=pp[i];

}

}

infile.close();

for(ii=0;ii<15;ii++)

{

cout<<'\20';

Sleep(15);

}

cout<<endl;

cout<<endl<<"————————恭喜!!!成功装载,数据文件以可以使用"<<endl<<endl;

loop4:;

}

void ji_ke_1_class::tongji()

{

ji_ke_1_class *pm=head;

int m,by=0,bz=0,bc=0,bj=0;

for(pm=head , m=0 ; m<n ; m++ , pm=pm->next)

{

if( pm->ave >= 85 ) by++;

if( pm->ave < 85 && pm->ave >=75 ) bz++;

if( pm->ave >=60 && pm->ave < 75 ) bj++;

if( pm->ave < 60 ) bc++;

}

cout<<endl

<<"总计 "<<n<<" 人:"<<endl

<<" 优秀生人数:"<<setw(5)<<by<<setw(12)<<"优秀率为:"<<setw(6)<<setprecision(5)<<(double)by/n<<endl

<<" 中等生人数:"<<setw(5)<<bz<<setw(12)<<"中等率为:"<<setw(6)<<setprecision(5)<<(double)bz/n<<endl

<<" 及格生(60-75)人数:"<<setw(5)<<bj<<setw(12)<<"及格率为:"<<setw(6)<<setprecision(5)<<(double)bj/n<<endl

<<" 不及格人数为:"<<setw(5)<<bc<<setw(12)<<"不及格率为:"<<setw(6)<<setprecision(5)<<(double)bc/n<<endl<<endl;

}

void bz()

{

system("cls");

M"欢"Y"迎"Y"使"Y"用"Y"本"Y"程"Y"序"Y"-"Y"-"Y"-"Y"-"Y"-"Y" 使"Y"用"Y"说"Y"明"Y":"N;cout<<endl<<endl;

M"一"Y""Y"、"Y"建"Y"立"Y"自"Y"己"Y"的"Y"数"Y"据"Y"("Y"建"Y"议"Y"马"Y"上"Y"存"Y"储"Y"!"Y"!"Y")"Y"按"Y"提"Y"示"Y"操"Y"作"Y"即"Y"可"Y";"Y"呵"Y"呵"N;cout<<endl<<endl;

M"二"Y""Y"、"Y"注"Y"意"Y"事"Y"项"Y":"Y" 对"Y"链"Y"表"Y"("Y"数"Y"据"Y")"Y"若"Y"超"Y"过"Y"6"Y"0"Y"个"Y","Y"则"Y"请"Y"联"Y"系"Y""Y""Y"吕"Y""Y""Y"威"Y""Y""Y"___"Y"qq"Y":"Y"921963406"Y","Y"可"Y"免"Y"费"Y"赠"Y"送"Y"所"Y"需"Y"程"Y"序"N;cout<<endl<<endl;

M"三"Y""Y"、"Y"建"Y"链"Y"表"Y"的"Y"最"Y"后"Y"使"Y"全"Y"为"Y"0"Y","Y"建"Y"表"Y"结"Y"束"N;cout<<endl<<endl;

M"四"Y""Y"、"Y"因"Y"技"Y"术"Y"有"Y"限"Y","Y"清"Y"屏"Y"函"Y"数"Y"造"Y"成"Y"head"Y"丢"Y"失"Y";"Y"慎"Y"用"Y"!"Y"!"N;cout<<endl<<endl<<" ";

M"制"Y"作"Y"人"Y":"Y""Y""Y""Y""Y"吕"Y""Y""Y""Y""Y"威"Y""Y""Y""Y""N;cout<<endl<<endl;

}

////////////////////////////////////////////////////////////////////////////////////////////

////

////

////////////////////////////////////////////////////////////////////////////////////////////

void mult()

{tm * tp;

time_t t;

cout<<"____________________________________________________________________________________________________\n";

cout<<" ╭——————————————╮\n"

<<" ";

t=time(NULL);

tp=localtime(&t);

cout<<tp->tm_mon+1<<"-"<<tp->tm_mday<<"-"<<tp->tm_year+1900<<" ";

cout<<tp->tm_hour<<":"<<tp->tm_min<<":"<<tp->tm_sec;

cout<<" ∣ 菜单 ∣ \n"

<<" ∣____________________________∣\n"

<<" ∣ 0---创建数据 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 1---按学号排序 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 2---按分数排序 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 3---删除一学生信息 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 4---插入一学生信息 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 5---检索一学生 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 6---统计数据 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 7---保存 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 8---打开 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 9---清屏 ∣\n"

<<" ∣ ∣\n"

<<" ∣ 10--帮助(建议先看) ∣\n"

<<" ∣ other---quit ∣\n"

<<" ∣ ∣\n"

<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n";

}

void select()

{

int fl=0,a,num2;

ji_ke_1_class aa;

loop:

cout<<"What can I do for you ? ? ?(输入命令---数字) :";

cin>>a;

switch(a)

{

case 0 :

{

cout<<"输入数据\n";

aa.creat();

aa.print();

goto loop;

}

case 1 :

{

aa.sort(1);

goto loop;

}

case 2 :

{

aa.sort(2);

goto loop;

}

case 3 :

{

cout<<"num========";

cin>>num2;

aa.del(num2);

goto loop;

}

case 4 :

{

aa.insert();

goto loop;

}

case 5 :

{

char xx[20]={0};

cout<<"输入要查询的学生的学号 或 姓名:";

cin>>xx;

if( xx[0]>=48 && xx[0]<=57 )

aa.index(1,xx);

else

aa.index(2,xx);

goto loop;

}

case 6 :

{

aa.tongji();

goto loop;

}

case 7 :

{

aa.save();

fl=1;

goto loop;

}

case 8 :

{

aa.load();

goto loop;

}

case 9 :

{

ji_ke_1_class *nn=new ji_ke_1_class;

head=nn;

system("cls");//清屏造成head丢失-------------------------------------------------------??????????????????

nn=head;

mult();

goto loop;

}

case 10 :

{

bz();

mult();

goto loop;

}

default :

{

if(fl=0)

{

char f;

cout<<"你想要储存吗?y/N";

cin>>f;

if(f=='y'||f=='y')

{

aa.save();

fl=1;

goto loop;

}

else goto end;

}

else goto end;

}

}

end:;

}

void main()

{

int q2=0;

ifstream file0("程序必用1.dat",ios::binary);

if(!file0)

{

file0.close();

ofstream file1("程序必用1.dat",ios::binary);

file1.write( (char *)&q2 , sizeof(q2) );

file1.close();

goto loop5;

}

file0.close();

loop5:

mult();

select();

}

学生成绩管理系统属于计算机哪方面的应用

猜你喜欢

联系我们

联系我们

888-888

邮件:admin@lcrz.cn

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部