Imagine a class of TV with data members Name, brand, model and price. Give appropriate data types of data members. Write the following functions in this use case scenario.
· Display function for all members and write this function outside of the class
· Add three of constructors as discussed in class
· Add destructor
· Write setter and getter
· Create object and call the function accordingly
· All inputs should be user runtime inputs
#include <iostream>
using namespace std;
class TV
{
private:
string name;
string brand;
char model[15];
double price;
public:
TV() {};
TV(string _name, string _brand, char* _model, double _price)
{
name = _name;
brand = _brand;
strcpy_s(model, _model);
price = _price;
}
TV(const TV& tv)
{
name = tv.name;
brand = tv.brand;
strcpy_s(model, tv.model);
price = tv.price;
}
string getTVname();
string getTVbrand();
char* getTVmodel();
double getTVprice();
void setTVname();
void setTVbrand();
void setTVmodel();
void setTVprice();
void displayInfo();
~TV() {};
};
string TV::getTVname() { return name; }
string TV::getTVbrand() { return brand; }
char* TV::getTVmodel() { return model; }
double TV::getTVprice() { return price; }
void TV::setTVname()
{
cout << "Enter TV name: ";
cin >> name;
}
void TV::setTVbrand()
{
cout << "Enter TV brand: ";
cin >> brand;
}
void TV::setTVmodel()
{
cout << "Enter TV model: ";
cin >> model;
}
void TV::setTVprice()
{
cout << "Enter TV price: ";
cin >> price;
}
void TV::displayInfo()
{
cout << "\nTV Name: " << name << "\n";
cout << "TV Brand: " << brand << "\n";
cout << "TV Model: " << model << "\n";
cout << "TV Price: " << price << "\n";
}
int main()
{
TV tv1;
TV tv2;
tv1.setTVname();
tv1.setTVbrand();
tv1.setTVmodel();
tv1.setTVprice();
tv1.displayInfo();
tv2 = tv1;
tv2.displayInfo();
return 0;
}
Comments
Leave a comment