Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please modify the c++ code (given below) to using the requirements below . More Types of Radios Create a new class called PioneerAM. This class

please modify the c++ code (given below) to using the requirements below

. More Types of Radios Create a new class called PioneerAM. This class will inherit from PioneerCarRadio. o PioneerAM behaves like PioneerCarRadio except that it operates in the AM band only! o There is no ability to change to the FM band they shouldnt even display the FM band o Do this by overriding the appropriate methods that are in the parent class or grandparent class. Create a new class called PioneerWorld. This class will inherit from PioneerAM. o PioneerWorld behaves like PioneerAM ? Except that the AM band range is 531 kHz to 1602 kHz ? And the interval between frequencies is 9 kHz, not 10 kHz ? So scanning up from 531 would bring you to 540, then 549, etc. Wrapping from 1602 brings you to 531. o Do this by overriding the appropriate methods that are in the parent class or grandparent class. New/Delete and Exceptions Create a new testHarness (i.e. your main()) and put it in a file called ultimateRadio.cpp. In this main o Change your PioneerCarRadio variable to be a pointer o Give it an initial value of NULL o Call this variable pRadio. When your program starts o You will need to create and call a function named createRadio() that takes a string (or char pointer your choice) to determine which type of radio you want to start with and returns a pointer to that radio back to main() and into the pRadio pointer. ? Your program will need to get this string (or char pointer) from the command line arguments of the program ? This means you needs to take in and parse command-line arguments ? This function will exist in the ultimateRadio.cpp file and when passed the string (or char pointer) will ? If the program is started with the runtime switch of car then instantiate a new PioneerCarRadio object and return it to assign it to pRadio. ? If the program is started with the runtime switch of am then instantiate a new PioneerAM object and return it to assign it to pRadio. ? If the program is started with the runtime switch of world then instantiate a new PioneerWorld object and return it to assign it to pRadio. ? Otherwise, throw an exception. ? Remember you will need to write this createRadio() function o Since it will be throwing exception(s), remember to put the call to createRadio() in a try block o Remember that you will initially be getting this functions parameter from a command line argument o In the catch clause, print an error message and quit the program o Make sure to instantiate each radio in an off state Whenever you use new, use the principles discussed in class to handle this correctly. o You are required to use the new new in this assignment o Use exception handling to detect out-of-memory situations Virtual Functions In order to implement these 2 new children classes, you will once again need to override some methods Make any overridden methods virtual in the parent class o Recommendations: ToggleFrequency(), ScanUp(), ScanDown(). Since we are using virtual functions, remember best practices and make all destructors virtual Switching Radios and Quitting the Program Each specialized radio class needs to tell the user who they are o The PioneerCarRadio already does with the Pioneer XS440 that appears in its output o Make the PioneerAM class say Pioneer XS440-AM o And the PioneerWorld class say Pioneer XS440-WRLD Create a destructor for each new class o In each destructor, simply print a message stating which radio is being destroyed o e.g. "Destroying Pioneer XS440-WRLD Radio" The output from PioneerCarRadio, PioneerAM and PioneerWorld is somewhat the same except for the difference in its name (i.e. the first line of output) and the presence/absence of the FM band o Try to think of a clever way to implement this radio name idea o Perhaps by adding a data member to one of the classes to hold the name hmmm Each radio instance that is created, will run until the 'x' key is pressed within that instance o This means that each of the Pioneer classes shares the same input processing ? As developed in Assign-03 o Once an x key is pressed, the radio object is destroyed in the ultimateRadio.cpp source o And do nothing until the user presses one of the following keys ? c -- to create and run a new PioneerCarRadio radio ? a -- to create and run a new PioneerAM radio ? w -- to create and run a new PioneerWorld radio ? x - to quit the program ? Note that these keystrokes will need to be captured and processed within your testHarness (where the new radio would be created) In Case It Makes Things Easier You can create mutators and accessors for whatever private data members you need to from the AmFmRadio class What Not To Do Don't put excessive amounts of the parent class's functionality (PioneerCarRadio) in the child classes (PioneerAM, PioneerWorld) unnecessarily o This is duplicating functionality and code a definite no-no

//////////////////////////////////////////////

//PioneerCarRadio.cpp

#include

#include

#include

#include "PioneerCarRadio.h"

/* -- Method Header Comment

Name : PioneerCarRadio -- CONSTRUCTOR

Purpose : Its purpose is to state the initial status of the car radio which is off(false)

Inputs : NONE

Outputs : NONE

Returns : Nothing

*/

PioneerCarRadio::PioneerCarRadio()

{

AmFmRadio(false);

}

/* -- Method Header Comment

Name : PioneerCarRadio -- destructor

Purpose : to destroy the PioneerCarRadio object

Inputs : NONE

Outputs : outputs a final message "Pioneer Car Radio destructed." from the object before being destroyed

Returns : Nothing

*/

PioneerCarRadio::~PioneerCarRadio()

{

printf("Pioneer Car Radio destructed.");

}

/* -- Method Header Comment

Name : ProcessKey

Purpose : it handles the controlling keystroke. if the keystroke represents valid action, print current state of radio

Inputs : key_val string It is used to entering valid keystroke values

Outputs : NONE

Returns : Nothing

*/

void PioneerCarRadio::ProcessKey(char key_val)

{

// to track whether to print state at the end of check

bool display = true;

switch (key_val)

{

case 'o':

{

PowerToggle();

break;

}

case '+':

{

int current_volume = GetVolume();

if (current_volume < 100) {

SetVolume(current_volume + 1);

};

break;

}

case '_':

{

int current_volume = GetVolume();

if (0 < current_volume) {

SetVolume(current_volume - 1);

};

break;

}

case '=':

{

ScanUp();

break;

}

case '-':

{

ScanDown();

break;

}

case 'b':

{

ToggleFrequency();

break;

}

case '1': case '2': case '3': case '4': case '5':

{

// if key_val is 1 to 5 this block will execute

// we use implicit type cast to get int from char.

int station_number_set = key_val - '1';

SelectCurrentStation(station_number_set);

break;

}

case '!': case '#': case '$': case '%':

{

// same logic. exception is that '@' isn't aligned with these 4 symbols

int station_number_choose = key_val - '!';

SetButton(station_number_choose);

break;

}

case '@':

{

SetButton(1);

break;

}

default:

// if no label was matched than wrong key was pressed

// suppress display in this case

display = false;

}

if (display)

{

DisplayState();

}

}

/* -- Method Header Comment

Name : DisplayState

Purpose : Its purpoe is to display current state of radio. output is different depending on power of radio

Inputs : NONE

Outputs : It displays the current state of the radio

Returns : Nothing

*/

void PioneerCarRadio::DisplayState()

{

if (GetRadioPower())

{

// print upper part of message

printf(" Pioneer XS440 ");

printf("Radio is on ");

printf("Volume: %d ", GetVolume());

printf("Current Station: %.1f %s ", GetCurrentStation(), GetBand());

// now print buttons

Freqs buttons[5];

// get buttons values

GetButtons(buttons);

printf("AM Buttons: ");

// i is 0 to 3 to avoid trailing comma and to add newline

for (int i = 0; i < 4; i++)

{

printf("%d: %d, ", i + 1, buttons[i].AMFreq);

}

printf("5: %d ", buttons[4].AMFreq);

// same for FM

printf("FM Buttons: ");

for (int i = 0; i < 4; i++)

{

printf("%d: %.1f, ", i + 1, buttons[i].FMFreq);

}

printf("5: %.1f ", buttons[4].FMFreq);

}

else

{

printf(" Pioneer XS440 Radio is off ");

}

}

//////////////////////////////////////////////////////////

//PioneerCarRadio.h

#include "AmFmRadio.h"

class PioneerCarRadio :

public AmFmRadio

{

public:

PioneerCarRadio();

~PioneerCarRadio();

// handle the controlling keystroke. if the keystroke represents valid action,

// print current state of radio

void ProcessKey(char key_val);

// display current state of radio. output is different depending on power of radio

void DisplayState();

};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

6-22. New budget figures

Answered: 1 week ago