C++ 123

[C++] 명품 C++ 프로그래밍 실습문제 6장 2번

[C++] 명품 C++ 프로그래밍 실습문제 6장 2번 [C++]명품 C++ programming 실습문제 6장 2번 명품 C++ 프로그래밍실습문제/연습문제 /C++ //2-1 #include #include using namespace std; class Person{ double weight; int id; string name; public: Person(){ this->id =1; this->name ="grace"; this->weight = 20.5; } Person(int id,string name){ this->id =id; this->name =name; weight = 20.5; } Person( int id , string name, double weight ){ this->id =id..

C++ 2023.01.07

[C++] 명품 C++ 프로그래밍 실습문제 6장 오픈챌린지/openchallenge

[C++]명품 C++ 프로그래밍 실습문제 openchallenge [C++]명품 C++ 프로그래밍 실습문제 오픈챌린지 명품 C++ 프로그래밍 실습문제/연습문제 /C++ #include #include #include #include using namespace std; class Person{ string name; public: Person(string sen){ name = sen; } string getName(){ return name; } }; class UpAndDownGame{ public: static int getRand(){ srand((unsigned)time(0)); int realnum; realnum = rand()%100; return realnum;//이넘버와 같은 사람이 게..

C++ 2023.01.06

명품 C++ 실습문제 5장 12,12-1번

12-1번 #include #include using namespace std; class Dept { int size; int* scores; public: Dept(int size) { this->size = size; scores = new int[size]; } //생성자 /*Dept(const Dept& dept) { this->size = dept.size; this -> scores = new int[size]; for (int i = 0; i < size; i++) { scores[i] = dept.scores[i]; } }*///복사생성자 //~Dept() { delete[] scores; }//소멸자 소멸자를 적지 않는다면 힙메모리를 터트릴게 없어서 상관이 없어진다 int getSize..

C++ 2023.01.05

명품 C++ 실습문제 5장 8번

#include using namespace std; class MyIntStack{ int *p; int size; int tos; public: MyIntStack(int size){//매개생성자 인라인함수로 넣기 this->p = new int[size]; this->size = size; this->tos = -1;}//인덱스 리턴//매개생성자 MyIntStack(const MyIntStack &s){//복사 생성자 int len = s.size; this->p = new int[len]; this->size = len; this->tos = s.tos; for (int i = 0; i p[i] = s.p[i]; }//복사 생성자 ~MyIntStack(){delete [] p;} bool push..

C++ 2023.01.05