A:簡單的學生信息處理程序實現
總時間限制: 1000ms 內存限制: 65536kB
描述
在一個學生信息處理程序中,要求實現一個代表學生的類,並且所有成員變量都應該是私有的。
(注:評測系統無法自動判斷變量是否私有。我們會在結束之後統一對作業進行檢查,請同學們嚴格按照題目要求完成,否則可能會影響作業成績。)
輸入
姓名,年齡,學號,第一學年平均成績,第二學年平均成績,第三學年平均成績,第四學年平均成績。
其中姓名、學號爲字符串,不含空格和逗號;年齡爲正整數;成績爲非負整數。
各部分內容之間均用單個英文逗號","隔開,無多餘空格。
輸出
一行,按順序輸出:姓名,年齡,學號,四年平均成績(向下取整)。
各部分內容之間均用單個英文逗號","隔開,無多餘空格。
樣例輸入
Tom,18,7817,80,80,90,70
樣例輸出
Tom,18,7817,80
源代碼:
#include <iostream>
#include<string>
#include<cstdio>
using namespace std;
class Student{
private:
int age,g1,g2,g3,g4;
int average;
char name[100],a,num[100];
public:
void input(){
cin.getline(name,100,',');
cin>>age;
a=getchar();
cin.getline(num,100,',');
cin>>g1>>a>>g2>>a>>g3>>a>>g4;
}
void ave(){
average=((g1+g2+g3+g4)/4);
}
void output(){
cout<<name<<a<<age<<a<<num<<a<<average;
}
};
int main(){
Student s;
s.input();
s.ave();
s.output();
}