A simple c + + program (Experiment 1)

1, Purpose and requirements of the experiment:

1. Familiar with the common functions of Visual c++6.0 compiling system;

2. Learn how to use Visual C++6.0 to compile simple c + + programs;

3. Familiar with the basic structure of c + + program, learn to use simple input / output operation;

2, Experimental contents and results:

1,

  1. (1)//sy1_1.pp  
  2. main(){  
  3.     cout<<"this is a program.";  
  4. }  
Error message:


Correction experiment:

Scenario 1:

  1. //sy1_1.pp  
  2. #include<iostream>  
  3. using namespace std;  
  4. main(){  
  5.   
  6.     cout<<"this is a program.";  
  7.     return 0;  
  8. }  

Option two:

  1. //sy1_1.pp  
  2. #include<iostream>  
  3. main(){  
  4.   
  5.   
  6.     std::cout<<"this is a program.";  
  7.     return 0;  


Experimental results:



  1. //sy1_2.pp <2>  
  2. #include<iostream>  
  3. using namespace std;  
  4. main(){  
  5.     cin>>x;  
  6.     int y=x*x;  
  7.     cout<<"y=<<y<<\n";  
  8.     return 0;  
  9. }  

Error message:


Correction experiment:

  1. //sy1_2.pp <2>  
  2. #include<iostream>  
  3. using namespace std;  
  4. main(){  
  5.     int x;  
  6.     cin>>x;  
  7.     int y=x*x;  
  8.     cout<<"y=<<y<<\n";  
  9.     return 0;  
  10. }  

Experimental results:



  1. //sy1_3.pp <3>  
  2. #include<iostream>  
  3. using namespace std;  
  4. main(){  
  5.     int a,b;  
  6.     a=7;  
  7.     int s=a+b;  
  8.     cout<<"a+b="<<s<<endl;  
  9. return 0;  
  10. }  

Error message:


Correction experiment:

  1. //sy1_3.pp <3>  
  2. #include<iostream>  
  3. using namespace std;  
  4. main(){  
  5.     int a,b;  
  6.     a=7;  
  7.     b=0;  
  8.     int s=a+b;  
  9.     cout<<"a+b ="<<s<<endl;  
  10. return 0;  
  11. }  
Experimental results:
  1.   
  1.   

2,

  1. #include<iostream>  
  2. using namespace std;  
  3. main(){  
  4. int the_number;  
  5. cout<<"Please enter an integer;";  
  6. cin>>tne_number  
  7. return 0;  
  8. }  

3, Experiment summary:

This experiment simply reviewed the basic operation steps and error correction of the previous C language, learned from the past, learned the fun of C language, realized the deepening and simple type of C + +, simple and clear operation, reduced error rate, practice out the truth, master a computer language is really interesting.

Tags: C

Posted on Sun, 05 Apr 2020 11:57:47 -0700 by miha