본문 바로가기

언어/C++

4장 3번 - 문장입력하고 부분 문자 바꾸기 #include #include #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { string str; srand( (unsigned)time(0) ); string alpa[26]={"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; int cstr; int calp.. 더보기
4장 2번 - 가장 큰 수 찾기 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Sample{ private: int *a; int num=10; public: Sample(int num){ a=new int[num]; } ~Sample(){ delete [] a; } void read(){ for(int i=0; i> a[i]; } } void write(){ for(int i=0; i 더보기
up & down 게임 만들기 ! #include #include #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Player{ private : string name[2]; int idx; public : Player(){name[0]="옥돌이"; name[1]="돌딸기"; idx=-1;} string getName(){ idx++; if(idx==2){ idx=0; return name[idx]; } else{ return name[idx]; } } }; class UpAndDownGame{ private: static in.. 더보기
끝말잇기 게임 만들기 ! class Player(){ private : int number; int idx; string *name; public : Player(int n); ~Player() {delete [] name;} string getName(); }; Player :: Player(int n){ number =n; idx=-1; name=new string[number]; fflush(stdin); for(int i=0; i 더보기
겜블링 게임 만들기 ! class Player{ private : string name[2]; int i; public: Player() {i=0;} void setName(string name){name[i]=name; i++;} string getName (){ if(i>=2){ i=0; return name[i]; } else{ return name[i]; } i++; } }; class GamblingGame{ private : int num[3]; public : GamblingGame() {srand(unsigned) tme (0));} void Game(); }; void GamblingGame :: Game(){ cout 더보기
4단원 예제문제 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ //원의 개수를 입력받고 circle 배열을 동적 생성하라 // 반지름의 값을 입력 받아 circle 배열에 저장하고 // 면적이 100에서 200사이인 원의 개수를 출력하라 class Circle{ int radius; public: Circle(); ~Circle(){ } void setRadius(int r){ radius=r; } double getArea(){ return 3.14*radius*radius; } }; Circle :: Circle(){ radius=.. 더보기
5단원 실습문제 (참조, 복사생성자 ) //6번 #include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; class MyIntStack { int *p; int size; int tos; public : MyIntStack(); MyIntStack(int size){ tos=-1; p = new int[size]; this->size = size; } MyIntStack(MyIntStack& s); ~MyIntStack(){ delete [] p; } bool push(int n); bool pop(int &n); }; bool MyIntStack::p.. 더보기
복사생성자 #include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; class Person{ char *name; int id; public : Person(int id,char*name); Person(Person& person); ~Person(); void changeName(char *name); void show(){cout id=person.id; int len=strlen(person.name); this->name=new char[len+1]; strcpy(this->name,person.name); coutn.. 더보기