Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this C++ programming assignment thanks. I have provided some partial code at the bottom but I need to add some

Can someone help me with this C++ programming assignment thanks. I have provided some partial code at the bottom but I need to add some functions listed below. I have to create two different classes.

The assignment consists of the construction of 2 new classes to work with the driver file. You need to create a CPU.h file that declares all instance variables and functions of the class CPU, and a CPU.cpp file that implements all the functions of the class CPU. You also need to create a Computer.h file that declares all instance variables and functions of the Computer class, and a Computer.cpp file that implements all functions of the class Computer.

CPU CLASS

The CPU class describes the cpu of a computer. It has the following attributes and should be declared using private: type(string) and speed (int). All functions should be declared using public. The following constructor should be provided to initialize each attribute:

CPU() This constructor initializes type to "?" and speed to 0.

The destructor ~CPU() should be provided to display the following:

CPU with the type Pentium2 and the speed 200 is being destroyed. where Pentium2 is a value the variable type contains and 200 is a value that the variable speed contains.

The following accessor functions should be provided to get the attributes:

string getType()

int getSpeed()

The following modifier(mutator) functions should be provided to set the attributes:

void setType(string type)

void setSpeed(int speed)

The following function must be defined:

void printInfo() This should display the following: Pentium2,200HZ where Pentium2 is a CPU type and 200 is a CPU speed.

Computer Class:

The Computer class describes a computer that a customer can buy. It must have the following attributes and they are private: brandName (string), cpu( CPU *), memory(int), price (double)

The functions in the Computer class should be declared with public. The following constructor should be provided to initialize each attribute:

Computer() This constructor initializes all strings to "?", all integers to 0, and all double to 0.0 and allocates memory for the pointer of CPU (i.e., call the constructor of the CPU class).

The destructor ~Computer() should be provided to display the following:

The computer IBM is getting destroyed. where IBM is a value that the variable brandName contains. The destructor also should free the memory of the pointer cpu. The following accessor functions should be provided to get the attributes:

string getBrandName()

CPU * getCPU()

int getMemory()

double getPrice()

The following mutator functions should be provided to change the attributes:

void setBrandName(string BrandName)

void setCPU(string cpuType, int cpuSpeed)

void setMemory(int memoryAmount)

void setPrice(double price)

The following function must be defined:

void printInfo() This function should print a string of the following format:

BrandName:\tDell

CPU:\t\tpentium3,500HZ

Memory:\t\t398M

Price:\t\t$1390.00

The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main function should start by displaying the following menu in this exact format:

Choice\t\tAction

------\t\t------

A\t\tAdd Computer

D\t\tDisplay Computer

Q\t\tQuit

?\t\tDisplay Help

Next, the following prompt should be displayed: What action would you like to perform? Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase. Add Computer Your program should display the following prompt:

Please enter the computer information: Enter a brand name: Read in the user input and set the brand name on the computer object.

Then the following prompt: Enter a computer price: Read in the user input and set the price on the computer object.

Then the following prompt: Enter a computer memory: Read in the user input and set the memory on the bank object.

Then the following prompt: Enter a cpu type: Read in the user input.

Then the following prompt: Enter a cpu speed: Read in the user input and set the cpu type and the speed on the computer object. There is only one Computer pointer in this assignment. Thus when "Add Computer" option is selected more than once, the new one overwrites the old Computer data.

Display Computer

BrandName:\tDell

CPU:\t\tpentium3,500HZ

Memory:\t\t398M

Price:\t\t$1390.00

Make use of the printInfo function of the Computer class to display this information. Quit Your program should free the memory of the pointer to Computer and stop executing, free the memory of the pointer to Computer. Display Help Your program should redisplay the "choice action" menu. Invalid Command If an invalid command is entered, display the following line: Unknown action

Here is the given code:

#include

#include

#include

#include "CPU.h"

#include "Computer.h"

using namespace std;

void printMenu();

int main()

{ // local variables, can be accessed anywhere from the main method

char input1 = 'Z';

string inputInfo;

string brandName;

double price;

int memory;

string cpuType;

int cpuSpeed;

string line;

// allocate memory for the pointer of the Computer

Computer * computer1 = new Computer();

printMenu();

do // will ask for user input

{ cout << "What action would you like to perform? ";

input1 = getchar();

input1 = toupper(input1);

// matches one of the case statement

switch (input1)

{ case 'A': //Add Computer

cout << "Please enter the computer information: ";

cout << "Enter a brand name: ";

cin >> brandName;

computer1->setBrandName(brandName);

cout << "Enter a computer price: ";

cin >> price; computer1->setPrice(price);

cout << "Enter a computer memory: ";

cin >> memory; computer1->setMemory(memory);

cout << "Enter a cpu type: ";

cin >> cpuType;

cout << "Enter a cpu speed: ";

cin >> cpuSpeed;

computer1->setCPU(cpuType, cpuSpeed);

break;

case 'D': //Display computer

computer1->printInfo();

break;

case 'Q': //Quit

delete computer1;

break;

case '?': //Display Menu

printMenu();

break;

default:

cout << "Unknown action ";

break;

}

getchar(); //to flush ' '

} while (input1 != 'Q');

return 0;

}

/** The method printMenu displays the menu to a user**/

void printMenu()

{

cout << "Choice\t\tAction ";

cout << "------\t\t------ ";

cout << "A\t\tAdd Computer ";

cout << "D\t\tDisplay Computer ";

cout << "Q\t\tQuit ";

cout << "?\t\tDisplay Help ";

}

Example OUTPUT

Choice Action

------ ------

A Add Computer

D Display Computer

Q Quit

? Display Help

What action would you like to perform?

A

Please enter the computer information:

Enter a brand name:

IBM

Enter a computer price:

1050

Enter a computer memory:

128

Enter a cpu type:

Pentium2

Enter a cpu speed:

200

What action would you like to perform?

D

BrandName: IBM

CPU: Pentium2,200HZ

Memory: 128M

Price: $1050.00

What action would you like to perform?

Q

CPU with the type Pentium2 and the speed 200 is being destroyed.

The computer IBM is getting destroyed.

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions