DOCX

include

By Wesley Ward,2014-07-01 11:07
6 views 0
includeinclud

#include<iostream>

    #include<iomanip>

    #include<string>

    using namespace std;

    struct Student

    {char name[20];

     int num;

     int a[4];

     int rz;

     float rj;

    }stu[3]={{"Wang",101,55,57,80,96,0,0},{"Li",102,91,86,93,95,0,0},{"Zhao",103,82,61,49,52,0,0}};

    struct a

    {

     int kz;

     float kj;

    }ke[4]={0,0,0,0,0,0,0,0};

    void xs()

    {cout <<setw(12)<<"姓名"<<setw(7)<<"学号"<<setw(7)<<"数学"<<setw(12)<<"数据结构"<<setw(10)

    <<"C++"<<setw(8)<<"英语"<<setw(13)<<"每人总分"<<setw(11)<<"每人均分"<<endl; cout <<"--------------------------------------------------------------------------------";}

    float avg(struct Student stu[],struct a ke[])

    {

     int i,j;

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

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

     stu[i].rz=stu[i].rz+stu[i].a[j];

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

     stu[i].rj=stu[i].rz/4.0;

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

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

     ke[i].kz=ke[i].kz+stu[j].a[i];

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

     ke[i].kj=ke[i].kz/3.0;

     return 1;

    }

    float Avg(struct Student stu[],struct a ke[])

    {

     int i;

     avg(stu,ke);

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

     cout

    <<setw(12)<<stu[i].name<<setw(7)<<stu[i].num<<setw(7)<<stu[i].a[0]<<setw(10)<<stu[i].a[1]<<s

    etw(10)

<<stu[i].a[2]<<setw(10)<<stu[i].a[3]<<setw(10)<<stu[i].rz<<setw(14)<<stu[i].rj<<endl;

     cout <<"课程总分"<<setw(19);

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

     cout <<ke[i].kz<<setw(10);

     cout <<'\b'<<endl<<endl<<"课程均分"<<setw(18);

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

     cout <<ke[i].kj<<setw(10);

     cout <<endl<<endl;

    return 1;}

    void highest(struct Student stu[]) {

     int i,j,max=0,max_i,max_j;

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

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

     if(stu[i].a[j]>max)

     {max=stu[i].a[j];

     max_i=i;max_j=j;}

     cout <<"高分"<<max<<""<<',';

     cout <<"其对应学生?"<<stu[max_i].name<<',';

     cout <<"其对应课程?";

     if(max_j==0)cout <<"C++"<<endl;

     else if(max_j==1)cout <<"数据结构"<<endl;

     else if(max_j==2)cout <<"C++"<<endl;

     else cout <<"英语"<<endl;

     cout <<endl;

    }

    void bjg(struct Student stu[]) {

     int i,j,s[3]={0,0,0};

     string r[3];

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

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

     if(stu[i].a[j]<60)s[i]++;

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

     if(s[i]==2||s[i]>2)r[i]="";

     else r[i]="";

    cout <<setw(12)<<"姓名"<<setw(7)<<"学号"<<setw(7)<<"数学"<<setw(12)<<"数据结构"<<setw(10)

    <<"C++"<<setw(8)<<"英语"<<setw(11)<<"及格"<<endl; cout <<"--------------------------------------------------------------------------------";

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

     cout

    <<setw(12)<<stu[i].name<<setw(7)<<stu[i].num<<setw(7)<<stu[i].a[0]<<setw(10)<<stu[i].a[1]<<s

    etw(10)

<<stu[i].a[2]<<setw(10)<<stu[i].a[3]<<setw(10)<<r[i]<<endl<<endl;

    }

void jm()

    {cout <<endl<<"------ 学生成绩分析------"<<endl; cout <<"1.输出学生基本成绩信息"<<endl;

    cout <<"2.输出高分对应学生和课程"<<endl; cout <<"3.两门上;包括两门;课程及格输出及格否否则输出学生信息"<<endl;

cout <<"4.退出"<<endl;

    }

    int main()

    {

    int choice;

    char s;

    cout <<"**********************************"<<endl;

    cout <<" 欢迎使用 "<<endl;

    cout <<"**********************************"<<endl;

    jm();

    while(1)

    {Student

    stu[3]={{"Wang",101,55,57,80,96,0,0},{"Li",102,91,86,93,95,0,0},{"Zhao",103,82,61,49,52,0,0}};

    a ke[4]={0,0,0,0,0,0,0,0}; cout <<"否继续;y/n";

    cin >>s;

    if(s=='y')

    {jm();

    cout <<"请选择;1-4;?";

    cin >>choice;}

    else return 0;

    switch(choice)

    {

    case 1:

     xs();

     Avg(stu,ke);

     break;

    case 2:

     highest(stu);

     break;

    case 3:

     bjg(stu);

     break;

case 4:

     return 0;

}}}

Report this document

For any questions or suggestions please email
cust-service@docsford.com