page 167: #include using namespace std ; int times(int) ; int main(void) { cout << times (2) << endl ; cin.get() ; return 0 ; } int times (int i) { return i * i ; } page 168: #include using namespace std ; int times (int) #include "exp.h" int main() { cout << times (2) << endl ; return 0 ; } int times (int i) { return i * i ; } page 169 //////////////////////////////////////// #include "exp.h" extern int x ; int main() { cout << x * times(2) << endl ; return 0 ; } //////////////////////////////////// int x = 3 ; int times (int i) { return (i * x) ; } ////////////////////////////// #include using namespace std ; int times (int) ; page 170 #include "exp.h" static int x = 4 ; int main() { cout << x * times(2) << endl ; return 0 ; static int x = 3 ; int times(int i) { return i * x ; } page 171 #include using namespace std ; class part { int i ; public: part(): i(0) { ;} part(int j): i(j) { ;} void display(void) { cout << i << endl ;} } ; int main(void) { part p1(3) ; p1.display() ; return 0 ; } page 172 #include using namespace std ; class part { int i ; public: part(): i(0) { ;} part(int j): i(j) { ;} void display(void) ; } ; #include "exp.h" int main(void) { part p1(3) ; p1.display() ; return 0 ; } #include "exp.h" void part::display(void) { cout << i << endl ;} page 173 #include using namespace std ; #define ED 1 #if defined(ED) #define JO 2 #else #define AL 3 #endif int main(void) { cout << ED << endl ; cout << JO << endl ; //cout << AL << endl; //causes an errror - saying AL not declared. return 0 ; } page 174 #include using namespace std ; #define ED 1 #undef ED #if defined(ED) #define JO 2 #else #define AL 3 #endif int main(void) { //cout << ED << endl ; //cout << JO << endl ; cout << AL << endl ; return 0 ; } #include "exp.h" #include "exp.h" int main(void) { part p1(3) ; p1.display() ; return 0 ; } page 175 #if !defined(EXP_H) #define EXP_H #include "exp.h" #endif int main(void) { part p1(3) ; p1.display() ; return 0 ; } #if !defined(EXP_H) #define EXP_H #include "exp.h" #endif #if !defined(EXP_H) #define EXP_H #include "exp.h" #endif int main(void) { part p1(3) ; p1.display() ; return 0 ; } page 176 namespace two { int alpha = 2 ; } #include using namespace std ; #include "exp.h" namespace one { int alpha = 1 ; } int main(void) { cout << one::alpha << endl ; cout << two::alpha << endl ; return 0 ; } using namespace two ; int main(void) { cout << one::alpha << endl ; cout << alpha << endl ; return 0 ; } page 177 typedef unsigned int unsit ; #include using namespace std ; #include "exp.h" unsit i = 1 ; int main(void) { cout << i << endl ; return 0 ; } page 178 #include using namespace std ; template void display(T n) { cout << n << endl ; } int main(void) { int i = 3 ; long l = 4L ; float f = 6.4F ; double d = 6.5 ; display(i) ; display(l) ; display(f) ; display(d) ; cin.get() ; return 0 ; } page 179 #include using namespace std ; class part { int a ; public: part():a(0) { ;} public: part(int b):a(b) { ;} void display(void) {cout << a << endl ;} } ; main() { int x = 2 ; part p1(x) ; p1.display() ; return 0 ; } page 180 #include using namespace std ; template class part { private: T a ; public: part():a(0) { ;} public: part(T b):a(b) { ;} void display(void) {cout << a << endl ;} } ; int main(void) { int x = 2 ; part p1(x) ; p1.display() ; float f = 2.3F ; part p2(f) ; p2.display() ; cin.get() ; return 0 ; } page 181 #include using namespace std ; template class part { T a ; private: public: part():a(0) { ;} public: part(T b):a(b) { ;} void display(void) ; } ; int main(void) { int x = 2 ; part p1(x) ; p1.display() ; float f = 2.3F ; part p2(f) ; p2.display() ; cin.get() ; return 0 ; } template void part::display(void) {cout << a << endl ;} //////////////////////////////////////////////////////////////////// #include using namespace std ; template class part { T a ; private: public: part():a(0) { ;} public: part(T b):a(b) { ;} T display(T) ; } ; int main(void) { int x = 2 ; part p1(x) ; p1.display(x) ; float f = 2.3F ; part p2(f) ; p2.display(f) ; return 0 ; } template T part::display(T n) {cout << n << endl ; return a; } /////////////////////////////////////////////////////////////////// page 182 #include #include using namespace std ; ///////////////////////// class Part { private: int arr[2] ; public: class TooBig { public: string sr ; TooBig(string or) {sr = or ;} } ; void init(int i) { if (i >= 2) {cout << i << endl; throw TooBig("init") ; } arr[i] = i ; } } ; ///////////////////////// int main() { try { Part p1 ; p1.init(2) ; } ///////////////////////// catch(Part::TooBig bg) {cout << bg.sr << endl ; cin.get() ;} return 0 ; } ///////////////////////// page 183 #include #include using namespace std ; int main(void) { vector v ; v.push_back(0) ; v.push_back(1) ; v.push_back(2) ; v.push_back(3) ; return 0 ; } page 184 #include #include using namespace std ; int main(void) { vector v ; v.push_back(1) ; v.push_back(2) ; v.push_back(3) ; v.push_back(4) ; v.push_back(5) ; v[0] = 6 ; v.insert(v.begin() ,7) ; v.erase(v.begin() + 1) ; return 0 ; } page 185 #include #include using namespace std ; int main(void) { int arr[4] = {1,2,3,4} ; vector v(arr,arr+4) ; vector::iterator it ; v.push_back(5) ; v[0] = 6 ; it = v.begin() ; v.insert(it,7) ; it = v.begin() ; v.erase(it + 1) ; return 0 ; } page 186 #include #include #include using namespace std ; int main(void) { int arr[4] = {2,1,4,3} ; vector v(arr,arr+4) ; vector::iterator it ; it= find(v.begin(),v.end(),4); sort(v.begin(),v.end()) ; return 0 ; } page 187 #include #include #include using namespace std ; int main(void) { void square(int ) ; int arr[4] = {1,2,3,4} ; vector v(arr,arr+4) ; vector::iterator it ; for_each(v.begin(),v.end(),square); for(it= v.begin();it !=v.end();it++) cout << *it << endl ; cin.get(); return 0 ; } void square(int i) { i = i * i ; } page 189 #include #include #include using namespace std ; int main(void) { string names[] = {"ed","jo","al"} ; string progs[] = {"C++","java","VB"}; map mapProgs ; for(int i = 0; i< 3 ; i++) mapProgs[names[i]] = progs[i] ; cout << mapProgs["ed"] << endl ; cin.get(); return 0 ; }