Question
*****C++, Please add comment on the program to help me understand. I have attached program for Stereo Receiver class, and we are supposed to add
*****C++, Please add comment on the program to help me understand.
I have attached program for Stereo Receiver class, and we are supposed to add some more data to it (below it the details)
*****Here is the instruction
Modify the Stereo Receiver class created in Module 1. If the user attempts to create or modify a stereo receiver object when any of the values passed are invalid, an invalid argument exception should be thrown with appropriate text:
- Manufacturer, Model, or Serial Number not provided
- Inappropriate values for Wattage, Number of Channels, Band , Frequency , Volume, or Power
The constructor and mutator methods should throw invalid parameter exceptions if invalid parameters are provided.
Create a program that utilizes this class to create and display stereo receivers based on user input. Utilize try-catch blocks to validate the user input. Ensure that the exception thrown includes appropriate text to describe the problem (e.g. Invalid Value volume cannot exceed 10 or Invalid Frequency). Demonstrate usage of the class and its embedded exception handling in a program that prompts users for initial values, creates a receiver object, and then prompts the user to change the various values.
*******Here is the program ( Please highlight or use different font or mention the lines of the added code to help me get it easily. TY :)
#include
#include
#include
using namespace std;
class StereoReceiver{
private:
string manufacturer;
string model;
string srlNo;
float wattage;
int noOfChannels;
string band;
float frequency;
int volume;
bool power;
public:
StereoReceiver(string manufacturer, string model, string srlNo, float wattage, int noOfChannels){
this->manufacturer = manufacturer;
this->model = model;
this->srlNo = srlNo;
this->wattage = wattage;
this->noOfChannels = noOfChannels;
this->power = false;
this->band = \"FM\";
this->volume = 0;
this->frequency = 0;
}
//manufacturer
string getManufacturer(){
return this->manufacturer;
}
void setManufacturer(string manufacturer){
this->manufacturer = manufacturer;
}
//model
string getModel(){
return this->model;
}
void setModel(string model){
this->model = model;
}
//serial No
string getSerialNo(){
return this->srlNo;
}
void setSerialNo(string srlNo){
this->srlNo = srlNo;
}
//wattage
float getWattage(){
return this->wattage;
}
void setWattage(float wattage){
this->wattage = wattage;
}
//No of channels
int getNoOfChannels(){
return this->noOfChannels;
}
void setNoOfChannels(int noOfChannels){
this->noOfChannels = noOfChannels;
}
//band
string getBand(){
return this->band;
}
void setBand(string band){
this->band = band;
}
//frequency
float getFrequency(){
return this->frequency;
}
void setFrequency(float freqeuncy){
this->frequency = freqeuncy;
}
//volume
int getVolume(){
return this->volume;
}
void setVolume(int volume){
this->volume = volume;
}
//power
void powerOn(){
this->power = true;
}
void powerOff(){
this->power = false;
}
bool getPowerStatus(){
return this->power;
}
};
int getIntegerInput(){
int n;
cin>>n;
while(!cin || cin.fail()) {
cin.clear(); // reset failbit
cin.ignore(std::numeric_limits::max(), ' ');
cout\"input>
cin>>n;
}
return n;
}
float getFloatInput(){
float n;
cin>>n;
while(!cin || cin.fail()) {
cin.clear(); // reset failbit
cin.ignore(std::numeric_limits::max(), ' ');
cout\"input>
cin>>n;
}
return n;
}
int getVolume(){
int volume;
volume = getIntegerInput();
while(volume 10){
cout\"volume>
volume = getIntegerInput();
}
return volume;
}
int main() {
string manufacturer , model,srlNo,band;
int noOfChannels,volume;
float wattage, frequency;
cout\"please>
cout\"manufacturer:>
cin >>manufacturer;
cout\"model:>
cin >> model;
cout\"serial>
cin>>srlNo;
cout\"wattage:>
wattage = getFloatInput();
cout\"no>
noOfChannels = getIntegerInput();
StereoReceiver reciever(manufacturer,model,srlNo,wattage,noOfChannels);
cout\"displaying>
cout
cout
cout
cout
cout\"no>
cout\"switching>
reciever.powerOn();
cout\"is>
cout\"caliberating>
cout\"adjust>
volume = getVolume();
reciever.setVolume(volume);
cout\"adjust>
frequency = getFloatInput();
reciever.setFrequency(frequency);
cout
cout\"volume>
cout\"frequency>
cout\"switching>
reciever.powerOff();
cout\"is>
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started