"C + + Syntax Basics" Experiment 1

Source: Internet
Author: User

  1. Experimental content:
    1. 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. "
        1. 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

    2. 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. )

      1. 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

  2. Basic C + + summary:

    • Input and output I/O flows for data:
      • In C + +, the flow of data from one object to another is abstracted as "flow". The stream is to be established before use and is deleted after use.

      • The input and output of the data is implemented through I/O streams, and CIN and cout are predefined stream class objects. CIN is used to process standard input, which is keyboard input. The cout is used to process standard output, which is the screen output.
      • The operation to get data from a stream is called an extract operation, and the operation to add data to the stream is called an insert operation.
    • 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
  3. Problems encountered using the software:
    1. 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

    2. Codeblocks How to do the Step-by debug: https://jingyan.baidu.com/article/597a064352b507312a524350.html
    3. Devc How to distribute debug: http://blog.csdn.net/github_39363510/article/details/76368968

"C + + Syntax Basics" Experiment 1

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.