Answer to Question #274026 in C++ for William

Question #274026

1. Write a program in C++ to create abstract class Figure having abstract method area(), and data members length, breadth. Derive classes Triangle and Rectangle from Figure having member function area(). Find area of triangle and rectangle by function overriding concept? [Note: sub classes does not contain any data members]. 


2. Write a program in C++ to justify the control flow and use of templates by mentioning overloaded function as well.


1
Expert's answer
2021-12-01T18:38:16-0500


SOLUTION CODE


//Function overloading by use of templates
#include <iostream>
using namespace std;


//function called square_of_a_number taking int as a parameter
void square_of_a_number(int my_number)
{
	cout << "Square of " << my_number<< " is " << my_number * my_number<< endl;
}


//function called square_of_a_number taking double as a parameter
void square_of_a_number(double my_number)
{
	cout << "Square of " << my_number<< " is " << my_number * my_number<< endl;
}


// Driver Code
int main()
{
	// Function Call for integer value
	square_of_a_number(12);


	// Function Call for double value
	square_of_a_number(5.5);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS