[0311] C + + Simple programming-1

Source: Internet
Author: User

Experimental Report of Nanjing University of Information Engineering

Experiment Name C + + simple programming-1 experimental date 2018-3-13 score Instructor Shan Department of Soft College professional embedded + soft-embedded grade 2017 Frequency (1) name Schhao Yang School number 20161334026

First, the purpose of the experiment
    • familiar with C + + program development environment, experience the steps and methods of writing and running a simple C + + program using devc++, Code::Blocks, vs2017.
    • Master the basic methods of data input and output in C + +
    • Statements that master branching structures and looping structures
II. Preparation of the experiment

Before the experiment, please study the content in combination with teaching material and web search.

    • Development environment Use
      • Steps for writing and running C + + programs in devc++
      • Steps for writing and running C + + programs in Code::Blocks
      • Steps for writing and running C + + programs in vs2017
    • Simple C + + program structure reading, learning materials "2.1.3 C + + program examples"
    • Basic methods of data input and output in C + + read and learn 2.3 sections, learn basic usage of I/O flow, predefined caret < > in C + + <和提取符> .
    • Use of the IF statement, switch statement, while statement, Do...while statement
      In conjunction with example 2-4 and example 2-6, understand the simple algorithm behind the example and the switch statement, break statement, Do...while statement involved.
Iii. contents of the experiment
    • Validation experiments
      • Devc++, code::blocks, vs2017 software download and installation See course e-mail → file Center under "Software download URL." pdf"
      • Write and run the textbook example 2-1 in the C + + program development environment (Devc++, Code::Blocks, vs2017). Understand the simple C + + program structure and how to write and run it.
      • Run the textbook example 2-4 to understand the use of the switch statement and the break statement involved.
      • Run the textbook example 2-6 to understand the arithmetic expressions involved and the use of circular statements.
    • Programming exercises
      • Reference textbook example 2-4, programming implementation: Input 1~7 Integer, if the input is a delivery, then output "workday." Let's work hard "; If you enter 6~7, the output is" weekend. Let ' s has a rest. "
      • Textbook Example 2-6, 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, and the program is programmed to implement 563 as a total output of a number. )
Iv. conclusion of the experiment
    • Programming exercises (1) source code and running results
      • Code:

        #include<bits/stdc++.h>#define workday() cout<<"Workday. Let's work hard."<<endl;#define weekend() cout<<"Weekend. Let's have a rest."<<endl;using namespace std;int main(){     int day;  cin>>day;  switch (day)  {  case 1:workday();break;  case 2:workday();break;  case 3:workday();break;  case 4:workday();break;  case 5:workday();break;  case 6:weekend();break;  case 7:weekend();break;  default:puts("Wrong Number!\n");break;  }  return 0;}
      • Screenshot:

    • Programming exercises (2) source code and running results
      • Code1:

        #include<bits/stdc++.h>using namespace std;int main(){  int num,ans=0;  cin>>num;  do{  ans=ans*10+num%10;  num/=10;  }while(num);  cout<<ans;  return 0;}
      • Screenshot:

Five, the experiment summary and experience
    • The biggest problem encountered in this experiment is the use of markdown language, the native syntax does not support underscores, cannot define a two-level ordered list, code indentation cannot be represented ... After searching, these problems have been solved by using the

      123
    • The method used in programming experiment 2 has insufficient processing on big data, can be solved by string, and the time efficiency is also lower, with code:
      • Code:

        #include<bits/stdc++.h>using namespace std;string work_stl(string num){  while (num[num.length()-1]=='0')  num=num.substr(0,num.length()-1);  return num==""?"0":num;}int main(){  string num;  cin>>num;  num=work_stl(num);  reverse(num.begin(),num.end());  cout<<num;  return 0;}
      • Screenshot:

[0311] C + + Simple programming-1

Related Article

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.