Answer to Question #185824 in C++ for najam malik

Question #185824

Sony TV Manufacturer want you to design a program that will help their customers to

check the price along with the dimensions for their products to be purchased. For this

Carefully read all the instructions and follow the requirements.

o Create a class called SONY_TV along with two constructors as follows:

o A Default constructor to set the length of TV.

o A parameterized constructor that will receive the width in float.

o By using a friend function calculate the area of the SonyTV

o Create a member function to calculate the price of the sony TV by multiplying the area

with Rs 100.

o Create a show( ) function to show the details of the purchased sony TV.

In the main you will construct three objects that will show the use of the two constructors. After

calling the constructor it will call the area function, and then the price calculation function.


1
Expert's answer
2021-04-27T13:12:13-0400
#include <iostream>
using namespace std;
//class define
class SONY_TV{
    //data member define
    private:
        float length;
        float width;

    //methods
    public:
        //default consturctor
        SONY_TV(){
            length=2;
            width=2;
        }
        //parametrise constructor
        SONY_TV(float len,float wid){
            length=len;
            width=wid;
        }
        //friend class
        float friend calculateArea(SONY_TV s);
        //function to calculate the area
        float calculatePrice(){
            return calculateArea(*this)*100;
        }
        //display the parameters
        void show(){
            cout<<"Sony TV length: "<<length<<endl;
            cout<<"Sony TV width: "<<width<<endl;
            cout<<"Sony TV area: "<<calculateArea(*this)<<endl;
            cout<<"Sony TV price: "<<calculatePrice()<<"\n"<<endl;
        }
};


//friend function
float calculateArea(SONY_TV s){
    return s.width*s.length;
}
int main(){
    SONY_TV stv1;
    SONY_TV stv2(5,6);
    SONY_TV stv3(8,4);
    stv1.show();
    stv2.show();
    stv3.show();

    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