final_sample_spr10_solutions - * SOLUTIONS * Final Exam...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 ***** SOLUTIONS ***** Final Exam Sample Questions - Spring 2010 Note: these questions are based on material since the midterm The final exam will have questions from the earlier material as well. 1. PC Class You are to write part of a class named PC to represent features of personal computers. The data members of the class and default values will be: Data member Description Default value name name of the computer (string) "PC" speed processor speed in gigahertz (double) 1.0 memory memory size in megabytes (double) 512.0 disk disk drive size in gigabytes (double) 40.0 price price in dollars (double) 1.0 Initially, there will be four member functions: a default constructor and a constructor with parameters, a function called showSpecs to display the values of the data members, and addMemory which increases a PC object's memory size and its price. a) Write the declaration section of the class showing the data member declarations and the function declarations for the constructors, showSpecs() , and addMemory() . Member function showSpecs() should have as a parameter a reference to an ostream object. Function addMemory() will have parameters for the additional memory and the price of that memory. class PC { private: string name;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
double speed; double memory; double disk; double price; public: PC(); PC(string, double, double, double, double); void showSpecs(ostream &); void addMemory(double, double); }; b) Write the definition for the constructor that will initialize the data members using parameters. Use a constructor initialization list. class PC PC::PC(string N, double S, double M, double D, double P) : name(N), speed(S), memory(M), disk(D), price(P) {} c) Write the definition for the member function addMemory() which increases the PC object's memory size and price. void PC::addMemory(double mem, double cost) { memory += mem; price += cost; } 2. Overloading Operators Now extend the PC class by overloading the * symbol to multiply the price of a PC object by a discount factor. For example, if pc1 is a PC object that has a price of $1000.00, pc2 is a PC object with default data member values, and discount is a double with value 0.80, then pc2 = pc1*discount; will create a new PC object with price $800.00 and assign it to pc2 . The other data member values for pc2 will be the same as the pc1 values. a) Write the declaration for the operator function.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

final_sample_spr10_solutions - * SOLUTIONS * Final Exam...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online