C ++ language program design (third edition) homework

xiaoxiao2021-03-05  30

For (x = 2; x > Number; IF (primes) cout << Number << "is the number"; Else Cout << Number << "is not a magnet"; int i; cin >> i;} // 3-10 # INCLUDE "stdafx.h" Using Namespace std; int common_measure (int mark_multiple); int co_multiple (int Num1, int Num2); int COMPAR (int Num1, int Num2, char t); main () {Int Num1, Num2; cout << "Please enter two integers" << Endl; CIN >> Num1 >> Num2; cout << "Their largest number of conventions is:" << COMMON_MEASURE (Num1, Num2) << endl; cout < <"The maximum number of matters is:" << Common_multiple (NUM1, NUM2) << endl; int Temp; cin >> Temp;} int common_measure (int Num1, int Num2) {INT i; for (i = compare (Num1 , Num2, 'N'); I> 1; I -) {IF ((Num1% I) == 0) && ((Num2% i) == 0)) {RETURN I;}}} int COMMON_MULTIPLE (int Num1, int Num2) {Int i; for (i = compare (NUM1, NUM2, 'X'); i <= Num1 * Num2; i ) {IF ((i% Num1) == 0) && (I% Num2) == 0)) {RETURN I;}}} INT COMPARE (INT NUM1, INT NUM2, CHAR T) {IF (t == 'x') RETURN NUM1> Num2? Num1: Num2; Else Return NUM1 > Number; cout << "sum is" << su (number); int Temp; cin >> Temp;} // 3-14 # include " Stdafx.h "using namespace std; int fib (int n) // with a recursive function, speed does not say, super TM slow {IF ((n == 1) || (n ==

2))) {RETURN 1;} Return (FIB (N-1) FIB (N-2));} INT FIB2 (int N) // Made of FOR, speed is more than {INT i = N; int result_n = 1; int result_n_1 = 1; int T; for (i = 1; i > Number; cout << Fib (Number); int Temp; cin >> Temp;} // 3-15 # include "stdafx.h" Using "stdafx.h" Namespace std; float pn (int x, int N); main () {int number, xx; cout << "Input PN (x) n =?"; cin >> Number; cout << "Enter PN (X ) X =? "; Cin >> xx; cout << pn (xx, number); int Temp; cin >> Temp;} float pn (int x, int N) {if (n == 0) {Return 1;} else {IF (n == 1) Return X; Else Return (Float ((2 * n-1) * x * Pn (x, n-1) - (N-1) * PN (X, N-2)) / n));}} // 4-8 #}} // 4-8 # include "stdafx.h" Using namespace std; class dog {public: DOG () {agn = 0; weight = 0;}; void setdog INT D_AGE, INT D_WEIGHT); void showdog (); private; @, void dog :: setdog (int D_age, int d_weight) {agn = D_AGE; Weight = D_Weight;} void Dog :: showdog ) {COUT << "Dog's agent" << age << ". DOG IS" << Weight << "kg." <

Rectangle (Rectangle & rec); void setRec (point t_LBpoint, point t_RTpoint); int getarea (); private: point LBpoint; point RTpoint; int areaVal;}; int Rectangle :: getarea () {areaVal = - (RTpoint.GetX ( ) -Lbpoint.getx ()) * (RTPoint.Gety () - lbpoint.gety ()); return areaval;} Rectangle :: Rectangle (Rectangle & Rec): lbpoint (rec.lbpoint), Rtpoint (REC.RTPOINT) { areaVal = rec.areaVal;} void Rectangle :: setRec (point t_LBpoint, point t_RTpoint) {LBpoint = t_LBpoint; RTpoint = t_RTpoint;} // 4-10 # include "stdafx.h" using namespace std; class date {public: Date () {year = 2000; month = 1; day = 1;} Date (int Tyear, int Tmonth, int TDAY); void setdate (int Tyear, Int Tmonth, int TDay); int getYear (); int GETMONTH ( ); Int product: int year; int month; int day;}; date :: date (int Tyear, int TMONTH, INT TDAY) {year = type; month = tmonth; day = tday;} void Date :: setdate (int Tyear, int Tmonth, int TDAY) {year = Tyear; month = tmonth; day = tday;} int DAY;} int DAY ;.} Int Date: getMonth ()} int DAY; } int Date: getYear () {Return Year;} CLA ss employee {public: employee (int tnum, char tgender, date tbirthday, int tid); ~ employee () {}; employee (employee & otheremp); int getnum (); char getgender (); date getbirthday (); int getid (); Void Putin (int TNUM, int TID); void showemployee (); private: int Num; char gender; Date Birthday; int ID;}; Employee :: Employee (int TNUM , date tbirthday, int tid): birthday (tbirthday) {num = tnum; gender = tgender; id = tid;} employee :: employee (employee & otheremp): birthday (otheremp.birthday) {num = otheremp.num; gender = OtHeRemp.gender; id = Otheremp.id;} int equployee :: getnum () {return num;} Date Employee :: getBIRTHDAY () {Return Birthday;

} Char employee :: getgender () {return gender;} int employee :: getid () {return id;} void employee :: putin (int tnum, char tgender, date tbirthday, int tid) {birthday = tbirthday; num = TNUM; gender = TGENDER; ID = TID;} void Employee :: ShowemPloyee :: ShowemPloyee () {cout << "Num =" << "" gender = "<< GENDER <<" id = "<< ID << ENDL } main () {Date Birthday (2004, 3, 23); Employee My (2703, 'M, Birthday, 816); Employee Your (My); my.showemployee (); Your.ShowemPloyee (); Your. Putin (9876, 'f', Birthday, 51025); Your.ShowemPloyee (); Date Tempdate; Tempdate = my.getbirdhday (); cout << Tempdate.getDay () << endl;} // 4-11 # 网clude "stdafx.h" using namespace std; class Rectangle {public: Rectangle (float twhiget, float thight); void setRec (float twhiget, float thight); float acreage (); protected: float whight; float hight;}; Rectangle: : Rectangle (float twhight, float thight) {whight = twhight; hight = thight;} void Rectangle :: setRec (float twhight, float thight) {whight = twhight; hight = thight;} float Rectangle :: acreage () {return WHIGHT * HIGHT;} main () {Rectangle Box (54.1, 15.1); co T << Box.acreage () << endl;} // 4-14 # include "stdafx.h" Using Namespace std; class tree {public: Tree (int Tage) {ages = TAGE;} Void GROW Void Age (); protected: int Ages;}; void tree :: agge () {cout << Ages << Endl;} void tree :: grow (int year) {ages = AGES YEAR;} main ) {Tree Green (5); green.GROW (2); green.age ();} //6-4sizeof oneArray / sizeof oneArray [0]; //6-16 # include "stdafx .h "#include Using namespace std; void main () {int a; int * p = & a; int & r = a; * p = 10; r = 5;} // 6-5 # incrude" stdafx .h "#include <

String> using namespace std; void main () {for (int A [5] [3], i = 0; i <15; i ) * (* a i) = i;} // 6-17 # include "stdafx.h" #include using namespace std; void main () {int * p; p = new int (9); cout << "The value at p: << * p; delete p;} //6-18 # include "stdafx.h" #include using namespace std; int * fn1 (); void main () {int * a = fn1 (); cout << "The value at a is: << * a; delete a;} int * fn1 () {INT * P = new int (5); return p;} // 6-20 # include "stdafx.h" #include Using Namespace STD ; class SimpleCircle {public: SimpleCircle (float); float Area (); float perimeter (); ~ SimpleCircle (); private: float * itsRadius; const double pi;}; SimpleCircle :: SimpleCircle (float radius): pi (3.1415926 {Itsradius = new float (radius);} float simple :: area () {return pi * (* itsradius) * (* itsradius);} float simplecircle :: perimeter () {return 2 * pi * (* itsradius) } Simplecircle :: ~ simplecircle () {delete itsradius;} main () {SimpleCircle C1 (123); cout << c1.area () << end1;} //6-21 # include "stdafx.h" # INCLUDE using namespace std; int Wordnum (Char S []); main () {char s [] = "vnhfgtrfdewqasdhgghfhgfhgfhgf"; cout << WordNum (s) << end1;} int WordNum (CHAR S []) {INT N = 0; for (int i = 0; S [i]! = '/ 0'; i ) {IF ((S [i] <= 'z' && s [i]> = 'a') || (s [i] <= 'z' && s [ I]> = 'a')) N ;} Return N;} // 6-22 # include "stdafx.h" #include using namespace std; int index (char * s, char * t) {bool Same = true; for (int i = 0; s [i]! = '/ 0'; i ) {IF (s [i] == t [0]) {for (int J = 1; t [j] ! = '/ 0'; J

) {IF (s [i j]! = T [j]) {same = false; break;}} f (Same) Return i;}} Return -1;} main () {char s [] = "jiaxun"; char t [] = "xun"; cout << index (s, t);} // 6-23 # include "stdafx.h" #include using namespace std; Reverse (char * s ) {If (* s! = '/ 0') {Reverse (s 1); cout << * s;}} main () {char string [] = "abcdefg"; Reverse (String); cin.get ();} // 6-24 # include "stdafx.h" #include using namespace std; main () {const INT n = 8; int successs [n]; int sum = 0; cout << " Enter "<< n <<" The results of a classmate "<< Endl; for (int i = 0; i > Students [i]; sum = students [i];} cout <<" average score is: "<< float (sum) / float (n) << endl;} // 6- 25 # include "stdafx.h" #include using namespace std; class MyString {public: MyString (); MyString (char * newStr); MyString (MyString & OtherStr); ~ MyString (); int Length (); MyString Operator (MyString S2); Char & Operator [] (int N); void operator = (const myString Otherstr); Void Operator = (MyString Otherstr); Operator Char * (Void) Const; Privat E: Char * Str; Int getlen (char * s); char * tempstr;}; mystring :: mystring () {tempstr = new char [255]; str = 0;} mystring :: mystring (char * newstr) { Tempstr = new char [255]; int newstrlength = getlen (newstr); str = new char [newstrlength]; for (int i = 0; i

Otherstr.tempstr [I]; if (orthol) Str = 0; else {int tength () 1; str = new char [otherStrlength]; for (int i = 0; i < Otherstrlength; i ) str [i] = taherstr [i];}} int myString :: getlen (char * s) {INT i = 0; while (s [i]! = '/ 0') i ; returni i 1;} int mystring :: length () {return getlen (str) -1;} myString :: ~ mystring () {delete [] str; delete [] tempstr;} mystring mystring :: Operator (mystring s2) { INT longth = getlen (STR); INT i; for (i = 0; i <(length-1); i ) Tempstr [i] = STR [I]; int S2LEN = S2.LENGTH () 1; for INT j = 0; i (Getlen (STR))) {cout << "subscript" << Endl; cin.get ();} Return Str [n];} void myString :: operator = (MyString Otherstr ) {Delete [] str; Int = new char [taherstrlen]; for (int i = 0; i using namespace std; void Chang (int C [3]); main () {Int C [3 ] [3] = {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; chang (c); for (int i = 0; i <3; i ) { For (int J = 0;

J <3; J ) {cout << C [i] [j] << "";} cout << end1;}} void Chang (int C [3] [3]) {int Temp [3] [3 ]; For (int i = 0; i <3; i ) {for (int J = 0; j <3; j ) {TEMP [J] [i] = C [i] [j];}} for INT i = 0; i <3; i ) {for (int J = 0; j <3; j ) {c [i] [j] = TEMP [i] [j];}}} // 6-27 #include "stdafx.h" #include using namespace std; void Chang (int * C, int m, int N); main () {Int C [3] [4] = {1, 2, 3 , 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; chang ((int *) C, 3, 4); cin.get ();} void Chang (int * C, INT M, INT N) {INT * TEMP = New INT [m * n]; for (int i = 0; i using name {Class Employee { public: employee (char tgender, int tid, int tzipcode, string tcity, string taddress, string tname); employee (employee & otheremp); void chage_name (string newname); void dispaly (); private: char gender; int id; string String name; string city; int zipcode;}; employee :: employee (char tgender, int tid, int tzipcode, string tcity, string taddress, string tname) {gender = tgender; id = tid; zipcode = tzipcode; city = tcity; address = taddress; name = tname;} void Employee :: chage_name (String newname) {name = newname;} void Employee :: dispaly () {cout << "Name:" name << "<< Gnder << Endl; cout <<" ID: " << ID << Endl; Cout << "Zip code:" << Zipcode <<

转载请注明原文地址:https://www.9cbs.com/read-34017.html

New Post(0)