Question

Marks: 2.5 Due: Week 5 lab class Classes and Objects Create a PC class that contains the following members: A private data me

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given below is the code for the question.
Please do rate the answer if it helped. Thank you

#include <iostream>
#include <iomanip>
using namespace std;

class PC{
private:
double cpu_speed;
int ram_capacity;
int hd_capacity;
double cost;
public:
void input(){
do{
cout << "Enter CPU Speed (in GHz): ";
cin >> cpu_speed;
if(cpu_speed <= 0)
cout << "Invalid CPU Speed!" << endl;
}while(cpu_speed <= 0);

do{
cout << "Enter Hard Disk capacity (in TB): ";
cin >> hd_capacity;
if(hd_capacity <= 0)
cout << "Invalid Hard Disk Capacity!" << endl;
}while(hd_capacity <= 0);

do{
cout << "Enter RAM capacity(in GB): ";
cin >> ram_capacity;
if(ram_capacity <= 0)
cout << "Invalid RAM capacity!" << endl;
}while(ram_capacity <= 0);
}

double getCost(){
cost = 500 + cpu_speed * 100 + hd_capacity * 50 + ram_capacity * 10;
return cost;
}

void display(){
cout << setw(5) << cpu_speed << " GHz CPU, " << setw(5) << hd_capacity << " TB HD, ";
cout << setw(5) << ram_capacity << " GB RAM" << "\t $" << right << setw(8) << getCost() << endl;
}
};

int main(){
int n;
double total = 0;

do{
cout << "How many PCs? ";
cin >> n;
}while(n <= 0);

PC *pcs = new PC[n];
for(int i = 0; i < n; i++){
cout << "Enter details for PC " << (i+1) << endl;
pcs[i].input();
cout << endl;
}

cout << "No. of PCs ordered = " << n << endl;
cout << fixed <<setprecision(2);
for(int i = 0; i < n; i++){
pcs[i].display();
total += pcs[i].getCost();
}

cout << endl << "Total" << setw(45) << "$" << setw(8)<< total << endl;

delete[] pcs; //deallocate memory
}

HOw many PCs? 2 Enter details for PC 1 Enter CPU Speed (in GHz): 2.4 Enter Hard Disk capacity (in TB): 1 Enter RAM capacity(i

Add a comment
Know the answer?
Add Answer to:
Marks: 2.5 Due: Week 5 lab class Classes and Objects Create a PC class that contains...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please include comments in java Create a command line program that can be used for computer...

    Please include comments in java Create a command line program that can be used for computer inventory purposes Create a super class that will store the following data: CPU speed Amount of RAM Hard Disk size Operating System Allow the user to enter data using any units of measurement they desire (i.e. - 500GB or 1TB for hard disk size). Create a class that inherits from the previous class and stores information for a Windows based computer. Store the following...

  • C++ design a class named Technician that contains private data members to store the following: -technician's...

    C++ design a class named Technician that contains private data members to store the following: -technician's name (a string) - number of service calls - total time of all service calls - average service call time the technician class should also have the following public member functions: - a constructor function that initializes all data members by obtaining their values from the users. with the exception of the average service call time which will be calculated as: total_time/number_of_call - a...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Using your Games class, create an array of Games’ objects on the heap (three for the...

    Using your Games class, create an array of Games’ objects on the heap (three for the SIZE) and then pass the pointer that points to that array to a function that loads it up with the same info from part A. Print the array’s values using the pointer. Make sure the program properly uses the accessors and mutators. When completed the program should cleanup. //This is my Games class class Games { private: string gameName, gameType; float gameCost; public: //constructor...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • Question: Write the Main class code for the following application. The first three classes are given...

    Question: Write the Main class code for the following application. The first three classes are given below. Lottery This lottery app allows users to sign up for an account, choose a random number or two, and then win a certain amount of money if their chosen number matches the number that the game draws. The house keeps the cash proceeds if nobody wins. The app must repeatedly do the following: Allow the user to (1) Add Player Account (2) Play...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • (20 marks) Read the following scenario and write a report according to the requirements: The Company...

    (20 marks) Read the following scenario and write a report according to the requirements: The Company you work for is purchasing brand new desktop computers to replace the old outdated ones that it has had in its offices. A local distributor has been contacted, requesting specifications of the types of PCs they offer for businesses. They have responded providing specifications for two different types of PCs. Your boss has requested that you write a report with your recommendations regarding which...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT