, you can also simply use the Debug macro or printf function printing. Specific or personal habits. There's only one goal anyway: Improve code stability.7, Programming exercises (title 7):1#include 2 3 voidBoth (void);4 voidOne_three (void);5 6 intMainvoid){7printf"starting now:\n");8 One_three ();9printf"done!\n");Ten return 0; One } A - voidBoth (void){ -printf"two\n"); the } - - voidOne_three (void){ -printf"on\n"); + both (); -printf"three\n"); +}Operation Result:Starting now:OnBot
be shared between files, and the internal name of the link is shared only by functions in one file.3. Using the keyword register, it is recommended that the compiler use CPU registers to store automatic variables, which are designed to increase the speed of accessing variables. (Same as the previous usage of auto, c++11 obsolete).4. Static storage persistence variables provide 3 features: external linkage (external declaration of code blocks), internal chaining (code block external static decla
1. OOP emphasizes the decision-making during the run phase, not the compile phase, when the program is running, while the compile phase refers to when the compiler combines the program.2. The value of the variable is stored in the stack, and new allocates memory from a memory area known as a heap or free storage area.3. Static linking: It is added to the program at compile time.Dynamic linking: Created when the program is running.4. The array name is interpreted as the address of its first eleme
" - "Max is" $ "min is"Endl; the } the the Drive the#include -#include in#include string> the#include the#include"Sales.h" About using namespacestd; the the intMain () { thecout "Enter a number you want to fill the array\n"; + intn, I; -CIN >>N; the Double*ar =New Double[n+1];Bayicout "Enter an double array\n"; the for(i =0; I ) theCIN >>Ar[i]; - sales::sales Ex1, ex2; - sales::setsales (Ex1, AR, n); the sales::setsales (EX2); the sales::showsales (EX1); the sal
:\n"; C1. Report (); C2. Report (); //Cd SD;cout"using Type cd * pointer to object:\n"; PCD-Report (); PCD= C2; PCD-Report (); cout"calling a function with a Cd reference argument:\n"; Bravo (C1); Bravo (C2); cout"Testing Assignment"Endl; Classic copy; Copy=C2; Copy. Report (); return 0;}voidBravo (ConstCd disk) {disk. Report ();}Test.cppCall the base class construct first, then call the derived class construct, the destructor instead, call the derived class destructor firs
potentially scoped to the beginning of the declaration point to the end of the declaration area. The name in the namespace cannot be used outside of the file to which the unnamed namespace belongs, providing a substitute for a static variable that is linked internally.
3. concept of use of namespaces
Instead of using an external global variable, use the variable declared in the named namespace.
Use a variable declared in a named namespace instead of using a static global variable.
the ability to closely connect the hardware1.3 Portability and standards Portability: If you recompile the program without modifying the code, the program will run well, and the program is portableTwo barriers to portability: 1. Hardware-specific programs that are not portable (placing hardware-dependent parts in function modules can minimize portability: this is just a matter of rewriting these modules). 2. Standard issues (establishing a unified C + + standard)There are some differences betwe
of 3 years is:"return 0;}7#include structcar{Charmake[ +];intyear;};intMain () {using namespaceStdintNum Car * cars; cout "How many cars does you wish to catalog:"; CIN >> Num; Cars =NewCar[num]; for(inti =0; i "Car #"1":\ n"; cout "Please enter the Make:";//cin >> cars[i].make;Cin.getline (Cars[i].make, +); Cin.get (); cout "Please enter the year made:"; Cin >> Cars[i].year; } cout "Here is your collection:\ n"; for(inti =0; i " "Delete[] cars;return 0;}8#include #include i
operator, however, means that the original address (arr[2]) is de-referenced instead of the incremented new address, so the value of *pt++ is arr[2], or 25.4,However, the value of PT will be the address of arr[3] When the statement is executed.#include"stdafx.h"#includeintMain () {using namespacestd; Doublearr[5]={21.1,32.8,23.4,45.2,37.4}; Double*pt=arr; ++pt; intA; Doublex; coutEndl; coutEndl; coutEndl; coutEndl; X=*pt++; coutEndl; CIN>>A;}Note: The pointer increment and decrement follow the
of 3 years is:"return 0;}7#include structcar{Charmake[ +];intyear;};intMain () {using namespaceStdintNum Car * cars; cout "How many cars does you wish to catalog:"; CIN >> Num; Cars =NewCar[num]; for(inti =0; i "Car #"1":\ n"; cout "Please enter the Make:";//cin >> cars[i].make;Cin.getline (Cars[i].make, +); Cin.get (); cout "Please enter the year made:"; Cin >> Cars[i].year; } cout "Here is your collection:\ n"; for(inti =0; i " "Delete[] cars;return 0;}8#include #include i
,const stonewt) as a friend function, and let the Stonewt (double) constructor convert a parameter of type double to a parameter of type STONEWT.② overloads the addition operator to a function that explicitly uses a double type argument: Ⅰ, STONEWT operator + (double X);//member function Ⅱ, friend Stonewt operator+ (double X,STONEWT S );//friend function pros and Cons: The first method relies on implicit conversions to make the program shorter because fewer functions are defined. The disadvant
declarations in a class: A struct, class, or enumeration declared in a class declaration is referred to as being nested within a class and scoped to the entire class. This declaration does not create a data object, but simply specifies the type that can be used in the class. If the declaration is made in the private part of the class, the declared type can be used only in that class, and if the declaration is made in the public part, the declared type may be used from the outside of the class
calculates the tax. Use loops so that users can enter multiple times.#include The ABC Mail Order Grocery Artichoke is priced at $1.25/lb, the beet is priced at $0.65/lb, and the carrot is priced at $0.89/lb. Before adding shipping charges, they offer a 5% discount on orders of $100. Shipping and handling costs of $3.50 are charged for orders of 5 pounds or less, and orders over 5 lbs. and less than 20 lbs. for shipping and handling costs of 1o.oo USD: 20 pounds or more,
C primer plus (version 5) programming exercises-Chapter 8 programming exercises, primerplus
1. design a program to count the number of characters from the input to the end of the file.
# Include
2. Write a program and read the input as a forward stream until an EOF is encountered. This program prints each input character and its ASCII decimal value. Note that the characters before the space characters i
, the reinterpret_cast operator does not support all type conversions. For example, you can convert a pointer type to an integer that is sufficient to store the pointer representation, and a single cannot convert the pointer to a smaller integer or float type. Another limitation is that you cannot convert a function pointer to a data pointer, or vice versa.In C + +, ordinary class conversions are also restricted. Basically, you can perform other types of conversions,
a set of string constants;cin>>c; The expression also has a return value, for example, C is an integer, but the input is a string, returns false, and the input string is stored in the buffer. The c++ function cannot return a string so it can only return his address. This time the function is to create a new pointer variable length to the length of the string plus 1 the last assignment is the n+1//c++ function pointer--you need to enclose it in parent
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.