๐คํ๋ก๊ทธ๋๋ฐ ์ธ์ด
C++ ์ ๋ฆฌ - 26 (๋ถํ ์ปดํ์ผ,๊ธฐ์ต ์กด์ ์๊ฐ, ์ฌ์ฉ๋ฒ์, ๋งํฌ,์๋ ๋ณ์,์ ์ ๋ณ์, ์ ์ ์กด์ ์๊ฐ, ์ธ๋ถ ๋งํฌ,์ฌ์ฉ ๋ฒ์ ๊ฒฐ์ ์ฐ์ฐ์)
๋ฉ๋ชจ๋ฆฌ ๋ชจ๋ธ๊ณผ ์ด๋ฆ ๊ณต๊ฐ ๋ถํ ์ปดํ์ผ ์๋ณธ ํ๋ก๊ทธ๋จ์ ๋ค์๊ณผ ๊ฐ์ด ์ธ ๋ถ๋ถ์ผ๋ก ๋ถํ ํ ์ ์๋ค. 1. ๊ตฌ์กฐ์ฒด ์ ์ธ๊ณผ, ๊ทธ ๊ตฌ์กฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ ํจ์๋ค์ ์ํ์ด ๋ค์ด์๋ ํค๋ ํ์ผ 2. ๊ทธ ๊ตฌ์กฐ์ฒด์ ๊ด๋ จ๋ ํจ์๋ค์ ์ฝ๋๊ฐ ๋ค์ด์๋ ์์ค์ฝ๋ ํ์ผ 3. ๊ทธ ๊ตฌ์กฐ์ฒด์ ๊ด๋ จ๋ ํจ์๋ค์ ํธ์ถํ๋ ์ฝ๋๊ฐ ๋ค์ด์๋ ์์ค์ฝ๋ ํ์ผ ํํ ํค๋ ํ์ผ์๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒ๋ค์ ๋ฃ๋๋ค. 1. ํจ์ ์ํ 2. #define์ด๋ const๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ํ๋ ๊ธฐํธ ์์ 3. ๊ตฌ์กฐ์ฒด ์ ์ธ 4. ํด๋์ค ์ ์ธ 5. ํ ํ๋ฆฟ ์ ์ธ 6. ์ธ๋ผ์ธ ํจ์ ํ์ผ ์ด๋ฆ์ด ๊ดํธ๋ก ๋ฌถ์ฌ์์ผ๋ฉด, ์ปดํ์ผ๋ฌ๋ ํ์ค ํค๋ ํ์ผ๋ค์ด ๋ค์ด์๋ ํธ์คํธ ์์คํ ์ ํ์ผ ์์คํ ์์ญ์์ ๊ทธ๊ฒ์ ์ฐพ๋๋ค. ๊ทธ๋ฌ๋ ํฐ ๋ฐ์ดํ๋ก ๋ฌถ์ฌ์์ผ๋ฉด, ์ปดํ์ผ๋ฌ๋ ๋จผ์ ํ์ฌ ์์ ๋ํ ํ ๋ฆฌ๋ ์์ค..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 13 ํด๋์ค์ ์์ p.989~ 1๋ฒ~4๋ฒ
1๋ฒ //classic.h #ifndef CLASSIC_H_ #define CLASSIC_H_ class Cd { private: char performers[50]; char label[20]; int selections; double playtime; public: Cd(char* s1="no name", char* s2="no label", int n=0, double x=0.0); //Cd(const Cd& d); virtual ~Cd() {} virtual void Report() const; Cd& operator=(const Cd& d); }; class Classic :public Cd { private: char title[50]; public: Classic(char* s3 = "no ..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 12 ํด๋์ค์ ๋์ ๋ฉ๋ชจ๋ฆฌ ๋์ p.892~ 1๋ฒ~6๋ฒ
1๋ฒ //cow.h #ifndef COW_H_ #define COW_H_ class Cow { private: char name[20]; char* hobby; double weight; public: Cow(); Cow(const char* nm, const char* ho, double wt); Cow(const Cow& c); ~Cow(); Cow& operator=(const Cow& c); void ShowCow() const; }; #endif //cow.cpp #include #include"cow.h" Cow::Cow() { strcpy(name, "no name"); hobby = new char[1]; hobby[0] = '\0'; weight = 0.0; } Cow::Cow(const..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 11 ํด๋์ค์ ํ์ฉ p.787~ 1๋ฒ~7๋ฒ
1๋ฒ // randwalk.cpp -- Vector ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ค // vect.cpp ํ์ผ๊ณผ ํจ๊ป ์ปดํ์ผํ๋ค #include #include #include // rand(), srand()์ ์ํ #include // time()์ ์ํ #include "vect.h" int main() { using namespace std; using VECTOR::Vector; srand(time(0)); // ๋์ ๋ฐ์๊ธฐ์ ์จ๋ฅผ ๋ฟ๋ฆฐ๋ค double direction; Vector step; Vector result(0.0, 0.0); unsigned long steps = 0; double target; double dstep; ofstream write_randwalk; write_randwalk.ope..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 10 ๊ฐ์ฒด์ ํด๋์ค p.705~ 1๋ฒ~8๋ฒ
1๋ฒ //account.h #ifndef account_H_ #define account_H_ class BankAccount { private: char name[40]; char acctnum[25]; double balance; public: BankAccount(const char* client, const char* num, double bal = 0.0); void show(void) const; void deposit(double cash); void withdraw(double cash); }; #endif //account.cpp #include #include #include"account.h" BankAccount::BankAccount(const char* client, const ..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 09 ๋ฉ๋ชจ๋ฆฌ ๋ชจ๋ธ๊ณผ ์ด๋ฆ ๊ณต๊ฐ p.630~ 1๋ฒ~4๋ฒ
1๋ฒ //golf.cpp #include"golf.h" #include #include void setgolf(golf& g, const char* name, int hc) { strcpy(g.fullname, name); g.handicap = hc; } int setgolf(golf& g) { using std::cout; cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 08 ํจ์์ ํ์ฉ p.555~ 1๋ฒ~7๋ฒ
1๋ฒ #include using namespace std; void print(char* a, int n = 0); int main() { char a[50]; int n,count=0; for(;;) { cout n).get(); if (n == 0) { print(a); count++; } else for (int i = 0; i < count; i++) print(a, n); } return 0; } void print(char* a, int n) { cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 07 ํจ์-C++์ ํ๋ก๊ทธ๋๋ฐ ๋ชจ๋ p.462~ 7๋ฒ~10๋ฒ
7๋ฒ #include const int Max = 5; double * fill_array(double * a, double * b); void show_array(double* a, double* b); void revalue(double r, double* a, double* b); int main() { using namespace std; double properties[Max]; double * b = fill_array(properties, properties + Max); show_array(properties, b); if (properties != b) { cout > factor)) { cin.clear(); while (cin.get() != '\n') continue; cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 07 ํจ์-C++์ ํ๋ก๊ทธ๋๋ฐ ๋ชจ๋ p.461~ 1๋ฒ~6๋ฒ
1๋ฒ #include double aver(double x, double y); int main() { using namespace std; double x, y,z; for(;;) { cout > x >> y; if (x == 0 || y == 0) break; z = aver(x, y); cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 06 ๋ถ๊ธฐ ๊ตฌ๋ฌธ๊ณผ ๋ ผ๋ฆฌ ์ฐ์ฐ์ p.370~371 6๋ฒ~9๋ฒ
6๋ฒ #include struct donation_info { char name[20]; double donation; }; int main() { using namespace std; cout > n; donation_info * SPRI = new donation_info[n]; for (int i = 0; i name; cout name > (SPRI + i)->donation; } cout donation >= 10000) { cout name