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.
#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;
}
Comments
Leave a comment