“Data Structure” experiment 1: Flexible use of VC programming tools

"Data Structure" Experiment 1: Flexible use of VC programming tools

One. .Experimental purpose

Review and consolidate the use of VC programming environment and C++ template design.

1. Review and master the VC single file structure program design process.

2. Review and master the VC multi-file engineering design process

3. Master the VC program debugging process.

4. Review C++ template and template programming.

Two. Experiment time

The second class in the second week. 2 class hours.

Three. Experimental content

1. Design a single-file structure program to input two numbers from the keyboard, and output the results of the “sum” and “product” of the two. The requirements are as follows:

1) Design functions to calculate “sum” and “product”, call them in the main function, and consider overloaded functions, so that both integers and decimals can be calculated.

2) Use single step debugging and breakpoint debugging to debug the program respectively. And many times to run and strive to be proficient in debugging methods.

2. Use function templates to achieve the above functions.

3. Use a class to achieve the above functions. Requirements:

1) Use class templates

2) Use multiple files: the declaration of the class is in the header file; the function definition of the class is in one source file and designed in the main program file The main function program outputs the result in the instantiation.

4. Reference materials

Experimental tutorial P159-170.

Source code

# include 
using namespace std;

int and(int x,int y)
{
int sum;
sum = x + y;
return sum;
}
int and1(int x, int y)
{
int sum1;
sum1 = x * y;
return sum1;
}
float and(float x,float y)
{
float sum;
sum = x + y;
    return sum;

}
float and1(float x,float y)
{
float sum1;
sum1 = x * y;
return sum1;
}
int main()
{int x,y,sum,sum1;
    float x1,y1,sum2,sum3;
cout<<"Please input two numbers :"<>x; cin>>y;

    sum=and(x, y );
    sum1=and1( x, y );

cout <<" sum= "< 

Leave a Comment

Your email address will not be published.