💡 글 작성자는 vscode를 활용하여 Python을 작성하고있습니다.
해당글에는 QList (QT)를 활용하였습니다.
만약 C++로만 하는 경우에는 vector로 변경하면 됩니다.
#include <iostream>
#include "Student.h"
#include "Subject.h"
#include "School.h"
using namespace std;
int main()
{
School *sch = new School("대학교");
Student *donggyu = new Student("동규");
Student *mansu = new Student("동글");
donggyu->subList->append(new Subject("국어", 100));
donggyu->subList->append(new Subject("수학", 100));
donggyu->subList->append(new Subject("영어", 100));
mansu->subList->append(new Subject("국어", 100));
mansu->subList->append(new Subject("수학", 100));
mansu->subList->append(new Subject("영어", 100));
sch->schlist->append(donggyu);
sch->schlist->append(mansu);
cout << "학교: " << sch->getName() << endl;
cout << "학생1: " << sch->schlist->at(0)->getName() << endl;
cout << "과목: " << donggyu->subList->at(0)->getName() << " / " << donggyu->subList->at(0)->getNumber() << endl;
cout << "과목: " << donggyu->subList->at(1)->getName() << " / " << donggyu->subList->at(1)->getNumber() << endl;
cout << "과목: " << donggyu->subList->at(2)->getName() << " / " << donggyu->subList->at(2)->getNumber() << endl;
cout << "=====================================\n";
cout << "학생2: " << sch->schlist->at(1)->getName() << endl;
cout << "과목: " << mansu->subList->at(0)->getName() << " / " << mansu->subList->at(0)->getNumber() << endl;
cout << "과목: " << mansu->subList->at(1)->getName() << " / " << mansu->subList->at(1)->getNumber() << endl;
cout << "과목: " << mansu->subList->at(2)->getName() << " / " << mansu->subList->at(2)->getNumber() << endl;
}
#ifndef SCHOOL_H
#define SCHOOL_H
#include <iostream>
#include <QList>
#include "Student.h"
#include "Subject.h"
#include <QString>
#include <QDebug>
using namespace std;
class School {
public:
School(string name);
~School();
QList<Student*> *schlist;
string getName();
void printInfo()
{
//cout << "학생1: " << schlist->at(0)->getName() << endl;
//cout << "학생2: " << schlist->at(1)->getName() << endl;
}
private:
string m_name;
};
#endif
#include "School.h"
School::School(string name)
{
m_name = name;
schlist = new QList<Student*>();
}
School::~School()
{
}
string School::getName()
{
return m_name;
}
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <QList>
#include "Subject.h"
using namespace std;
class Student {
public:
Student(string name);
~Student();
QList<Subject*> *subList;
string getName();
private:
string m_name;
};
#endif
#include "Student.h"
Student::Student(string name)
{
m_name = name;
subList = new QList<Subject*>();
}
Student::~Student()
{
}
string Student::getName()
{
return m_name;
}
#ifndef SUBJECT_H
#define SUBJECT_H
#include <iostream>
using namespace std;
class Subject {
public:
Subject(string name, int score);
~ Subject();
string getName();
int getNumber();
private:
string m_name;
int m_score;
};
#endif
#include "Subject.h"
Subject::Subject(string name, int score)
{
m_name = name;
m_score = score;
}
Subject::~Subject()
{
}
string Subject::getName()
{
return m_name;
}
int Subject::getNumber()
{
return m_score;
}
[C언어|C++] C++만들면서 배우기03 / 만들면서 배우는 C++ 구구단 (0) | 2021.07.19 |
---|---|
[C언어|C++] C++만들면서 배우기02 / 만들면서 배우는 C++ 성적 변환 만들기 (0) | 2021.07.19 |