Question: #include using namespace std; #include Monitor.h int main() { // create Monitor by passing width, height and ppi values Monitor mon(1920,1080,70); // set brand and
#include using namespace std; #include "Monitor.h" int main() { // create Monitor by passing width, height and ppi values Monitor mon(1920,1080,70); // set brand and model of hte monitor mon.setBrand("Acer"); mon.setModel("H243H"); // Monitor.h #ifndef MONITOR_H #define MONITOR_H #include using namespace std; class Monitor{ private: string brand; string model; int width; int height; int ppi; double refreshRate; char speakers; int ports; string portType; public: // default Constructor with no parameters will initialize all numeric variables to 0. Monitor(); Monitor(int,int,int); // Destructor ~Monitor(); // setters of Monitor void setBrand(string br); void setModel(string mod); void setWidth(int wid); void setHeight(int height); void setPpi(int ppi); void setRefreshRate(double refreshRate); void setSpeakers(char speakers); void setPorts(int ports); void setPortType(string portType); // getters of Monitor string getBrand(); string getModel(); int getWidth(); int getHeight(); int getPpi(); double getRefreshRate(); char getSpeakers(); int getPorts(); string getPortType(); double getScreenSize(); void listMonitor(); }; #endif Monitor.cpp
#include "Monitor.h" #include
// default Constructor with no parameters will initialize all numeric variables to 0. Monitor :: Monitor(){ brand = "Generic"; model = "Basic"; width = 0; height = 0; ppi = 0; refreshRate = 60; speakers = 'N'; ports = 1; portType = "HDMI"; } Monitor :: Monitor(int wt,int ht,int pi){ brand = "Generic"; model = "Basic"; width = wt; height = ht; ppi = pi; refreshRate = 60; speakers = 'N'; ports = 1; portType = "HDMI"; } // Destructor Monitor :: ~Monitor(){ }
// setters of Monitor void Monitor :: setBrand(string br) { brand = br; } void Monitor :: setModel(string mod) { model = mod; } void Monitor :: setWidth(int wid) { width = wid; } void Monitor :: setHeight(int height) { height = height; }
void Monitor :: setPpi(int ppi) { ppi = ppi; }
void Monitor :: setRefreshRate(double refreshRate) { refreshRate = refreshRate; }
void Monitor :: setSpeakers(char speakers) { speakers = speakers; }
void Monitor :: setPorts(int ports) { ports = ports; }
void Monitor :: setPortType(string portType) { portType = portType; }
// getters of Monitor string Monitor :: getBrand() { return brand; } string Monitor ::getModel() { return model; } int Monitor :: getWidth() { return width; } int Monitor :: getHeight() { return height; } int Monitor :: getPpi() { return ppi; } double Monitor :: getRefreshRate() { return refreshRate; } char Monitor :: getSpeakers() { return speakers; } int Monitor :: getPorts() { return ports; } string Monitor :: getPortType() { return portType; }
// find the diagonal double Monitor :: getScreenSize(){ // sqrt(w*w + h*h) double p = pow(width,2) + pow(height,2); return sqrt(p); }
// display the monitor void Monitor :: listMonitor(){ cout << "Brand: " << brand << ",Model: " << model <<",Screen size (pixels) " << width << "x" << height << " @ " << ppi <<"ppi, (diagonal) " << getScreenSize() << endl; }
Instructions:
1) Code main() function and name it getMonitors.cpp.
2) Instantiate an Acer object of the Monitor class and set width and height as 1920 x 1080, Brand as Acer, Model as H243H, and ppi as 70, 1 HDMI port, 60Hz refresh rate. Call the functions to calculate the Screen Size and write the output listing. Output should be:
Brand: Acer,Model: H243H,Screen size (pixels) 1920x1080 @ 70ppi, (diagonal) "result of getScreenSize"
3) Instantiate a Sony object of the Monitor class and set width and height as 1440 x 980, Brand as Sony, Model as VX200, and ppi as 72, 1 HDMI port, 60Hz refresh rate. Call the functions to calculate the Screen Size and write the output listing the Sony monitor.
Brand: Sony,Model: VX200,Screen size (pixels) 1440x980@ 72ppi, (diagonal) "result of getScreenSize"
4) Upload the getMonitors.cpp.
***** I have uploaded Monitor.h and Monitor.cpp and provide me the answer with two outputs
Brand: Acer,Model: H243H,Screen size (pixels) 1920x1080 @ 70ppi, (diagonal)
Brand: Sony,Model: VX200,Screen size (pixels) 1440x980@ 72ppi, (diagonal)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
