Question 1 (35 marks) This question is based on contents covered in Chapter 10 o
ID: 3873359 • Letter: Q
Question
Question 1 (35 marks) This question is based on contents covered in Chapter 10 of text. The objectives of the questions are to: access if students have understood the basic concepts of object-oriented class write the class specification, constructor and methods write test driver to test the written methods e Examine the following class diagram, additional information and answer the questions that follow screenType: char screenSize: int resolution: string price: double standard: bool TV(char = 'L', int = 50, string="HD", double = 600, bool true setorder void display:void getPrice ) :double etStandard):bool; Method Remarks TV (char-'Lint 50, string "DConstructor with default values. The double-600, bool- true) positional arguments are screenType screenSize, resolution, price and standard. Set the data members accordingly. [Note: Screen type 'O stands for OLED and L stands for LCD. Screensize is can be "HD and "UHD" Assessor for data members, price and getPrice ) : double getstandard:bool: setorder :void Prompt the user to enter the screenType, screenSize and resolution. The default price S600 is for standard size (50 inch), screen type (LCD) and resolution(HD). If there is any change to standard values, set standard to false. If the screen Type is O add S300. If the screenSize is greater than 50 inch, add S20 for LCD TVs and $40 for OLED TVs for each additional inch. If the resulution is UHD, add $200 for LCD TVs and S400 for OLED TVs. Update the price Uses cout to display the respective data members. If standard is true, displays Standard TV".If standard is false display:voidExplanation / Answer
Here is the code for TV.h:
#include <iostream>
using namespace std;
class TV
{
char screenType;
int screenSize;
string resolution;
double price;
bool standard;
public:
TV(char screenType = 'L', int screenSize = 50, string resolution = "HD", double price = 600, bool standard = true);
void setOrder();
void display();
double getPrice();
bool getStandard();
};
And the code for TV.cpp is:
#include "TV.h"
TV::TV(char screenType, int screenSize, string resolution, double price, bool standard)
{
this->screenType = screenType;
this->screenSize = screenSize;
this->resolution = resolution;
this->price = price;
this->standard = standard;
}
double TV::getPrice() { return price; }
bool TV::getStandard() { return standard; }
void TV::setOrder()
{
cout << "Enter screen type: ";
cin >> screenType;
cout << "Enter screen size: ";
cin >> screenSize;
cout << "Enter resolution: ";
cin >> resolution;
if(screenType != 'L' || screenSize != 50 || resolution != "HD")
standard = false;
if(screenType == 'O')
price += 300;
if(screenSize > 50)
{
if(screenType == 'L')
price += 20 * (screenSize - 50);
else
price += 40 * (screenSize - 50);
}
if(resolution == "UHD")
{
if(screenType == 'L')
price += 200;
else
price += 400;
}
}
void TV::display()
{
cout << "Screen Type: " << (screenType == 'L' ? "LCD" : "OLED") << endl;
cout << "Screen Size: " << screenSize << """ << endl;
cout << "Resolution: " << resolution << endl;
cout << "Price: $" << price << endl;
if(standard)
cout << "Standard TV" << endl;
else
cout << "Customised TV" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.