C ++ Primer Plus study Note 2, cprimerplus
C ++ Primer Plus study Note 2
Chapter 5 loop and relational expressions
========================================================== ========================================================== ==========================================
1. Set a flag for the cout. setf (ios: boolalpha) function call. The cout command shows true and false instead of 1 and 0.
2. In a for loop, for (int I = 0; I <len; I ++) only exists in the for statement, this variable disappears. So if the variable I needs to be used later, we need to declare the I before the loop. Int I;
3. In the same statement, do not progressively decrease or decrease the value multiple times, which will blur.
4. prefix and suffix format
For (n = lim; n> 0; -- n)
For (n = lim; n> 0; n --)
The prefix is the same as the suffix, and the efficiency of the prefix is higher than that of the suffix. The prefix will subtract 1 and then return directly. The suffix will first copy a copy, subtract 1 from it, and then return the copy.
5. Increment/decrease operators and pointers
1) The prefix increment, prefix decrease, and unreference operator have the same priority level and are combined from right to left.
2) * ++ pt first applies the ++ application and pt-> uses the pointer to the added pt.
3) ++ * pt first obtains the value pointed to by pt, and then adds this value to 1.
4) (* pt) ++ removes the reference from the pointer, and then ++
5) * pt ++ because the suffix operator ++ has a higher priority level, this means that the operator is used for pt instead of pt, so the pointer increments, however, the suffix operator removes the reference from the original address rather than the new address after the increment. That is to say, the value of * pt ++ is arr [2], but after the execution is complete, the pt value is the address of arr [3 ].
6. Note that the difference operator (=) and the value assignment operator (=) do not use = to compare whether the two quantities are equal. Otherwise, it will usually enter an endless loop, it must be true because a non-zero value is assigned to a variable or array element.
7. The array name is the address of the array, and the String constant enclosed in quotation marks is also the address. "Mate"
8. test whether the C-style strings are equal in strcmp ().
1) if str1 and str2 are equal to strcmp (str1, str2) = 0;
2) If str1 and str2 are not equal, strcmp (str1, str2 )! = 0;
3) If str1 is in front of str2, strcmp (str1, str2) <0;
4) if str1 is behind str2, strcmp (str1, str2)> 0;
9. differentiate between C-style characters and string-type strings
For (char ch = 'a'; strcmp (word, "mate"); ch ++)
For (char ch = 'a'; word! = "Mate"; ch ++)
10. Wait for a while and write the delayed Program
Long wait = 0;
While (wait< 10000)
Wait ++;
11. do while LOOP
If you request a user input, the program must first obtain the input and then test it. At this time, we need to use do while
Format: statement1
Do
Statement2;
While (test_expr );
Statement3;
12. Identify the original cin input and cin. get (char) for remediation
1) When cin reads the char value, like reading other types, cin will ignore spaces and line breaks, so the spaces in the input are not echo, and of course they are not included in the count.
2) using cin. get (char), each character is displayed and all characters are included, including spaces.
13. differentiate cin. get () in C and C ++ Environments ()
Cin. get (name, Arsize) in C)
C ++ supports function overloading of OPP. In addition to C, you can also use cin. get (char)
14. File end conditions
If the input is from a file, we can use EOF. After detecting EOF, cin sets both eofbit and failbit to 1.
Therefore, you can write while (cin. fail () = false) to detect EOF.
Run this program in Windows. Press Ctrl + Z and enter to simulate EOF conditions. For UNIX and Linux users, press Ctrl + D.
Common Character Input practices:
Char ch;
Cin. get (ch );
While (cin. fail () = false)
{}
15. Generally, EOF is set to-1 because there is no ASCII value-1.
16. Common Character Input and Output Methods
Int ch;
While (ch = cin. get ())! = EOF)
{
Cout. put (char (ch ));
++ Count;
}
Note the following two points! = Priority Ratio = high, so brackets must be added ② use cout. put () because the prototype in the brackets is char, so we must forcibly convert the integer type to char type.
Distinguish between cin. get (ch) and ch = cin. get ()
The former is to assign the value to the parameter ch; the latter is to assign the return value of the number of rows to ch, so here is an integer.
17. Two-dimensional array Initialization
1) char * cities [Cities] =
{
"......",
"............ ",
}
2) char cities [] [] =
{
{...............},
{...............},
}
3) string cities [Cities] =
{
"............ ",
"......",
}
========================================================== ========================================================== ==========================================
Chapter 6 branch statements and logical operators
1. if ......
Else if ......
Else ......
2. cctype of the character function library
1) isalnum () checks for letters or numbers
2) isalpha () Check letters
3) isblank () Checks space or horizontal tabs
4) iscntrl () detection parameter is a control character
5) isdigit () detection parameter is a number
6) isgraph () detection parameters are printed characters except spaces
7) islower () detection parameters are lowercase letters
8) isprint () detection parameters are printed characters including Spaces
9) ispunct () detection parameters are punctuation marks
10) The isspace () detection parameter is a standard white space character
11) isupper () detection parameters are uppercase letters
12) isxdigit () Checks who the parameter is in hexadecimal format
13) If tolower () is an uppercase letter, convert it to a lowercase letter.
14) If toupper () is a lowercase letter, convert it to an uppercase letter.
3 ,? : Operator: this is the only operator in C ++ that requires three operands. This is applicable to simple relationships and simple expressions x = (x> y )? X: y;
4. switch statement
Switch (integer-expression) // constant
{
Case 1: statement1 (s );
Break;
Case 2: statement2 (s );
Break;
Case 3: statement3 (s );
Break;
......
Default: statement4;
}
Note that the break statement is used to ensure that only the specific part of the switch statement is executed. Therefore, we can use the break control to output the statement precisely. That is to say, if case 1 and case 2 are the same, we can
Case 1:
Case 2: statement1 (s); break;
We have learned enumeration before, so we can use enumeration as the switch label.
If you can use the if else if statement or switch statement, use the switch statement when there are no less than three options.
5. The rest of the break jump out of the loop and reach the next statement. continue jumps out of the remaining code of the loop body and starts a new round of loop.
========================================================== ========================================================== ==========================================
Chapter 7 functions-C ++ compilation Module
1. To use a function, you must provide the definition and prototype and call the function.
1) C ++ defines functions, which are divided into functions without return values and those with return values. For functions with return values, the return type has certain limitations, not arrays, but it can be any other type-integer, floating point number, pointer, or even structure and object. Note that C ++ can return an array as a structure or an object component.
2) prototype is generally required because the prototype describes the interface from the function to the compiler. The only way to avoid using the function prototype is to define it before using the function for the first time, but this is always feasible.
2. function parameters: when defining a function, if the two parameters of the function have the same type, the type of each parameter must be specified separately, instead of being like declaring a regular variable, combine declarations.
Void fifi (float a, float B)
Void fufu (float a, B) (invalid)
3,R= (51, 50, 49, 48, 47, 46)/(6, 5, 4, 3, 2, 1)
Long double result = 1.0;
For (n = numbers, p = picks; p> 0; n --, p --)
Result = result * n/p;
Distinguish between (10 then 9)/(2 then 1) and (10/2) Then (9/1)
If there are more factors, the larger the center value of the first method is, the higher the overflow is.
4. Function Header
Int sum_arr (int arr [], int n)
Note that arr is not actually an array but a pointer,
Int sum_arr (int * arr, int n) is in C ++ and only used in function header or prototype.
Int * arr and int arr [] have the same meaning, which means that arr is an int pointer. Note that in other contexts, the meanings of these two items are not equal.
5. Two constants: array and pointer
Arr [I] = * (arr + I)
& Amp; arr [I] = arr + I
Remember, adding 1 to the pointer (array name) actually adds a value equal to the length of the type pointed to by the pointer. For traversing the array, pointer addition is equivalent to array subscript.
6. To tell the array handler function the array type and number of elements, we need to pass two different parameters to them void fillArray (int arr [], int size)
Instead of trying to use square brackets to pass the array Length
Void fillArray (int arr [size]); (invalid)
7. Use functions of array intervals
For (pt = begin; pt! = End; pt ++)
Total = total + * pt;
End-begin is an integer equal to the number of elements in the array. In fact, this is the rule of pointer subtraction.
8. If the data type itself is not a pointer, you can assign the addresses of const data or non-const data to the pointer to const, however, only the addresses of non-const Arrays can be assigned to non-const pointers.
9. Differentiate the const pointer and const pointer
1) int gorp = 16;
Int chips = 12;
Const int p_snack = & gorp; p_snack = 20; (invalid) do not modify the value pointed to by the pointer
P_snack = & chips; (valid) pointer can point to another variable
2) int gorp = 16;
Int chips = 12;
Int const p_snack = & gorp; p_snack = 20; (valid) the value pointed to by the pointer can be modified.
P_snack = & chips; (invalid) do not change the vector pointing
10. Functions and two-dimensional arrays
Int data a [3] [4] = {1, 2, 3, 4}, {9, 8, 7, 6}, {2, 4, 6, 8 }};
Int total = sum (data, 3 );
Prototype: Two Methods
1) int sum (int (ar2) [4], int size );
2) int sum (int ar2 [] [4], int size );
11. Use a C-style string as a parameter Function
Three methods to represent strings
1) char array char ghost [15] = "galloping ";
2) String constant int n = strlen ("gamboling") enclosed in quotation marks ")
3) char pointer char str = "galumphing";
12. An important difference between a C-style string and a regular char array is that the string has a built-in ending character, which means that we do not have to pass the length of the string as a parameter to the function, the function can check every character in the string cyclically until it encounters a null character at the end. Note that the char array that contains characters but does not end with a null value is an array rather than a string.
(Important) standard way to process characters in strings
While (* str)
{
Statements
Str ++;
}
// Count the number of times the ch character appears in the string. cppint c_in_str (const char * str, char ch) {int count = 0; while (* str) {if (* str = ch) count ++; str ++ ;} return count ;}
Const has many advantages. If the error address function modifies the content of the string, the compiler will capture this error.
12. Return the C-style string functions.
The function cannot return a string, but can return the address of the string. This is more efficient. The function receives two parameters: one character and one number. The function uses new to create a string with the same length as the number parameter, and then initializes each element to this character.
// Create a string containing n ch. cppchar * buildstr (char c, int n) {char * pstr = new char [n + 1]; pstr [n] = '\ 0'; while (n --> 0) pstr [n] = c; return pstr ;}
Note that delete is used.
13. struct members and
// Time addition. cppstruct travel_time {int hours; int mins;}; travel_time sum (travel_times t1, travel_time t2) {travel_time total; total. mins = (t1.mins + t2.mins) % 60; total. hours = t1.hours + t2.hours + (t1.mins + t2.mins)/60; return total ;}
14. Processing Space Structure
// Convert the Cartesian coordinates into polar coordinates. cppstruct rect {double x; double y ;}; struct polar {double distance; double angle ;}; // converts the radian value to an angle value, multiply the radian value by 180/pi to about 57.29577951 polar rect_to_polar (rect xypos) {polar answer; answer. distance = sqrt (xypos. x * xypos. x + xypos. y * xypos. y); answer. angle = atan2 (xypos. y, xypos. x); return answer ;}
15. Transfer Structure address
// Convert the Cartesian coordinates into polar coordinates. cppvoid rect_to_polar (const rect * pxy, polar * pda) {using namespace std; pda-> distance = sqrt (pxy-> x * pxy-> x + pxy-> y * pxy-> y); pda-> angle = atan2 (pxy-> y, pxy-> x );}
16. Recursion
Unlike C, C ++ does not allow main () to call itself. This function is called recursion.
Contains a recursive call
Void recurs (argumentlist)
{
Statments1
If (test)
Recurs (arguments)
Statments2
}
========================================================== ========================================================== ======================================
Ended at on March 16 ,.
Plsql Study Notes 2
There are many brands of laptops, but from the recent computer warranty and after-sales service, the most important thing is the cost effectiveness, I recommend two brands of computers "Lenovo and HP"
Below I will introduce several computers, the landlord can consider,
Lenovo
Its Y430 series are among the first in terms of sales volume of computers and attention to the Ultimate Edition.
I want to introduce three models.
Y430a-pse
The configuration is as follows:
Processor Model Intel Core 2 dual-core P7450
Nominal clock speed 2.13 GHz
Front-End bus 1066 MHz
Level 2 Cache 3 MB
Kernel architecture Penryn
Platform technology Intel Platform
Motherboard chipset Intel PM45
Standard memory capacity 2 GB
Memory type DDRIII
Supports up to 4 GB memory
Hard drive/Optical Drive
Hard disk capacity 250 GB
Hard Disk description SATA
Optical Drive Type DVD recorder
Built-in design type Optical Drive
Graphics/sound effects
Low-end independent video card
NVIDIA GeForce 9300 m gs graphics chip
Stream processor count 16
Memory/Bit Width 256 MB/64 bit
Video memory type DDRII
Audio System built-in sound chip
Speaker Dolby certified sound effects, 2.1 audios (stereo speaker + subwoofer)
Display
Screen Size: 14.1 inch
Screen Ratio
Screen Resolution: 1280x800
Screen description LED WXGA
Size/weight
2350 GB laptop weight
Shape: 334x241x26-38mm
Case Material Composite Material
Network Communication
Wireless Network Card Intel 5100AGN
Nic description Mbps Nic
Support for Bluetooth
Modem 56 K
Red outer line infrared interface
Mouse/keyboard
Device touchpad
Keyboard description Lenovo notebook keyboard with high touch
Interface
USB interface: three USB Interfaces
Extended Interface ExpressCard
Card Reader-in-One Card Reader (SD/MMC, xD, MS, MS pro, SD Pro)
Video output HDMI high-definition port and standard VGA Interface
Other interfaces, such as 1394, RJ45, and full-array noise-resistant microphones, support for stereo audio headphone jack/audio output, and
Power supply description
Battery Type 6-core lithium battery
Power adapter 90 W power adapter
Others
Windows Vista Home Basic
Warranty Period: 3 years
Associated Software Package
Random attachment mouse
Optional accessory and notebook Gift Packs (purchased separately)
Other features: 1.3 million pixels support secure and easy-to-use Face Recognition
Quiet Mode with one click
Dolby audio 2.1 audio system
Electrostatic induction multimedia touch operation
Entertainment shuttle Sound Field Control
Hdmi hd output port
Other features: Lenovo one-click rescue/Lenovo flash link Ren Yitong
Environment requirements
Operating temperature 0-35 ℃
Operation humidity parameter error 10%-90% (no condensation)
The price is around 6100, which is definitely worth the money... In particular, it has good heat dissipation performance!
The second is y430-tfi.
Configuration
Intel Core 2 dual core T5800
Nominal 2 GHz clock speed
Front-End bus 800 MHz
Level 2 Cache 2 MB
Kernel architecture Merom
Platform technology: Intel®
Motherboard chipset Intel PM45
Standard memory capacity 2 GB
Memory type DDRIII
Supports up to 4 GB memory
Hard drive/Optical Drive
Hard disk capacity 250 GB
Hard Disk description SATA
Optical Drive Type DVD recorder
Built-in design type Optical Drive
Graphics/sound effects
Low-end independent video card
NVIDIA GeForce 9300 m gs graphics chip
Stream processor count 16
Memory/Bit Width 256 MB & #47 ...... remaining full text>
After reading C Primer Plus, can I learn C ++?
Yes
Differences between C and C ++:
1. The new program thinking, C language is process-oriented, and C ++ Is Object-Oriented.
2. The C language has a standard function library, which is loose, but stores functions with the same functions in a header file. C ++ is tightly integrated with most functions, in particular, the APIs in C ++ that are not available in C language are an organic combination of most APIs in the Window system and are a collective. However, you may also call the API separately.
3. Especially in C ++, it is very different from the language graphics. Graph processing functions in C language cannot be used in C ++. The C language standard does not include graphic processing.
4, C and C ++ both have the structure concept, but in C, the structure only has member variables, but there is no Member method. In C ++, it can have its own member variables and member functions. However, in the C language, the structure members are public and can be accessed by anyone who wants to access them. In VC ++, the structure members do not have a qualifier that is private.
4. C language can write many programs, but C ++ can write more and better. C ++ can write programs based on DOSr, DLL, control, and system.
5. The c language is loose to program files, and almost all files need to be processed. The c ++ organizes files by project and each file is clearly classified.
6. The IDE in C ++ is very intelligent. Like VB, some functions may be better than VB.
7. C ++ pairs can automatically generate the program structure you want, saving you a lot of time. There are many available tools, such as when you add a class to MFC and when you add a variable.
There are also many additional tools in C ++. You can perform system analysis, view APIs, and view controls. Powerful debugging functions and diverse methods.