主题:原创:学生成绩处理程序
原创
/*
问题描述: 假设某公司招工n名。考试课程有五门。考试成
绩分为四类:第一类为一门不挂;第二类为挂一门;第三类
为挂两门;其余为第四类。录取方法是按类次并在每一类中
按总分从高到低录取。试设计一个成绩处理程序,要求打印
输出n份录取通知书,列出录取者五门课程的成绩及总分。
(假设第n名与第n+1名一定不会同类且总分相等。)
说明:
(1)输入数据:输入每个学生的姓名及各门课程的考试成绩。
(2)输出数据:按照择优录取的次序打印出n份录取通知书
如附图示(略)。
*/
#include <iostream.h>
#define n 8
int s_politics[]={80,85,90,30,60,100,70,85};
int s_mathematics[]={85,90,95,40,70,100,90,90};
int s_physics[]={90,70,40,50,80,100,60,90};
int s_chemistry[]={95,50,50,60,90,30,100,100};
int s_total[]={100,90,70,70,100,80,80,100};
struct student{
char name[25];
int politics;
int mathematics;
int physics;
int chemistry;
int total;
int score;
char leibie;
int k;//
};
struct student_arr{
student arr[n+1];
};
struct student_arr S_ARR;
student_arr build_student (student_arr ,int );
student_arr L_paixu (student_arr );
student_arr M_paixu (student_arr );
student_arr paixu (int );
void dayin(student_arr ,int );
void main()
{
S_ARR=build_student(S_ARR,n);
cout<<"============================================================="<<endl;
cout<<"====***************录取结果******************************===="<<endl;
cout<<"============================================================="<<endl;
S_ARR=L_paixu(S_ARR);
//dayin(S_ARR,n);
S_ARR=M_paixu(S_ARR);
dayin(S_ARR,n);
return;
}
//===============================
student_arr build_student(student_arr S_ARR,int m)
{
int i;
for(i=0;i<8;i++)
{
//=======================
cout<<"Input the name:"<<endl;
cin>>S_ARR.arr[i].name;
//=======1==================
//cout<"Input the politics score:"<<endl;
//cin>>S_ARR.arr[i].politics;
S_ARR.arr[i].politics=s_politics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].politics;
if(S_ARR.arr[i].politics<60) S_ARR.arr[i].k++;
//=======2================
//cout<<"Input the mathematics score:"<<endl;
//cin>>S_ARR.arr[i].mathematics;
S_ARR.arr[i].mathematics=s_mathematics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].mathematics;
if(S_ARR.arr[i].mathematics<60) S_ARR.arr[i].k++;
//========3===============
//cout<<"Input the physics score::"<<endl;
//cin>>S_ARR.arr[i].physics;
S_ARR.arr[i].physics=s_physics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].physics;
if(S_ARR.arr[i].physics<60) S_ARR.arr[i].k++;
//=======4================
//cout<<"Input the chemistry score::"<<endl;
//cin>>S_ARR.arr[i].chemistry;
S_ARR.arr[i].chemistry=s_chemistry[i];
S_ARR.arr[i].score+=S_ARR.arr[i].chemistry;
if(S_ARR.arr[i].chemistry<60) S_ARR.arr[i].k++;
//=======5================
//cout<<"Input the total score::"<<endl;
//cin>>S_ARR.arr[i].total;
S_ARR.arr[i].total=s_total[i];
S_ARR.arr[i].score+=S_ARR.arr[i].total;
if(S_ARR.arr[i].total<60) S_ARR.arr[i].k++;
if(S_ARR.arr[i].k>2) S_ARR.arr[i].k=3;
switch(S_ARR.arr[i].k)
{
case 0: S_ARR.arr[i].leibie='A';break;
case 1: S_ARR.arr[i].leibie='B';break;
case 2: S_ARR.arr[i].leibie='C';break;
case 3: S_ARR.arr[i].leibie='D';break;
default :cout<<"ERROR!"<<endl;
}
}//end for;
return S_ARR;
}// end build_student;
//=====================================
student_arr L_paixu(student_arr S_ARR)
{
int i,j;
for(j=0;j<n-1;j++)
for(i=j+1;i<n;i++)
if(S_ARR.arr[j].leibie>S_ARR.arr[i].leibie)
{
S_ARR.arr[n]=S_ARR.arr[j];
S_ARR.arr[j]=S_ARR.arr[i];
S_ARR.arr[i]=S_ARR.arr[n];
}
return S_ARR;
}//end L_paixu;
//=====================================
student_arr M_paixu(student_arr S_ARR)
{
int i,j;
for(j=0;j<n-1;j++)
for(i=j+1;i<n;i++)
if(S_ARR.arr[j].leibie==S_ARR.arr[i].leibie)
if(S_ARR.arr[j].score<S_ARR.arr[i].score)
{
S_ARR.arr[n]=S_ARR.arr[j];
S_ARR.arr[j]=S_ARR.arr[i];
S_ARR.arr[i]=S_ARR.arr[n];
}
return S_ARR;
}//end M_paixu;
void dayin(student_arr S_ARR,int m)
{
int i;
for(i=0;i<n;i++)
{
cout<<" ADMISSION NOTICE"<<endl<<endl;
cout<<" 名次:"<<" "<<i+1<<endl;
cout<<" 类别:"<<" "<<S_ARR.arr[i].leibie<<endl;
cout<<" 总分:"<<" "<<S_ARR.arr[i].score<<endl<<endl;
cout<<" NAME:"<<" "<<S_ARR.arr[i].name<<endl;
cout<<" You have been admitted!"<<endl;
cout<<" You scores:"<<endl;
cout<<" Politics"<<" "<<S_ARR.arr[i].politics<<endl;
cout<<" Mathematics"<<" "<<S_ARR.arr[i].mathematics<<endl;
cout<<" Physics"<<" "<<S_ARR.arr[i].physics<<endl;
cout<<" Chemistry"<<" "<<S_ARR.arr[i].chemistry<<endl;
cout<<" Total"<<" "<<S_ARR.arr[i].total<<endl;
cout<<endl;
cout<<endl;
cout<<" IBM COMPANY"<<endl;
cout<<"================================================="<<endl;
}
return;
}
此帖转自:[url]http://www.programfan.com/team/team.asp?team_id=1346[/url]
/*
问题描述: 假设某公司招工n名。考试课程有五门。考试成
绩分为四类:第一类为一门不挂;第二类为挂一门;第三类
为挂两门;其余为第四类。录取方法是按类次并在每一类中
按总分从高到低录取。试设计一个成绩处理程序,要求打印
输出n份录取通知书,列出录取者五门课程的成绩及总分。
(假设第n名与第n+1名一定不会同类且总分相等。)
说明:
(1)输入数据:输入每个学生的姓名及各门课程的考试成绩。
(2)输出数据:按照择优录取的次序打印出n份录取通知书
如附图示(略)。
*/
#include <iostream.h>
#define n 8
int s_politics[]={80,85,90,30,60,100,70,85};
int s_mathematics[]={85,90,95,40,70,100,90,90};
int s_physics[]={90,70,40,50,80,100,60,90};
int s_chemistry[]={95,50,50,60,90,30,100,100};
int s_total[]={100,90,70,70,100,80,80,100};
struct student{
char name[25];
int politics;
int mathematics;
int physics;
int chemistry;
int total;
int score;
char leibie;
int k;//
};
struct student_arr{
student arr[n+1];
};
struct student_arr S_ARR;
student_arr build_student (student_arr ,int );
student_arr L_paixu (student_arr );
student_arr M_paixu (student_arr );
student_arr paixu (int );
void dayin(student_arr ,int );
void main()
{
S_ARR=build_student(S_ARR,n);
cout<<"============================================================="<<endl;
cout<<"====***************录取结果******************************===="<<endl;
cout<<"============================================================="<<endl;
S_ARR=L_paixu(S_ARR);
//dayin(S_ARR,n);
S_ARR=M_paixu(S_ARR);
dayin(S_ARR,n);
return;
}
//===============================
student_arr build_student(student_arr S_ARR,int m)
{
int i;
for(i=0;i<8;i++)
{
//=======================
cout<<"Input the name:"<<endl;
cin>>S_ARR.arr[i].name;
//=======1==================
//cout<"Input the politics score:"<<endl;
//cin>>S_ARR.arr[i].politics;
S_ARR.arr[i].politics=s_politics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].politics;
if(S_ARR.arr[i].politics<60) S_ARR.arr[i].k++;
//=======2================
//cout<<"Input the mathematics score:"<<endl;
//cin>>S_ARR.arr[i].mathematics;
S_ARR.arr[i].mathematics=s_mathematics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].mathematics;
if(S_ARR.arr[i].mathematics<60) S_ARR.arr[i].k++;
//========3===============
//cout<<"Input the physics score::"<<endl;
//cin>>S_ARR.arr[i].physics;
S_ARR.arr[i].physics=s_physics[i];
S_ARR.arr[i].score+=S_ARR.arr[i].physics;
if(S_ARR.arr[i].physics<60) S_ARR.arr[i].k++;
//=======4================
//cout<<"Input the chemistry score::"<<endl;
//cin>>S_ARR.arr[i].chemistry;
S_ARR.arr[i].chemistry=s_chemistry[i];
S_ARR.arr[i].score+=S_ARR.arr[i].chemistry;
if(S_ARR.arr[i].chemistry<60) S_ARR.arr[i].k++;
//=======5================
//cout<<"Input the total score::"<<endl;
//cin>>S_ARR.arr[i].total;
S_ARR.arr[i].total=s_total[i];
S_ARR.arr[i].score+=S_ARR.arr[i].total;
if(S_ARR.arr[i].total<60) S_ARR.arr[i].k++;
if(S_ARR.arr[i].k>2) S_ARR.arr[i].k=3;
switch(S_ARR.arr[i].k)
{
case 0: S_ARR.arr[i].leibie='A';break;
case 1: S_ARR.arr[i].leibie='B';break;
case 2: S_ARR.arr[i].leibie='C';break;
case 3: S_ARR.arr[i].leibie='D';break;
default :cout<<"ERROR!"<<endl;
}
}//end for;
return S_ARR;
}// end build_student;
//=====================================
student_arr L_paixu(student_arr S_ARR)
{
int i,j;
for(j=0;j<n-1;j++)
for(i=j+1;i<n;i++)
if(S_ARR.arr[j].leibie>S_ARR.arr[i].leibie)
{
S_ARR.arr[n]=S_ARR.arr[j];
S_ARR.arr[j]=S_ARR.arr[i];
S_ARR.arr[i]=S_ARR.arr[n];
}
return S_ARR;
}//end L_paixu;
//=====================================
student_arr M_paixu(student_arr S_ARR)
{
int i,j;
for(j=0;j<n-1;j++)
for(i=j+1;i<n;i++)
if(S_ARR.arr[j].leibie==S_ARR.arr[i].leibie)
if(S_ARR.arr[j].score<S_ARR.arr[i].score)
{
S_ARR.arr[n]=S_ARR.arr[j];
S_ARR.arr[j]=S_ARR.arr[i];
S_ARR.arr[i]=S_ARR.arr[n];
}
return S_ARR;
}//end M_paixu;
void dayin(student_arr S_ARR,int m)
{
int i;
for(i=0;i<n;i++)
{
cout<<" ADMISSION NOTICE"<<endl<<endl;
cout<<" 名次:"<<" "<<i+1<<endl;
cout<<" 类别:"<<" "<<S_ARR.arr[i].leibie<<endl;
cout<<" 总分:"<<" "<<S_ARR.arr[i].score<<endl<<endl;
cout<<" NAME:"<<" "<<S_ARR.arr[i].name<<endl;
cout<<" You have been admitted!"<<endl;
cout<<" You scores:"<<endl;
cout<<" Politics"<<" "<<S_ARR.arr[i].politics<<endl;
cout<<" Mathematics"<<" "<<S_ARR.arr[i].mathematics<<endl;
cout<<" Physics"<<" "<<S_ARR.arr[i].physics<<endl;
cout<<" Chemistry"<<" "<<S_ARR.arr[i].chemistry<<endl;
cout<<" Total"<<" "<<S_ARR.arr[i].total<<endl;
cout<<endl;
cout<<endl;
cout<<" IBM COMPANY"<<endl;
cout<<"================================================="<<endl;
}
return;
}
此帖转自:[url]http://www.programfan.com/team/team.asp?team_id=1346[/url]