1#include <iostream> 2#include <string.h> 3#include <stdio.h> 4using namespace std; 5class student 6{ 7 public: 8 char name[100]; 9 int number; 10 double English,Math,Computer; 11 void inputPublicGreat() 12 { 13 cout << "输入英语成绩:"; 14 cin >> English; 15 cout << "输入数学成绩:"; 16 cin >> Math; 17 cout << "输入编程成绩:"; 18 cin >> Computer; 19 } 20 void inputInformation() 21 { 22 cout <<"输入学号:"; 23 cin >> number; 24 cout <<"输入姓名:"; 25 cin >> name; 26 } 27 double calTotalGreat() 28 { 29 double Total=English+Math+Computer; 30 return Total; 31 } 32 double calAveGreat() 33 { 34 double Ave=(English+Math+Computer)/3.0; 35 return Ave; 36 } 37 void TPrint() 38 { 39 cout << endl; 40 cout << "学号:" << number << endl; 41 cout << "姓名:" << name << endl; 42 cout << "English:"<<English <<" Math:"<<Math <<" Computer:"<< Computer << endl; 43 cout <<"公共课总分成绩为:" <<calTotalGreat() << endl; 44 cout <<"公共课平均成绩为:"<<calAveGreat()<<endl; 45 } 46}; 47class Cstudent:public student 48{ 49 public: 50 double DB,C,CstuTotal; 51 void inputCstudentGreat() 52 { 53 cout << "输入数据库成绩:"; 54 cin >> DB; 55 cout << "输入C语言成绩:"; 56 cin >> C; 57 } 58 void outputCstudentGreat() 59 { 60 cout << "数据库:" <<DB <<" "<<"程序设计:" <<C <<endl; 61 } 62 void notice() 63 { 64 cout << "请录入计算机专业学生信息:"<< endl; 65 } 66 void calCstudentGreat() 67 { 68 CstuTotal=DB+C+calTotalGreat(); 69 } 70 void Print() 71 { 72 cout <<name << "的总成绩为:" << CstuTotal << endl; 73 } 74}; 75class Astudent:public student 76{ 77 public: 78 double Acc,Eco,AstuTotal; 79 void inputAstudentGreat() 80 { 81 cout << "输入会计学成绩:"; 82 cin >> Acc; 83 cout << "输入经济学成绩:"; 84 cin >> Eco; 85 } 86 void outputAstudentGreat() 87 { 88 cout << "会计学:" <<Acc <<" "<<"经济学:" <<Eco <<endl; 89 } 90 void notice() 91 { 92 cout << "请录入会计学专业学生信息:"<< endl; 93 } 94 void calAstudentGreat() 95 { 96 AstuTotal=Acc+Eco+calTotalGreat(); 97 } 98 void Print() 99 { 100 cout <<name <<"的总成绩为:" << AstuTotal << endl; 101 } 102}; 103class Hstudent:public student 104{ 105 public: 106 double OrgH,Hana,HstuTotal; 107 void inputHstudentGreat() 108 { 109 cout << "输入有机化学成绩:"; 110 cin >> OrgH; 111 cout << "输入化学分析成绩:"; 112 cin >> Hana; 113 } 114 void outputHstudentGreat() 115 { 116 cout << "有机化学:" <<OrgH <<" "<<"化学分析:" <<Hana <<endl; 117 } 118 void notice() 119 { 120 cout << "请录入化学专业学生信息:"<< endl; 121 } 122 void calHstudentGreat() 123 { 124 HstuTotal=OrgH+Hana+calTotalGreat(); 125 } 126 void Print() 127 { 128 cout << name<<"的总成绩为:" << HstuTotal << endl; 129 } 130}; 131int main() 132{ 133 int choice; 134 char flag; 135 while(1) 136 { 137 cout <<"请选择你要录入的学生专业:(1.计算机 2.会计学 3.化学):"; 138 cin >> choice; 139 switch(choice) 140 { 141 case 1: 142 { 143 Cstudent cstu; 144 cstu.notice(); 145 cstu.inputInformation(); 146 cstu.inputPublicGreat(); 147 cstu.inputCstudentGreat(); 148 cstu.calTotalGreat(); 149 cstu.calAveGreat(); 150 cstu.calCstudentGreat(); 151 cstu.TPrint(); 152 cstu.outputCstudentGreat(); 153 cstu.Print(); 154 cout << endl; 155 cout << "你还要再录入其他学生成绩吗?(Y/N):"; 156 cin >> flag; 157 if(flag=='N') goto label; 158 break; 159 } 160 case 2: 161 { 162 Astudent astu; 163 astu.notice(); 164 astu.inputInformation(); 165 astu.inputPublicGreat(); 166 astu.inputAstudentGreat(); 167 astu.calTotalGreat(); 168 astu.calAveGreat(); 169 astu.calAstudentGreat(); 170 astu.TPrint(); 171 astu.outputAstudentGreat(); 172 astu.Print(); 173 cout << endl; 174 cout << "你还要再录入其他学生成绩吗?(Y/N):"; 175 cin >> flag; 176 if(flag=='N') goto label; 177 break; 178 } 179 case 3: 180 { 181 Hstudent hstu; 182 hstu.notice(); 183 hstu.inputInformation(); 184 hstu.inputPublicGreat(); 185 hstu.inputHstudentGreat(); 186 hstu.calTotalGreat(); 187 hstu.calAveGreat(); 188 hstu.calHstudentGreat(); 189 hstu.TPrint(); 190 hstu.outputHstudentGreat(); 191 hstu.Print(); 192 cout << endl; 193 cout << "你还要再录入其他学生成绩吗?(Y/N):"; 194 cin >> flag; 195 if(flag=='N') goto label; 196 break; 197 } 198 } 199 } 200 label: 201 return 0; 202} 203