#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Name {
string name;
public:
Name() {
}
Name(string name) {
this->name = name;
}
void setName(string name) {
this->name = name;
}
string getName() {
return name;
}
};
class Subject {
int score;
public :
void setScore(int score) {
this->score = score;
}
int getScore() {
return score;
}
};
//공통적인기능을 하기때문에 집어넣음
class ScoMag {
Name name;
Subject kor;
Subject eng;
Subject mat;
int total;
float avg;
public:
void setName(string name) {
this->name.setName(name);
}
void setKor(int score) {
kor.setScore(score);
}
void setEng(int score) {
eng.setScore(score);
}
void setMat(int score) {
mat.setScore(score);
}
void setTotal(int total) {
this->total = total;
}
void setAvg(float avg) {
this->avg = avg;
}
string getName() {
return name.getName();
}
int getKor() {
return kor.getScore();
}
int getEng() {
return eng.getScore();
}
int getMat() {
return mat.getScore();
}
int getTotal() {
total = kor.getScore() + eng.getScore() + mat.getScore();
return total;
}
float getAvg() {
return getTotal() / 3.f;
}
};
void main() {
int num=0;
string name;
int kor, eng, mat;
cout << "몇 명할래" << endl;
cin >> num;
ScoMag *scomag = new ScoMag[num];
for (int i = 0; i < num; i++) {
cout << "이름을 입력하세요" << endl;
cin >> name; //메인에있는 변수에 줘야하지
scomag[i].setName(name); //그리고 호출하고 name을 줘야함
cout << "국어성적을 입력하세요" << endl;
cin >> kor;
scomag[i].setKor(kor);
cout << "영어성적을 입력하세요" << endl;
cin >> eng;
scomag[i].setEng(eng);
cout << "수학성적을 입력하세요" << endl;
cin >> mat;
scomag[i].setMat(mat);
}
cout << setw(5) << "이름\t국어\t영어\t수학\t총점\t평균\t" << endl;
for (int i = 0; i < num; i++) {
cout << scomag[i].getName()<<"\t" << scomag[i].getKor() << "\t" << scomag[i].getEng()
<< "\t" << scomag[i].getMat() << "\t" << scomag[i].getTotal() << "\t" << scomag[i].getAvg() <<endl;
}
}
'C++' 카테고리의 다른 글
String 클래스 구조 (0) | 2018.03.15 |
---|---|
동적바인딩을 이용한 Stack, Queue 구현 (0) | 2018.03.14 |
DAY1 (0) | 2018.03.06 |