Answer to Question #274025 in C++ for gikovi

Question #274025

Q1. Overload the function find_perimeter() with one, two and three float parameters. The function with one parameter is used to return the perimeter of the circle. The function with two parameters is used to return the perimeter of the rectangle. The function with three parameter s is used to return the perimeter of the triangle. Write the necessary C++ program to test the functionality of above functions.


Q2. Create a class Data with data members: height and breadth of object given by the user and member functions get_data() to read the values and put_data() to display the values. Create another class Rectangle that inherits class Data and implement its methods areaRectangle() and perimeterRectangle() that computes the area and perimeter of a rectangle. Create another class Triangle that inherits class Data and implement its methods areaTriangle() and perimeterTriangle() that computes the area and perimeter of a triangle.


1
Expert's answer
2021-12-01T06:40:18-0500

Q1. Overload the function find_perimeter() with one, two and three float parameters. The function with one parameter is used to return the perimeter of the circle. The function with two parameters is used to return the perimeter of the rectangle. The function with three parameter s is used to return the perimeter of the triangle. Write the necessary C++ program to test the functionality of above functions.

#include<iostream>
#include<conio.h>
using namespace std;
const float pi=3.14;
float perimeter(float n,float b,float h)
{
float perimeter;
perimeter=n*b*h;
return perimeter;
}
float perimeter(float r)
{
float perimeter;
perimeter=2*pi*r;
return perimeter;
}
float perimeter(float l,float b)
{
float perimeter;
perimeter=2*(l*b);
return perimeter;
}
int main()
{
float b,h,r,l;
float result;
cout<<" \nEnter the Base and Hieght of Triangle:";
cin>>b>>h;
result=perimeter(0.5,b,h);
cout<<"perimeter of Triangle:"<<result<<endl;
cout<<"\nEnter the Radius of Circle: ";
cin>>r;
result=perimeter(r);
cout<<"\nperimeter of Circle: "<<result<<endl;
cout<<"\nEnter the Length & Bredth of Rectangle: ";
cin>>l>>b;
result=perimeter(l,b);
cout<<"\nperimeter of Rectangle: "<<result<<endl;
getch();
}

Q2. Create a class Data with data members: height and breadth of object given by the user and member functions get_data() to read the values and put_data() to display the values. Create another class Rectangle that inherits class Data and implement its methods areaRectangle() and perimeterRectangle() that computes the area and perimeter of a rectangle. Create another class Triangle that inherits class Data and implement its methods areaTriangle() and perimeterTriangle() that computes the area and perimeter of a triangle.


#include<iostream>
using namespace std;
class Rectangle
{
     private:
        float length ; // This can't be inherited
     public:
        float breadth ; // The data and member functions are inheritable
        void Enter_lb(void)
        {
               cout << "\n Enter the length of the rectangle : "; 
                     cin >> length ;
               cout << "\n Enter the breadth of the rectangle : ";            
               cin >> breadth ;
        }
        float get_l(void)
        {      return length ; } 
};  // End of the class definition

class Rectangle1 : public Rectangle   
{      
     private:
        float area ;
      public:
        void Rec_area(void)
        {  area = get_l( ) * breadth ;  } 
        // area = length * breadth ;  can't be used here
void Display(void)
     {
       cout << "\n Length = " << get_l( ) ; // Object of the derived class can't
              //    inherit the private member of the base class. Thus the member
              //   function is used here to get the value of data member 'length'.
       cout << "\n Breadth = " << breadth ;
       cout << "\n Area = " << area  ;
     }
};  // End of the derived class definition D
int main()
{
        Rectangle1 r1 ;
        r1.Enter_lb( );
        r1.Rec_area( );
        r1.Display( );
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