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...

  • 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...

  • 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...

  • 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...

  • Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic me...

    Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

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
ADVERTISEMENT