CSI 250 Midterm, Spring 2011
American University of Science and Technology · Computer Programming II · 5 pages · Mr. Elie Nasr
More CSI 250 files
Show the text of this exam
Read the following at
ven very eavefully before start writing the code:
For th
Y the follo
Write Win pret
year the class Date, rete Assume class Date has already been implemented (@o NOY
and a method sonst i), The class Date includes methods that check for month, de
y print function that displays the date (the date is pri cag y>
followi
Wing format; Mi//Dt WVVYVY)
You a
re requested
sted to ereate the interface (header file) and the implementation
0 create q ader file) and the implementation of a new
Class calle
d EleetricaiMachine that contains:
ecifies the type of the machine (the int is 1 if
efault value is 1)
© An int j
int instance variable named kind that sp
ther the machine is on (true)
the machi
aaa snag is a generator, 2 if it is a motor, the di
an instance variable named status that identifies whe'
- ened default is false,
oat instance variable named speed that specifies the speed of the rotation of the
machine (default is 0,0)
r*) that specifies the serial number of the
¢ An instance variable named serialNum (cha
machine (default is "869-4569"),
that specifies the manufacturing
© A Date instance variable named manufacturingDate
date of the machine (default 01/01/2000).
te constructor (s), destructor, accessor and mutator
da friend print
he first four instance variables, an
The new class should include appropria
mber, manufacturing date, as well as the status
methods (get and cascaded set) for t
function that prints the kind, speed, serial nu
of the machine if it is on oF off,
that keeps track of the number
object is created and
r, count, of type integer,
Q that returns the
The class should also include a counte
of objects created (this counter must be incremented whenever an
decremented whenever an object is deleted), and a method getCount
number of objects created so far.
se of Composition by using the class Date.
Demonstrate the u
ting the following steps.
Write a driver program implemen
them with values of
stance variables, and
dem2, and initialize
dynamic objects eml, an
lay all the in
1- Instantiate two
your choice, call the friend print function to disp
f objects created.
then display the number 0
amic) with default values, and
2- Instantiate a third object ¢3 (not necessarily dyn ith de
then demonstrate the use of cascading through set functions invocations.
ay back the number of objects.
_ 3- Delete the object em! and then disp!
0 WICH LO te stanaara ouput when the following program is run?
#include<iostream>
using namespace std:
class Q1f
Public:
gag Amt a} :xta)i}:
void modifyX( Q1 q)
{
a.m. = 28:
}
int getX() const
{
return xX;
}
private:
ac x;
main( )
ma a(10):
£<o<"X = act: getX()<<endl:
iS wrong with the following code? Explain how to correct it .
Winclude<iostream>
using namespace std;
int getX() const
{
}
. :
Re wih pss 5
Ziend void modiiy= 3 -
= 1Q9 &. int}:
Public:
otint a = 10}-xtayt}
int getxX() const{
return xX;
}
Private:
atu. Sk):
modifyX(Q9 &q. int a)
oF OB:
Question #6 - (30 Points)
integ ag 3 arithmetic with fractions. Write a program
d the denominaves bao to represent the private data of the pti (the
i P Or). Provide a constructor that enables an object of this class
. tructor should contain default values in case
ide public member and or friend functions that perform
a) Overload the Stream Ins
b) Overload the + fe)
type r3 = rl+r2.
ertion and Stream Extraction operators.
perator so as two objects can be added when the user
Provide a driver that performs the following:
1- Create two Rational objects Rational rl, and r2 j loaded stream
2- Input their instance variables from the keyboard using the overloade
extraction operator Sania ber 1
3- Add rl and r2 and store their result into and new rational num
overloaded + operator
34 using the
4- Display the results of r3 af@2s# using the overloaded stream extraction operator.