“Data Structure” Experiment 1: Flexible Using the VC Programming Tool

. Experimental content

1. Design a program with a single file structure 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.

 # include 

using namespace std;

 

template 

T1 and(T1 x,T1 y)

{

T1 sum;

sum = x + y;

return sum;

}

 template 

T1 and1(T1 x, T1 y)

{

T1 sum;

sum = x * y;

return sum;

}

int main()

{

int x=3, y=2;

double x1=3.3, y1=2.2;

    double sum2, sum3;

int sum, sum1;

 

sum=and(x ,y); sum2=and(x1 ,y1);

cout<<"sum= "<

Run results

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4993 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.