8.24.2017

08.24 C++

#include <iostream>
#include <string>

using namespace std;

class Human{
public:
        string name;
        int age;
public:
        Human(){
                cout << "이름과 나이를 입력하시오.\n";
                cin >> name;
                cin >> age;
        }
        string returnName() {
                return name;
        }
        void print() {
                cout << "이름은 : " << name << "나이는 : " << age << endl;
        }
};

class Student public Human {
        int korean, math, english;
public:
        void s_input() {
                cout << "학생의 국어, 수학, 영어 점수를 입력하시오." << endl;
                cin >> korean >> math >> english;
        }
        void printStudent(){
                print();
                cout << "국어 점수 : " << korean << ", 수학 점수 : " << math << ", 영어 점수 : " << english << endl;
        }
};

class Teacher : public Human {
        Student* s[3];
        int index;
public:
        Teacher() {
                index = 0;
        }
        void addStudent(Student* p) {
                if (index > 2) {
                        cout << "학생 추가 불가" << endl;
                        return;
                }
                s[index] = p;
                index++;

        void printTeacher(){
                print();
                for (int i = 0; i < index; i++)
                        s[i]->printStudent();
         }
};

void main() {
        Student* s[10];
        Teacher* t[3];

        string name;
        int input = 0, i = 0, j = 0;
        while (input != 6) {
                cout << "[menu]\n1.학생추가 2.선생님추가 3.학생출력 4.선생님정보출력 5. 선생님의 학생 추가 6.종료" << endl;
        cin >> input;
                if (input == 1) {
                        s[i] = new Student();
                        s[i] -> s_input();
                        i++;
                }
                else if (input == 2) {
                        cout << "관리할 학생의 이름을 입력해주세요." << endl;
                        cin >> name;
                        for (int k = 0; k < i; k++) {
                                if (name == s[k]->returnName()) { // (*s[k]).returnName()
                                        t[j] = new Teacher();
                                        t[j]->addStudent(s[k]);
                                        j++;
                                        break;
                                }
                        }
                }
                else if (input == 3) {
                        for (int p = 0; p < i; p++) {
                                s[p]->printStudent();
                        }
                }
                else if (input == 4) {
                        //선생님의 이름, 나이, 학생명단출력
                        for (int q = 0; q < j; q++) {
                                t[q]->printTeacher();
                        }
                }
                else if (input == 5) {
                        cout << "어느 선생님을 바꾸실건가요?" << endl;
                        cin >> name;
                        for (int u = 0; u < j; u++) {
                                if (name == t[u]->returnName()) {
                                        cout << "학생 이름 입력해주세요." << endl;
                                        cin >> name;
                                        for (int k = 0; k < i; k++){
                                                if (name == s[k]->returnName())
                                                t[u]->addStudent(s[k]);
                                        }
                                }
                        }
                }
        }
}

===========================================================================================

#include <iostream>
#include <string>

using namespace std;

class Score {
        int kor, math, eng;
        string name;
public:
        Score(int a, int b, int c, string d) {
                kor = 0;
                math = 0;
                eng = 0;
                name = d;
        }
        void change_value() (int p, int q, int r) {
                kor = p;
                math = q;
                eng = r;
        }
        void change_value(string a) {
                name = a;
        }
        void printOut() {
                cout << "국어 점수는 : " << kor << "수학 점수는 : " << math << "영어 점수는 : " << eng << "\n이름은 : " << name << endl;
        }
};

void main(){
        int input = 0, score1, score2, score3;
        string name;
        Score s(12, 13, 14, "점수");
        while (input != 4) {
                cout << "[menu]\n1.점수 변경 2.이름변경 3.모두 출력 4.종료" << endl;
                cin >> input;
                if (input == 1) {
                        cout << "변경할 점수를 입력해주세요." << endl;
                        cin >> score1 >> score2 >> score3;
                        s.change_value(score1, score2, score3);
                }
                else if (input == 2) {
                        cout << "변경할 이름을 입력해주세요." << endl;
                        cin >> name;
                        s.change_value(name);
                }
                else if (input == 3) {
                        s.printOut();
                }
        }
}

===========================================================================================

#include <iostream>
#include <string>

using namespace std;

class hamburger {
protected :
        string name;
        int price, number;
public:
        /*
        hamburger(string name, int price, int number) {
                this->name = name;
                this->price = price;
                this->number = number;
        }
        */
        void show_info() {
                cout << name << price << number;
        }
};

class Set_menu :public hamburger{

public:
        Set_menu(string name, int price, int number)// : hamburger(name, price, number) {
                this->name = name;
                this->price = price;
                this->number = number;
        }
        // overriding
        void show_info() {
                cout << name << price - 500 << number;
        }
};

void main() {
        Set_menu s1("불고기", 2000, 5);
        s1.show_info();
}

댓글 없음:

댓글 쓰기