[(개정판) 명품 C++ programming] 7장 실습 문제 ※문제 1 ~ 4까지 사용될 Book 클래스는 다음과 같다. class Book { string title; int price, pages; public: Book(string title = " ", int price = 0, int pages = 0) { this->title = title; this->price = price; this->pages = pages; } void show() { cout C-C++/명품 C++ Programming 2023.01.06
[(개정판) 명품 C++ programming] 6장 실습 문제 1. add() 함수를 호출하는 main()함수는 다음과 같다. . . 1-1. add() 함수를 중복 작성하고 프로그램을 완성하라. [소스 코드] #include using namespace std; int add(int x[], int y) { int sum = 0; for (int i = 0; i < y; i++) { sum += x[i]; } return sum; } int add(int x[], int y, int z[]) { int sum = 0; for (int i = 0; i < y; i++) { sum += x[i] + z[i]; } return sum; } int main() { int a[] = { 1, 2, 3, 4, 5 }; int b[] = { 6, 7, 8, 9, 10 }; i.. C-C++/명품 C++ Programming 2023.01.06
[백준] C++, JAVA, C# / 1001번 [C++ 소스 코드] #include using namespace std; int main() { int a{}, b{}; cin >> a >> b; cout ALGORITHM/BAEKJOON 2023.01.06
[(개정판) 명품 C++ programming] 5장 실습 문제 1.두 개의 Circle 객체를 교환하는 swap() 함수를 '참조에 의한 호출'이 되도록 작성하고 호출하는 프로그램을 작성하라. [결과] [소스 코드] #include using namespace std; class Circle { int radius; public: Circle(); Circle(int radius) { this->radius = radius; } int getRadius() { return radius; } void setRadius(int radius) { this->radius = radius; } void swap(Circle &a, Circle &b); }; void Circle::swap(Circle& a, Circle& b) { int swap; swap = a.getRa.. C-C++/명품 C++ Programming 2023.01.06
[백준] C++, JAVA, C# / 1000번 [C++ 소스 코드] #include using namespace std; int main() { int a{}, b{}; cin >> a >> b; cout ALGORITHM/BAEKJOON 2023.01.05
[(개정판) 명품 C++ programming] 4장 실습 문제 1. 다음은 색의 3요소인 red, green, blue로 색을 추상화한 Color 클래스를 선언하고 활용하는 코드이다. 빈칸을 채워라. red, green, blue는 0~255의 값만 가진다. [결과] [소스 코드] #include using namespace std; class Color { int red, green, blue; public: Color() { red = green = blue = 0; } Color(int r, int g, int b) { red = r; green = g; blue = b; } void setColor(int r, int g, int b) { red = r; green = g; blue = b; } void show() { cout C-C++/명품 C++ Programming 2023.01.05
[(개정판) 명품 C++ programming] 3장 실습 문제 1. main()의 실행 결과가 다음과 같도록 Tower 클래스를 작성하여라. [main()] #include using namespace std; int main() { Tower myTower; Tower seoulTower(100); cout C-C++/명품 C++ Programming 2023.01.05
[(개정판) 명품 C++ programming] 2장 실습 문제 1. cout과 e; float max = a; if (max secondPass; if (strcmp(firstPass, secondPass) == 0) cout > "; cin >> order >> amount; //switch 문 사용도 적합. 또한 string 외에 strcmp()으로 대체 가능. if (order == "에스프레소") { price = 2000 * amount; total += price; } else if (order == "아메리카노") { price = 2300 * amount; total +.. C-C++/명품 C++ Programming 2023.01.04