Student.h
#include <iostream> #include <string> using namespace std; class Student { protected: string name; //이름 string id; //학번 string major; //전공 unsigned int grade; //학년 unsigned int credit;//학점 public: Student(); ~Student(); }; Student::Student() { /* Do nothing */ } Student::~Student() { /* Do nothing */ }graduate.h
class Graduate:private Student { private: string assistant; //조교 float scholarship; // 장학금 public: Graduate(string s_name, string s_id, string s_major, unsigned int i_grade, unsigned int i_credit, string s_assistant, float f_scholarship); ~Graduate(); void print(void); }; Graduate::Graduate(string s_name, string s_id, string s_major, unsigned int i_grade, unsigned int i_credit, string s_assistant, float f_scholarship) { name = s_name; id = s_id; major = s_major; grade = i_grade; credit = i_credit; assistant = s_assistant; scholarship = f_scholarship; } Graduate::~Graduate() { /* Do nothing */ } void Graduate::print(void) { cout << "이름" << " : " << name << "\n"; cout << "학번" << " : " << id << "\n"; cout << "전공" << " : " << major << "\n"; cout << "학년" << " : " << grade << "\n"; cout << "이수학점" << " : " << credit << "\n"; cout << "조교유형" << " : " << assistant << "\n"; cout << "장학금비율" << " : " << scholarship << "\n"; }UnderGraduate.h
class UnderGraduate:private Student { private: string circle; //동아리 public: UnderGraduate(string s_name, string s_id, string s_major, unsigned int i_grade, unsigned int i_credit, string s_circle); ~UnderGraduate(); void print(void); }; UnderGraduate::UnderGraduate(string s_name, string s_id, string s_major, unsigned int i_grade, unsigned int i_credit, string s_circle) { name = s_name; id = s_id; major = s_major; grade = i_grade; credit = i_credit; circle = s_circle; } UnderGraduate::~UnderGraduate() { /* Do nothing */ } void UnderGraduate::print(void) { cout << "이름" << " : " << name << "\n"; cout << "학번" << " : " << id << "\n"; cout << "전공" << " : " << major << "\n"; cout << "학년" << " : " << grade << "\n"; cout << "이수학점" << " : " << credit << "\n"; cout << "동아리" << " : " << circle << "\n"; }Main.cpp
#include "student.h" #include "under_graduate.h" #include "graduate.h" int main() { Graduate g("홍길동","20051111","컴퓨터공학과",4, 140,"연구조교", 0.5); UnderGraduate u("하길동","20011111","컴퓨터공학과",2, 80,"Visaul C++"); g.print(); cout<<"-------------------------"<<endl; u.print(); return 0; }PS. VS2010 문제인지, 오랬만에 해서 뭔가 헛갈리는 건지 모르겠지만... Include 중복 문제가 있어서 이 코드는 좀 우습게 되었습니다. 참고만 하세요.
'Studies > C++ Espresso' 카테고리의 다른 글
9장 Programming 1. 은행계좌 (0) | 2011.12.13 |
---|---|
Chapter 8 LAB solution (4) | 2011.12.11 |
[Review] Chapter 01. p.14 ~ 15 Name Space 와 변수 (0) | 2011.09.06 |
[Review] Chapter 01. p.06 - 객체지향방법 (Object-oriented approach)의 목적 (0) | 2011.09.06 |
뭐부터 할까? (4) | 2011.09.06 |