C++ Programming Ch.6 Exercise 2 Solution

Problem: Person 클래스의 객체를 생성하는 main() 함수는 다음과 같다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Person { int id; double weight; string name; public: void show() { cout << id << ' ' << weight << ' ' << name << endl; } }; int main() { Person grace, ashley(2, "Ashley"), helen(3, "Helen", 32.5); grace.show(); ashley.show(); helen.show(); } (1) 생성자를 중복 작성하고 프로그램을 완성하라. ...

March 5, 2020 · 2 min · Sobamemil

C++ Programming Ch.3 Exercise 1 Solution

Problem: 아래 main()의 Execution Result가 다음과 같도록 Tower 클래스를 작성하라. 1 2 3 4 5 6 7 8 9 #include using namespace std; int main() { Tower myTower; // 1 미터 Tower seoulTower(100); // 100 미터 cout << "높이는 " << myTower.getHeight() << "미터" << endl; cout << "높이는 " << seoulTower.getHeight() << "미터" << endl; } Objective & Hints: 2개의 생성자와 여러 멤버를 가진 클래스 만들기 ...

March 2, 2020 · 1 min · Sobamemil

C++ Programming Ch.2 Exercise 12 Solution

Problem: 다음 C 프로그램을 C++ 프로그램으로 수정하여 실행하라. 이 프로그램의 Execution Result는 Exercise Problem 11과 같다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <stdio.h> int sum(); int main() { int n=0; printf("끝 수를 입력하세요>>"); scanf("%d", &n); printf("1에서 %d까지의 합은 %d 입니다.\n", n, sum(1,n)); return 0; } int sum(int a, int b) { int k, res=0; for(k=a; k<=b; k++){ res += k; } return res; } 2020/02/28 - [C++/명품 C++ programming] - 명품 C++ programming Exercise Problem 2장 11번 ...

February 28, 2020 · 2 min · Sobamemil