C++ Programming Ch.5 Exercise 12 Solution

Problem: 다음은 학과를 나타내는 Dept 클래스와 이를 활용하는 main()을 보여 준다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Dept { int size; // scores 배열의 크기 int* scores; // 동적 할당 받을 정수 배열의 주소 public: Dept(int size) { // 생성자 this->size = size; scores = new int[size]; } Dept(const Dept& dept); // 복사 생성자 ~Dept(); // 소멸자 int getSize() { return size; } void read(); // size 만큼 키보드에서 정수를 읽어 scores 배열에 저장 bool isOver60(int index); // index의 학생의 성적이 60보다 크면 true 리턴 }; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 int countPass(Dept dept) { // dept 학과에 60점 이상으로 통과하는 학생의 수 리턴 int count = 0; for (int i = 0; i < dept.getSize(); i++) { if (dept.isOver60(i)) count++; } return count; } int main() { Dept com(10); // 총 10명이 있는 학과 com com.read(); // 총 10명의 학생들의 성적을 키보드로부터 읽어 scores 배열에 저장 int n = countPass(com); // com 학과에 60점 이상으로 통과한 학생의 수를 리턴 cout << "60점 이상은 " << n << "명"; } (1) main()의 Execution Result가 다음과 같이 되도록 Dept 클래스에 멤버들을 모두 구현하고, 전체 프로그램을 완성하라. ...

March 5, 2020 · 5 min · Sobamemil