본문 바로가기

C++ 언어/연습문제

(34)
C++언어 연습문제34 [문제] 아래의 main 함수를 참고하여 클래스를 수정하라. 조건1) 문제33의 클래스를 기본으로 할 것 조건2) 상속을 사용하지 말 것 int main(void) { Police pman1(5, 3); pman1.Shot(); pman1.PutHandcuff(); Police pman2(0, 3); pman2.Shot(); pman2.PutHandcuff(); return 0; } [실행결과] BBANG! SNAP! Hut BBANG! SNAP! [코드] #include using namespace std; class Gun { private: int bullet; public: Gun(int bnum) :bullet(bnum) {} void Shot() { cout
C++언어 연습문제33 [문제] 아래 main 함수를 참고하여 Gun, Police 클래스를 설계하라. 조건) 상속을 이용할 것 int main(void) { Police pman(5, 3); pman.Shot(); pman.PutHandcuff(); return 0; } [실행결과] BBANG! SNAP! [코드] #include using namespace std; class Gun { private: int bullet; public: Gun(int bnum) :bullet(bnum) {} void Shot() { cout
C++언어 연습문제32 [문제] 아래의 실행결과와 main함수를 참고하여 Person class와 UnivStudent class를 정의하라. 조건1) UnivStudent 는 유도 클래스로, Person은 기초 클래스로 정의하라. 조건2) 동적 할당을 사용하라. int main(void) { UnivStudent ust1("Kim", "Mathematics"); ust1.WhoAreYou(); UnivStudent ust2("Yoon", "Physics"); ust2.WhoAreYou(); return 0; } [실행결과] My name is Kim My major is Mathematics My name is Hong My major is Physics [코드] #include using namespace std; clas..
C++언어 연습문제31 [문제] 아래의 실행결과와 main함수를 참고하여 Person class와 UnivStudent class를 정의하라. 조건) UnivStudent 는 유도 클래스로, Person은 기초 클래스로 정의하라. int main(void) { UnivStudent ust1("Lee", 22, "Computer eng."); ust1.WhoAreYou(); UnivStudent ust2("Yoon", 21, "Electronic eng."); ust2.WhoAreYou(); return 0; } [실행결과] My name is Lee I'm 22 years old My major is Computer eng. My name is Yoon I'm 21 years old My major is Electronic e..
C++언어 연습문제30 [문제] 아래의 실행결과가 나오도록 클래스와 main함수를 구성하라. 조건1) 정규직 직원에 대한 PermanentWorker 클래스를 정의할 것 조건2) 기능의 처리를 실제로 담당하는 EmployeeHandler 컨트롤 클래스를 정의하고 아래의 기능의 함수를 추가할 것 - 새로운 직원정보의 등록: AddEmployee - 모든 직원의 이번 달 급여정보 출력: ShowAllSalaryInfo - 이번 달 급여의 총액 출력: ShowTotalSalary [실행결과] name: KIM salary: 1000 name: LEE salay: 1500 name: JUN salay: 2000 salary sum: 4500 [코드] #include using namespace std; class PermanentWo..
C++ 언어 연습문제29 [문제] 아래의 코드에서 전역변수로 선언된 변수를 static변수로 변경하여라. #include using namespace std; int simObjCnt = 0; int cmxObjCnt = 0; class SoSimple { public: SoSimple() { simObjCnt++; cout
C++ 언어 연습문제28 [문제] 아래의 코드를 실행시키면 다음의 실행결과가 나타나면서 에러가 발생한다. 이름: Lee dong woo 나이: 29 이름: Lee dong woo 나이: 29 called destructor! 복사 생성자를 만들어서 에러를 없애고 아래의 실행결과가 나오도록 하라. 그리고 동적할당된 구조를 그림으로 그려라. #include #include using namespace std; class Person { private: char* name; int age; public: Person(const char* myname, int myage) { int len = strlen(myname) + 1; name = new char[len]; strcpy(name, myname); age = myage; } v..
C++ 언어 연습문제27 [문제] 아래 main문을 보고 클래스를 정의하라. int main(void) { Sosimple sim1(15, 30); cout