VISION is a world leader in manufacturing LCD Televisions. The company has decided that it will allow its customers to give the dimensions of the TV (in length and width).Using in c++.
Create a class called vision
Create three constructors as follows:
A default constructor that calls the setlength( ) and setwidth( ) function.
A parameterized constructor that will receive the length and width as integers
A parameterized constructor that will receive the length and width in float
By using a special function calculate the area of the TV
Create a function to calculate the price of the TV by multiplying the area with Rs. 65.
Create a display( ) function to show the details of the purchased TV.
In the main you will construct three objects that demonstrate the use of the three constructors. After calling the constructor it will take over and will handover control to the area function, and then the price calculation function.
#include<iostream>
using namespace std;
class Vision
{
float length;
float width;
float area;
float price;
public:
//Default constructor
Vision()
{
cout << "\nDefault constructor:\n";
setLength();
setWidth();
calcArea();
priceCalculate(65);
}
//Parametrized constructor with integers
Vision(int _length, int _width):length(_length), width(_width)
{
cout << "\nInt constructor:\n";
calcArea();
priceCalculate(65);
}
//Parametrized constructor with floats
Vision(float _length, float _width) :length(_length), width(_width)
{
cout << "\nFloat constructor:\n";
calcArea();
priceCalculate(65);
}
void setLength()
{
cout << "Please, enter a length: ";
cin >> length;
}
void setWidth()
{
cout << "Please, enter a width: ";
cin >> width;
}
void calcArea()
{
area=length*width;
}
void priceCalculate(int cost)
{
price=cost*area;
}
void Display()
{
cout << "Info about purchased TV: "
<< "\nLength = \t" << length
<< "\nWidth = \t" << width
<< "\nArea = \t\t" << area
<< "\nPrice = \t" << price << endl;
}
};
int main()
{
Vision a;
a.Display();
Vision b(30,50);
b.Display();
Vision c((float)35.765, 67.34);
c.Display();
}
Comments
Leave a comment