Answer to Question #185883 in C++ for Laiba

Question #185883

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-26T16:18:10-0400
#include <iostream>
using namespace std;
class SONY_TV{
    float length, width, area, price;
    public:
    SONY_TV(){
        cout<<"default constructor called\n";
        length = 16;
        width = 32;
    }
    SONY_TV(float w, float l){
        cout<<"parameterized constructor called\n";
        width = w;
        length = l;
    }
    friend float Area(const SONY_TV &);
    float Price(){
        area = Area(*this);
        price = area * 100;
        return price;
    }
    void show(){
        cout<<"Length: "<<length<<endl;
        cout<<"Width: "<<width<<endl;
        cout<<"Area: "<<area<<endl;
        cout<<"Price: "<<price<<endl;
    }
};
float Area(const SONY_TV &a){
    return a.length * a.width;
}
int main(){
    SONY_TV tv1; //default constructor called
    cout<<"Area of tv1: "<<Area(tv1)<<endl;
    cout<<"Price of tv1: "<<tv1.Price()<<endl;
    SONY_TV tv2(63, 20); //parameterized constructor called
    cout<<"Area of tv2: "<<Area(tv2)<<endl;
    cout<<"Price of tv2: "<<tv2.Price()<<endl;
    SONY_TV tv3; //default constructor called
    cout<<"Area of tv3: "<<Area(tv3)<<endl;
    cout<<"Price of tv3: "<<tv3.Price()<<endl;
    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