?? main.cpp
字號:
#include<iostream.h>
#include<string.h>
class student //學生類的定義,私有成員字符串型學號,各門成績和總分,
{
private: //帶默認形參的構造函數(shù)和不帶形參的構造函數(shù)
//外部接口有設置學生信息,輸出學生信息,返回總分
char num[11];
int math, phi, phy, eng, che, com, sum;
public:
student();
student(char *n, int ma, int pi, int py, int eg, int ce, int cm);
void set_inf(char *n, int ma, int pi, int py, int eg, int ce, int cm);
int get_sum();
void get_inf();
};
//學生類公有成員函數(shù)的實現(xiàn)
student::student()
{
strcpy(num, "00000");
math=0; phi=0; phy=0; eng=0; che=0; com=0;
sum=math+phi+phy+eng+che+com;
}
void student::set_inf(char *n, int ma, int pi, int py, int eg, int ce, int cm)
{
strcpy(num, n);
math=ma; phi=pi; phy=py; eng=eg; che=ce; com=cm;
sum=math+phi+phy+eng+che+com;
}
int student::get_sum() { return sum;}
void student::get_inf()
{
cout << "├───┼───┼───┼───┼───┼───┼───┼───┼───┤" << endl;
cout << "│" << num << "\t│ "<<math << "\t│ "<<phi<< "\t│ "<<phy << "\t│ "<<eng
<< "\t│ "<<che << "\t│ "<<com << "\t│ "<<sum <<"\t│";
}
////////////////
//////////////////////////主函數(shù)////////////////////////////////////
void main()
{
const int temp_total=30;
int total=30;
int ma=0, pi=0, py=0, eg=0, ce=0, cm=0;
char n[20]="00000";
student s[temp_total];
//設置30個學生信息
s[1].set_inf("93001",89,81,70,80,77,81);
s[2].set_inf("93002",76,87,90,81,82,73);
s[3].set_inf("93003",60,55,75,81,74,67);
s[4].set_inf("93004",81,85,86,81,90,89);
s[5].set_inf("93005",89,97,91,88,85,94);
s[6].set_inf("93006",96,92,84,93,98,89);
s[7].set_inf("93007",56,60,64,68,70,59);
s[8].set_inf("93008",87,62,69,78,92,65);
s[9].set_inf("93009",78,65,74,80,81,74);
s[10].set_inf("93010",74,56,45,61,70,79);
s[11].set_inf("93011",70,0,56,67,71,80);
s[12].set_inf("93012",88,78,80,76,90,77);
s[13].set_inf("93013",89,81,70,80,77,81);
s[14].set_inf("93014",45,50,56,60,55,61);
s[15].set_inf("93015",92,98,91,98,93,100);
s[16].set_inf("93016",80,79,68,74,80,84);
s[17].set_inf("93017",56,80,75,80,84,81);
s[18].set_inf("93018",81,86,87,79,80,90);
s[19].set_inf("93019",79,65,45,80,76,72);
s[20].set_inf("93020",76,74,80,72,69,80);
s[21].set_inf("93021",72,81,82,84,89,78);
s[22].set_inf("93022",81,87,89,90,92,89);
s[23].set_inf("93023",69,80,78,60,65,89);
s[24].set_inf("93024",73,91,80,78,67,90);
s[25].set_inf("93025",65,10,72,55,70,60);
s[26].set_inf("93026",100,80,78,89,90,0);
s[27].set_inf("93027",75,86,88,80,83,70);
s[28].set_inf("93028",76,85,80,81,66,72);
s[29].set_inf("93029",74,82,70,79,82,71);
s[0].set_inf("93030",61,55,75,81,74,68);
int max, j;
for(int i=0; i<total; i++) //排序的實現(xiàn)
{
max=i; //max記錄總分最大者的在數(shù)組中的下標
for(j=i+1; j<total; j++)
{
if(s[j].get_sum()>s[max].get_sum())
max=j;
}
student temp;
temp=s[i]; //交換學生的所有數(shù)據(jù)??!
s[i]=s[max];
s[max]=temp;
}
//輸出
cout << " ***********學生成績排名*********** " << endl << endl;
cout << "┌───┬───┬───┬───┬───┬───┬───┬───┬───┐"<< endl;
cout << "│ 學號 │ 數(shù)學 │ 哲學 │ 物理 │ 外語 │ 化學 │計算機│ 總分 │ 名次 │"<<endl;
for(i=0; i<total; i++)
{
s[i].get_inf();
cout <<" "<<i+1 <<"\t│" << endl;//名次,必須+1
}
cout << "└───┴───┴───┴───┴───┴───┴───┴───┴───┘"<< endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -