C++

increase_up · updated April 25, 2025
#include <iostream>
using namespace std;

class Person {
public :
    int age;
    char* name;
};

class Student : public Person {
public :
    char* major;
    void NewStudent() {
        char _name[10];
        char _major[10];
        cout << "[Add new student]" << endl
            << "- name :";
        cin >> _name;
        name = _name;
        cout <<"- major :";
        major = _major;
        cout <<"- age :";
        cin >> age;
    }
};

class MainMenu{
private:
    int sel;
public :
    int IssueMenu() {
        cout << "---------------<MainMenu>---------------"
            << endl <<"1. Add new student" << endl
            << "2. Show all student" << endl << endl
            << "0. Quit" << endl <<
            "----------------------------------------"<< endl
            << "Menu >>";
        cin >> sel;
        return sel;
    }  
};

class StudentManager {
private :
    int index;
    Student* SList[50];
public :
    bool AddStudent(Student* sp) {
        SList[index] = sp;
        index++;
        return true;
    }
    void ShowAllStudent(){
        for (int i = 0; i <= index; i++) {
            cout << SList[i]->name  <<"₩t"
                << SList[i]->age << "₩t" 
                << SList[i]->major << endl;
        }
    }
};

int main (void) {
    MainMenu mu;
    Student st; 
    cout << mu.IssueMenu() << endl;
    st.NewStudent();
    cout << st.name << endl <<st.age << 
        endl << st.major ;
}
Output

Comments

Please sign up or log in to contribute to the discussion.