- Experimental content:
- Title: Enter an integer for 1~7, or output "workday" if the input is a delivery. Let's work hard "; If you enter 6~7, the output is" weekend. Let ' s has a rest. "
-
- Code:
1#include <iostream>2 using namespacestd;3 4 intMain () {5 intN;6 while(cin>>N) {7 Switch(n) {8 Case(1):9 Case(2):Ten Case(3): One Case(4): A Case(5): -cout<<"Workday. Let's work hard"<<Endl; - Break ; the Case(6): - Case(7): -cout<<"weekend. Let ' s has a rest"<<Endl; - Break; + default: -cout<<"your data is worng,try again"<<Endl; + Break ; A } at - } - return 0; -}
View Code
Title: Enter an integer to invert the numbers and output. (for example, enter 365, output 563.) In the implementation of example 2-6, the 5-6-3 is output one by three times, which requires that 563 be output as a total number. )
- Code
1#include <iostream>2 using namespacestd;3 intMain () {4 intN,right;5 6 while(cin>>N) {7cout<<"Enter the number:"<<n<<Endl;8 intnewnum=0;9 Do{Tenright=n%Ten; Onenewnum=right+newnum*Ten; AN/=Ten; -} while(n!=0); -cout<<"The number in reverse oder is"<<newnum<<Endl; the } - - return 0; -}
View Code
Basic C + + summary:
- Input and output I/O flows for data:
- Common I/O Stream class Library operators: For example COUT<<SETW (5) <<setprecision (3) << 3.1415;
Table 2.1
Meaning |
Dec |
numeric data in decimal notation |
Hex |
Numeric data is represented by hexadecimal |
Oct |
The numeric data is represented by octal |
Wx |
Extracting whitespace characters |
Endl |
Line break, and refresh the stream |
Ends |
Insert NULL character |
setsprecision (int) |
Set the number of decimal places for floating-point numbers (including decimals) |
SETW (int) |
Set the field width |
- Namespaces: Avoid naming conflicts, STD is the C + + standard library namespace (namespace) name, using namespace std means open std namespace
- Problems encountered using the software:
- The Codeblocks run icon is grayed out and cannot be compiled. You cannot run the next program until you have tried multiple times to find that the previous compilation window is not closed.
There is also a situation where the compiler may not be downloaded. Workaround: http://blog.csdn.net/qq_24805141/article/details/51265174
- Codeblocks How to do the Step-by debug: https://jingyan.baidu.com/article/597a064352b507312a524350.html
- Devc How to distribute debug: http://blog.csdn.net/github_39363510/article/details/76368968
"C + + Syntax Basics" Experiment 1