Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 2: A company keeps track of the computers it buys for its employees. Create a class Computer, which has attributes: personName (name of the

image text in transcribed

Exercise 2: A company keeps track of the computers it buys for its employees. Create a class Computer, which has attributes: personName (name of the person in the company using the computer) cost (of the computer when it was bought) cpuSpeed age (number of days since the computer has been bought) memorySize (RAM size in megabytes) The name defaults to the empty string while the remaining attributes default to zero. (Use a default constructor with default parameters.) The class has the following member functions: A default constructor with default parameters A method setAll() should set the data member values at once A method toString() should return the data member values at once (hint use a string as a return value) A method sell which returns the price for a computer if we want to sell it, knowing that if a computer was bought more than 2 years ago, a discount of 50% on the original cost is made, otherwise the discount is 25%. A method ageInYears () which returns the age of a computer object in years. A method print () which prints the details of a computer in a nice format including its current price (if we want to sell it) and its age in days. Write a test program where you do the following: Instantiate three different objects of type Computer with the following details (name, original cost, CPU speed, age in days, RAM size): o computerl attributes: ali, 4020.50 , 2.4, 13, 128 o computer2 attributes: no details given o computer3 attributes: sumaya, 10000.25, 4.6, 890, 1000 Print the details of each computer. Set the data of the second computer to some new data to be read from the keyboard. Write the details of the second computer after its details have been read. Use the method toString() to return the values of the data members of computer3, print these values on the screen

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Question What is an educational benefit trust and how is it used?

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago