Answer to Question #185956 in C++ for saad

Question #185956

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-26T17:18:00-0400
#include <iostream>

using namespace std;


//define the class SONY_TV
class SONY_TV{
    //define the data members
    private:
	    float length;
	    float width;
	    
	//methods
    public:
        //define the default constructor
    	SONY_TV(){
    		length=2;
    		width=2;
    	}
    	// define the parameterized constructor
    	SONY_TV(float len,float wid){
    		length=len;
    		width=wid;
    	}
    	//declare the friend function
    	float friend calculateArea(SONY_TV s);
    	//define function to calculate area
    	float calculatePrice(){
    		return calculateArea(*this)*100;
    	}
    	//define function to diaplay length, width, area and price
    	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;
    	}
};


//define the friend function
float calculateArea(SONY_TV s){
	return s.width*s.length;
}


int main(){  
	SONY_TV t1;
	SONY_TV t2(4,5);
	SONY_TV t3(6,3);
	t1.show();
	t2.show();
	t3.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