The C ++ Programming Language Chapter VII

xiaoxiao2021-03-06  19

The C Programming Language Chapter VII James Chen050317

7.10.1 Write the following: A function, it is a pointer to the character, and the reference to the integer is parameter, does not return the value; a pointer to this function; a function that is parameter in this pointer; and a return this Function of a pointer. Write a definition of a function that is used as a parameter in one such a pointer and returns its parameters as the return value. Void F (Char *, INT &); VOID (* G) (CHAR *, INT &); TYPEDEF VOID (* H) (CHAR *, INT &) VOID I (H); HJ (h); ------ ------------ # include using namespace std; typedef void (* g) (CHAR *, INT &); // Define function pointer Void F (char * a, int in) / / Target function {cout << "A: << a << endl; cout <<" B: << B << end1;} void i (g t, char * x, int & y) // function The pointer is a metallin {t (x, y);} g h (g t) // Taking a function pointer as a parameter, returning a function pointer {Return T;} void main () {char A [] = "i love you !!! "; int b = 54321; g p1 = & f; I (p1, a, b); g p2 = h (& f); p2 (a, b);}

7.10.2 What does the following code mean? What is he used? TypedEf Int (INT, INT); this is a custom type that references a function, returns INT, which is referenced to two int. It can use the function as a variable, simplified using the program . Example: #include using namespace std; typedef int (INT); INT Add (int A, int b) {RETURN A B;} int MAX (int A, int b) {RETURN A> b)? A: B;} void main () {Int a = 10, b = 15; RIFII CX = Add, CZ = max; cout << CZ (A, B) << endl; cout << CX (a, b) << endl;}

7.10.3 Write a function similar to "Hello World!", Which uses a name as the command line parameter and writes "Hello Name". Modify this function so that it can be used as a parameter with a series of names and say hello separately. #include using namespace std; int main (int Argc, char * argv []) {for (int i = 1; i

D: /> 7103 Aaaa Bbbbhello, AAAA! Hello, BBBB!

7.10.7 Considering struct tnode {string words; int count; tnode * left; tnode * right;}; writing a function into the TNODE tree into a new word. Write a function to print the TNODE tree. Write a function to print the TNODE tree in order of the word dictionary. #include #include #include #include #include using namespace std; // tnode * newtnode (tnode *) // Insert new node // void printt (tnode * ) // Print Node // Void Prints (TNODE *) // Print the node in order

Struct TNODE {String Word; static int count; // node number is static global variable tnode * left; tnode :: count = 0; // Initialization Tnode :: counttnode * newtnode (tnode * b) ) {TNODE * a = new TNODE; CIN >> A-> Word; A-> Right = 0; A-> COUNT ; if (A-> Count <2) A-> LEFT = 0; // First Node The left node is not 0 else {a-> left = b; // The new left node is equal to the original node b-> Right = a; // The original right node is equal to the new node} Return A;} void printt (Tnode * Temp) {INT N = Temp-> count; while (n--) {cout << SETW (10) << Temp-> Word << ":" << Temp-> Left << "," << Temp << "," << Temp-> Right << Endl; Temp = Temp-> Left;}} Void Prints (TNODE * TEMP) {Vector CXBB; int N = Temp-> count; while (n--) {Cxbb.push_back (TEMP-> Word); Temp = Temp-> Left;} sort (cxbb.begin (), cxbb.end ()); // Sort Vector :: Iterator CZ; for (CZ = cxbb.begin (); CZ! = cxbb.end (); CZ ) cout << * cz << endl;} int main () {tnode * curr; int n = 5; while (n -) curr = newtnode (Curr); PrintT (CURR); // Print Node Prints (CURR); // Print Return 0 in the word order;}

zzzzdddsasdyyyyffff ffff: 00370D10,00372478,00000000 yyyy: 00370C70,00370D10,00372478 sasd: 00370988,00370C70,00370D10 ddd: 00371B88,00370988,00370C70 zzzz: 00000000,00371B88,00370988dddffffsasdyyyyzzzzPress any key to continue

7.10.9 Write an encrypted program that is input from the CIN and writes the encoded character sequence to COUT. The following simple encryption mode can be used: The encryption form of the character C is C ^ Key [i], where Key is a string provided by the command line parameter. This program uses the characters in key in a loop until read full input. The original body can be obtained with the same key to re-encrypt the original text. If Key does not provide Key, it is not encrypted.

#include using namespace std; void enc (char s, char * key) {char x; while (* key! = 0) {x = s ^ * key ; cout << x;} cout << end1; } int Main (int Argc, char * argv []) {if (argc> 1) ENC ('s', argv [1]); return 0;}

D: /> 7109 2342a @ gad: /> 7109 a @ ga2342d: /> 7109d: />

7.10.16 Implementation of Print, Void Print (Int Value, Int Base = 10), Base is the base, and the 16, 2-en-output output #include using namespace std; void bb (int a) {INT N = a / 2, t = a% 2; if (n> 1) {bb (n); cout << t;} else cout << n << t;} void aa (int a) {int n = a / 16, t = a% 16; if (n> 16) AA (N); if (n <10) cout << n; else cout << char (n 55); if (t <10) cout

192192c01100000000 Error !! Press any key to company

7.10.18 Write a step function that does not have recursive. #include using namespace std; int bb (int a) // cycle seeking order {int TEMP = a; while (a-> 1) Temp * = a; return temp;} int AA (int A) / / Recurrence sections {RETURN (a> 1)? A * aa (a-1): 1;} void main () {cout << aa (4) << endl; cout << aa (5) << ENDL COUT << BB (4) << endl; cout << bb (5) << endl;}

2412024120Press Any Key to Continue

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

New Post(0)