본문 바로가기
프로그램/C++ 1000제

C++ 129제] 어서와! C++은 처음이지! CHAPTER 11. PROGRAMMING EXERCISE 4. p476

by 건티 2024. 12. 9.
728x90

출처 : 반크_반크 20년 백서

 

참고풀이]

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;

class Person {
   string name;
   string address;
   string tel;
public:
   //생성자
   Person(string n, string add, string t) :name(n), address(add), tel(t) {}
   //접근자
   string getName() { return name; }
   string getAddress() { return address; }
   string getTel() { return tel; }
   //설정자
   void setName(string n) { name = n; }
   void setAddress(string add) { address = add; }
   void setTel(string t) { tel = t; }
   //출력함수
   void Print()
   {
      cout << "이   름 : " << getName() << endl;
      cout << "주   소 : " << getAddress() << endl;
      cout << "전화번호: " << getTel() << endl;
   }
};

class Customer :public Person {
   string id;
   int mileage;
public:
   //생성자
   Customer(string n, string a, string t, string d, int m) :

                    Person(n, a, t), id(d), mileage(m) {}
   //접근자
   string getId() { return id; }
   int getMileage() { return mileage; }
   //설정자
   void setId(string d) { id = d; }
   void setMileage(int m) { mileage = m; }
   //출력함수 재정의
   void Print()
   {
      cout << "이   름 : " << getName() << endl;
      cout << "주   소 : " << getAddress() << endl;
      cout << "전화번호: " << getTel() << endl;
      cout << "아 이 디: " << getId() << endl;
      cout << "마일리지: " << getMileage() << endl;
   }
};

int main()
{
   Customer c1("김철수", "서울시 종로구", "010-1111-2222", "1", 1000);

   c1.Print();

   return 0;
}

 

참고풀이 결과]

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 가을

 

반응형

댓글