๐คํ๋ก๊ทธ๋๋ฐ ์ธ์ด/C++๊ธฐ์ดํ๋ฌ์ค ์ฐ์ต๋ฌธ์
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 18 ์๋ก์ด C++ ํ์ค๊ณผ์ ๋ง๋จ p.1540~ 1๋ฒ~4๋ฒ
1๋ฒ #include #include template T average_list(std::initializer_list il) { T sum = 0; for (auto it=il.begin(); it!=il.end(); it++) sum += *it; return sum / il.size(); } int main() { using namespace std; auto q = average_list({ 15.4, 10.7, 9.0 }); cout zcode; } Cpmv::Cpmv(Cpmv&& mv) :pi(mv.pi) { std::cout zcode; } if (obj.pi) { qcode += obj.pi->qcode; zcode += obj.pi->zcode; } Cpmv temp(qcode, zcod..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 17 ์ ๋ ฅ, ์ถ๋ ฅ, ํ์ผ p.1458~ 1๋ฒ~7๋ฒ
1๋ฒ #include #include #include int main() { using namespace std; char ch; int count = 0; while (cin.get(ch)) { if (ch != '$') count++; else { cin.putback(ch); break; } } cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 16 string ํด๋์ค์ ํ์ค ํ ํ๋ฆฟ ๋ผ์ด๋ธ๋ฌ๋ฆฌ p.1342~ 1๋ฒ~10๋ฒ
1๋ฒ #include #include bool palindrome(const std::string& s); int main() { std::string temp; std::cout
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 15 ํ๋ ๋,์์ธ,๊ธฐํ ์ฌํญ p.1206~ 1๋ฒ~4๋ฒ
1๋ฒ // tv.h -- Tv ํด๋์ค์ Remote ํด๋์ค #ifndef TV_H_ #define TV_H_ class Tv { public: friend class Remote; // Remote๋ Tv์ private ๋ถ๋ถ์ ์ ๊ทผํ ์ ์๋ค enum { Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD }; Tv(int s = Off, int mc = 125) : state(s), volume(5), maxchannel(mc), channel(2), mode(Cable), input(TV) {} void onoff() { state = (state == On) ? Off : On; } bool ison() ..
(C++๊ธฐ์ดํ๋ฌ์ค 6ํ ํ๋ก๊ทธ๋๋ฐ ์ฐ์ต ์ ๋ต,์๋ฃจ์ ) CHAPTER 14 C++ ์ฝ๋์ ์ฌํ์ฉ p.1103~ 1๋ฒ~5๋ฒ
1๋ฒ //winec.h #ifndef WINEC_H_ #define WINEC_H_ #include #include #include template class Pair { private: T1 year; T2 num; public: T1 first() const { return year; } T2 second() const { return num; } Pair() {} Pair(const T1& y, const T2& n) :year(y),num(n){} }; class Wine { private: typedef std::valarray ArrayInt; typedef Pair PairArray; PairArray p; std::string label; int year_n; public: Wine(con..
(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