머리가 굳어서 인가.. 예제가 이따구 밖에 안나오네..
어떻게 쉽게 하려고 해도 똥망진창이 되어가는 코드..
주석도 붙이려다가.. 결국은 안붙이게 되고..
어떻게 쉽게 하려고 해도 똥망진창이 되어가는 코드..
주석도 붙이려다가.. 결국은 안붙이게 되고..
#pragma once #include <string> using namespace std; class Human { private: string name; string gender; int age; public: Human( string aName, int aAge, string gender ); // Constructor ~Human( void ); // Destroyer string getName( ); // getting a Name int getAge( ); // getting a Age string getGender( ); // getting a Gender bool setName( string aName ); // change to Name void growOld( ); // get on in years void printName( ); // print to Name void printAge( ); // print to Age };
#include <iostream> #include "Human.h" // 생성자 Human::Human( string aName, int aAge, string gender ) { this->name = aName; this->age = aAge; this->gender = gender; } // 파괴자 Human::~Human( void ) { } bool Human::setName( string aName ) { if( aName.size() > 3 ) { cout << "이름은 2~3자만 가능합니다." << endl; return false; } this->name = aName; std::cout << "이름을 " << aName << "로 바꾸었습니다." << std::endl; return true; } void Human::growOld( ) { std::cout << "나이를 한살 더 먹었습니다. " << std::endl; this->age++; } void Human::printName( ) { std::cout << "Name : " << this->name << std::endl; } void Human::printAge( ) { std::cout << "Age : " << this->age << std::endl; } string Human::getName( ) { return this->name; } int Human::getAge( ) { return this->age; } string Human::getGender( ) { return this->gender; }
#pragma once #include <iostream> #include <string> #include "Human.h" using namespace std; class Student : private Human { public: Student( string name, int age, string gender, string num, int grade, string major ); ~Student( void ); int getStGrade( void ); string getStNumber( void ); string getStMajor( void ); void nextGrade( void ); void changeMajor( string major ); void printStudentInfo( void ); private: int stGrade; string stNum; string stMajor; };
#include "Student.h" Student::Student( string name, int age, string gender, string num, int grade, string major ) : Human(name, age, gender) { this->stNum = num; this->stGrade = grade; this->stMajor = major; } Student::~Student(void) { } string Student::getStNumber( void ) { return this->stNum; } int Student::getStGrade( void ) { return this->stGrade; } string Student::getStMajor( void ) { return this->stMajor; } void Student::nextGrade( void ) { if( this->stGrade >= 4 ) cout << this->getName() << "님은 졸업합니다" << endl; else cout << ++this->stGrade << "학년으로 진급하였습니다." << endl; } void Student::changeMajor( string major ) { this->stMajor = major; cout << major << "로 전과하였습니다." << endl; } void Student::printStudentInfo( void ) { cout << "* 이름 : " << this->getName() << endl; cout << "* 나이 : " << this->getAge() << endl; cout << "* 성별 : " << this->getGender() << endl; cout << "* 학번 : " << this->stNum << endl; cout << "* 학과 : " << this->stMajor << endl; cout << "* 학년 : " << this->stGrade << endl; }
#include <iostream> #include <string&> #include "Human.h" #include "Student.h" using namespace std; #define pause() getc(stdin) int main(void) { Human me(string("최건호"), 26, string("male")); cout << "My names is " << me.getName() << endl; cout << "My age is " << me.getAge() << endl; cout << "My Gender is " << me.getGender() << endl; me.setName(string("최모군")); me.growOld(); me.printName(); me.printAge(); cout << "다음 으로 진행하시려면 Enter을 눌러주세요"; pause(); Student students( string("최건호"), 26, string("male"), string("200311703"), 4, string("컴퓨터공학과")); /* cout << "My names is " << students.getName() << endl; cout << "My age is " << students.getAge() << endl; cout << "My Gender is " << students.getGender() << endl; students.setName("잘생김"); students.growOld(); */ students.printStudentInfo( ); students.nextGrade(); students.changeMajor(string("철학과")); students.printStudentInfo( ); pause(); return 0; }
Posted by LaLuna