#define _CRT_SECURE_NO_DEPRECATE 1 #define _CRT_NONSTDC_NO_DEPRECATE 1 page 59 #include using namespace std ; int main() { int age[4]={1,2,3,4} ; cout << age[1] << endl ; cin.get(); return 0 ; } page 61 #include using namespace std; int main() { int age[2][4]={{1,2,3,4},{5,6,7,8}} ; cout << age[0][1] ; cin.get(); return 0 ; } page 62 #include using namespace std; void dodo(int []) ; int main() { int age[4]= {1,2,3,4} ; cout << age[2] << endl ; dodo(age) ; cout << age[2] << endl ; cin.get(); return 0 ; } void dodo(int ag[]) { ag[2] = 7 ; } page 63 #include using namespace std ; struct part { int i ; char s ; } ; int main() { part prt[2] ; prt[0].i= 1 ; prt[0].s='A' ; prt[1].i= 2 ; prt[1].s='B' ; cin.get(); return 0 ; } page 64 #include using namespace std; class part { private: int i ; char s ; public: void init(int j , char t) { i = j ; s = t ; } } ; int main() { part prt[2] ; prt[0].init(1,'A') ; prt[1].init(2,'B') ; cin.get(); return 0 ; } page 65 #include using namespace std ; int main() { float var = 2330000 ; cout << var << endl ; cin.get(); return 0 ; } #include #include using namespace std; int main() { float var = 2330000 ; cout << setiosflags(ios::fixed) ; cout << var << endl ; cin.get(); return 0 ; } #include #include using namespace std ; int main() { float var = 2330000 ; cout << setiosflags(ios::fixed) ; cout << setprecision(2) ; cout << var << endl ; cin.get(); return 0 ; } #include #include using namespace std ; int main() { float var = 2330000 ; cout << setprecision(2) ; cout << var << endl ; cin.get(); return 0 ; } page 66 #include // for cout #include // for srand and rand() #include // for time #include // for setw using namespace std ; int main() { srand(unsigned(time(NULL)) ) ; for (int j=1; j<=12; j++) cout << setw(10) << rand() ; cout << endl ; cin.get(); return 0 ; } page 67 #include // for cout #include // for setw using namespace std ; int main() { for (int j=0;j<26;j++) cout << j / 13 << setw(4) << (j % 13) << endl ; return 0 ; } #include using namespace std ; int main() { for (int i=0; i<32; i++) cout << static_cast(i) << endl; cin.get(); return 0 ; } page 68 #include using namespace std; int main() { char str[]="Farewell" ; cout << str << endl ; cin.get(); return 0 ; } page 69 #include using namespace std; int main() { char str[]= {'F','a','r','e','w','e','l','l','\0'}; cout << str << endl ; cin.get(); return 0 ; } page 70 #include using namespace std; int main() { char st1[]="Farewell" ; char st2[20] ; for (int i=0; i<9; i++) st2[i] = st1[i] ; cout << st2 << endl ; cin.get(); return 0 ; } page 70 #include #include using namespace std ; int main() { char st1[]="Farewell" ; cout << strlen(st1) << endl ; cin.get(); return 0 ; } page 71 #include #include using namespace std ; int main() { char st1[]="Farewell" ; char st2[20] ; cout << strcpy(st2,st1) << endl ; cin.get(); return 0 ; } page 72 #include #include using namespace std ; int main() { char st1[10]="House" ; char st2[]="Boat" ; cout << strcat(st1,st2) << endl ; cin.get(); return 0 ; } page 72 #include using namespace std ; #include int main() { char st1[]="House" ; char st2[]="House" ; cout << strcmp(st1,st2) << endl; cin.get(); return 0 ; } page 73 #include using namespace std ; #include int main() { char st1[]="House" ; char st2[]="se" ; if (strstr(st1,st2)!= NULL) cout << "found" << endl ; cin.get(); return 0 ; } page 73 #include using namespace std ; #include main() { char st1[]="House" ; _strset(st1,'*') ; cout << st1 << endl ; return 0 ; } page 74 #include using namespace std; #include int main() { char st1[][5]={"ed","joe","john"} ; for (int j = 0;j<3;j++) cout << st1 [j] << endl ; cin.get(); return 0 ; } page 76 #include #include using namespace std; class Strn { char st[8] ; public: Strn() {st[0] = '\0' ;} Strn(char s[]) {strcpy(st,s) ;} }; int main() { Strn s1 ; Strn s2("House") ; s1 = s2 ; cin.get(); return 0 ; } page 77 #include #include using namespace std ; class Strn { char st[10] ; public: Strn() {st[0] = '\0' ;} Strn(char s[]) { strcpy(st,s) ;} void concat(Strn str) { strcat(st,str.st) ; } } ; int main() { Strn s1("House") ; Strn s2("Boat") ; s1.concat(s2) ; cin.get(); return 0 ; } page 78 #include #include using namespace std ; class Strn { char st[10] ; public: Strn() {st[0] = '\0';} Strn(char s[]) {strcpy(st,s) ;} Strn concat(Strn Str) { Strn Temp ; strcpy(Temp.st,st) ; strcat(Temp.st,Str.st) ; return Temp ; } }; int main() { Strn s1("House") ; Strn s2("Boat") ; Strn s3 ; s3 = s1.concat(s2) ; cin.get(); return 0 ; } page 79 #include #include using namespace std ; int main() { string s1("House") ; string s2("Boat") ; string s3 ; s3 = s1 + s2 ; cout << s3 << endl ; cin.get(); return 0 ; }