題目要求如下:
----------------------------------------------------------------------------------------------------------------------------------------
代碼如下:
/*
* Copyright (c) 2013, 煙臺大學計算機學院
* All rights reserved.
* 作 者: 沈遠宏
* 完成日期:2014 年06月18日
* 版 本 號:v1.0
* 問題描述:Description
小平幫老師處理期末成績時遇到了問題。他需要計算每個同學的平均成績,並判斷他們是否通過了期末考試不及格成績(<60),若都通過才能pass,若沒通過要說明是哪幾科未通過。因此他需要兩個函數,一個求平均成績(不考慮小數),另一個判斷是否通過考試,通過輸出pass,否則輸出未通過的科目。請你們幫幫他!
期末包括Chinese,Math,English三門課程。
Input
輸入學號,並輸入三個個科目成績,三個科目名稱分別用Chinese,Math,English來表示
Output
輸出學號,並輸出與學號對應的平均成績,和掛科科目(全過輸出一個pass)。
每個輸出項佔一行,掛科科目每個也佔一行。
*/#include <iostream>
#include <cstring>
using namespace std;
class Student
{
private:
string no;
int chinese;
int math;
int english;
int ave;
public:
void get_inf()
{
cin>>no>>chinese>>math>>english;
}
int get_ave()
{
ave=(chinese+math+english)/3;
return ave;
}
void output_pass()
{
cout<<"student:"<<no<<endl;
cout<<get_ave()<<endl;
if(chinese>=60&&math>=60&&english>=60)
{
cout<<"pass"<<endl;
}
else
{
if(chinese<60)
cout<<"Chinese"<<endl;
if(math<60)
cout<<"Math"<<endl;
if(english<60)
cout<<"English"<<endl;
}
}
};
int main()
{
Student s1;
s1.get_inf();
s1.output_pass();
return 0;
}
運行結果:
OJ要求結果輸出例樣: