3-5 學生成績統計
阿新 • • 發佈:2019-02-12
Input the messages of five students(StudentID Name Math English Computer ) StuID Name Math Eng Com Total Average 1001 Andy 89 90 93 272 90.7 1002 Mary 93 95 98 286 95.3 1003 Luis 90 85 98 273 91.0 1004 Sam 91 95 98 284 94.7
1005 Lily 87 98 99 284 94.7
#include<iostream> #include<cstdio> #include<cstring> using namespace std; class student { private: int n,m,e,c; char name[11]; public: int sum(); double average(); void input(); void output(); }; int student :: sum() { return (m + e + c); } double student :: average() { return ((m + e + c) / 3.0); } void student :: input() { cin>>n>>name>>m>>e>>c; } void student :: output() { cout<<n<<'\t'<<name<<'\t'<<m<<'\t'<<e<<'\t'<<c<<'\t'<<sum()<<'\t'; printf("%.1lf\n",average()); } int main() { int i; student s[5]; for(i = 0;i < 5;i++) s[i].input(); cout<<"Input the messages of five students(StudentID Name Math English Computer )"<<endl; cout<<endl; cout<<"StuID"<<'\t'<<"Name"<<'\t'<<"Math"<<'\t'<<"Eng"<<'\t'<<"Com"<<'\t'<<"Total"<<'\t'<<"Average"<<endl; for(i = 0;i < 5;i++) s[i].output(); return 0; }