lab exam - sample 2

2
Programming Techniques Lab LAB Exam CMPN103 1/2 Cairo University Faculty of Engineering Credit Hours System Programming Techniques Lab Time: 60 min LAB Exam – Sample 2 Given the following code Class Driver: Driver.h #ifndef _DRIVER_H #define _DRIVER_H #include <iostream> using namespace std; class Driver { int ID; int Shift; //Driver's shift; 1: day shift, 2: night shift }; #endif Class Car: Car.h #ifndef _CAR_H #define _CAR_H #include "Driver.h" class Car { int PlateNum; Driver* Drv1; //Driver of day shift Driver* Drv2; //Driver of night shift }; #endif main function: Main.cpp #include "Car.h" int main() { //Create three drivers: //D1: ID=10, day shift, D2:ID=20, day shift, D3: ID=30, night shift. Driver D1(10, 0), D2(20, 0), D3(30, 1); Car C1(12345);//Create car C1:PalteNum = 12345 C1.Print(); //Print C1 information C1<<D1; //Assign driver D1 to car C1 C1.Print(); //Print C1 information C1<<D2; //Assign driver D2 to car C1 C1.Print(); //Print C1 information !D1; //Toggle shift of D1 C1<<D1; //Assign driver D1 to car C1 C1.Print(); //Print C1 information C1<<D3; //Assign driver D3 to car C1 C1.Print(); //Print C1 information return 0; } اﻟرﻗم: اﻻﺳم: PDF created with pdfFactory trial version www.pdffactory.com

Upload: bishoy-emile

Post on 22-Jul-2016

18 views

Category:

Documents


5 download

DESCRIPTION

labexam

TRANSCRIPT

Page 1: Lab Exam - Sample 2

Programming Techniques Lab LAB Exam

CMPN103 1/2

Cairo University Faculty of Engineering Credit Hours System

Programming Techniques Lab

Time: 60 min LAB Exam – Sample 2

Given the following code Class Driver:

Driver.h #ifndef _DRIVER_H #define _DRIVER_H #include <iostream> using namespace std; class Driver { int ID; int Shift; //Driver's shift; 1: day shift, 2: night shift }; #endif

Class Car: Car.h

#ifndef _CAR_H #define _CAR_H #include "Driver.h" class Car { int PlateNum; Driver* Drv1; //Driver of day shift Driver* Drv2; //Driver of night shift }; #endif

main function: Main.cpp

#include "Car.h" int main() { //Create three drivers: //D1: ID=10, day shift, D2:ID=20, day shift, D3: ID=30, night shift. Driver D1(10, 0), D2(20, 0), D3(30, 1); Car C1(12345);//Create car C1:PalteNum = 12345 C1.Print(); //Print C1 information C1<<D1; //Assign driver D1 to car C1 C1.Print(); //Print C1 information C1<<D2; //Assign driver D2 to car C1 C1.Print(); //Print C1 information !D1; //Toggle shift of D1 C1<<D1; //Assign driver D1 to car C1 C1.Print(); //Print C1 information C1<<D3; //Assign driver D3 to car C1 C1.Print(); //Print C1 information return 0; }

:االسم :الرقم

PDF created with pdfFactory trial version www.pdffactory.com

Page 2: Lab Exam - Sample 2

Programming Techniques Lab LAB Exam

CMPN103 2/2

Requirements

1- For class Driver, add the following functions

a. Non-default constructor to initialize class members b. Functions getID and getShift c. Function Print that prints ID and shift (see program output below)

2- For class Car, add the following functions a. Create a constructor to initialize Car members. b. Function Print that prints Car plate number plus information of all drivers assigned to

that car. If car has no day or night driver, it prints a message (see program output).

3- Overload ! operator to toggle driver's shift. i.e. it changes the driver's shift from day to night and vice-versa.

4- Overload operator << to assign a new driver to a car according to the driver's shift. If a driver is already assigned to that shift, it is replaced by the new driver. (see main function to see how this operator is used)

5- Compile and run the program to produce the following output.

Program Output Car Info: PlateNum=12345 Assigned Drivers: No Day Driver No Night Driver Car Info: PlateNum=12345 Assigned Drivers: Driver ID=10 Day Shift No Night Driver Car Info: PlateNum=12345 Assigned Drivers: Driver ID=20 Day Shift No Night Driver Car Info: PlateNum=12345 Assigned Drivers: Driver ID=20 Day Shift Driver ID=10 Night Shift Car Info: PlateNum=12345 Assigned Drivers: Driver ID=20 Day Shift Driver ID=30 Night Shift

Notes:

- Every class should be written in two files (.h and .cpp) - Do not add any more set or get functions to the above classes. - Do not update the main function.

[4 mark]

[3 marks]

[1 marks]

[4 marks]

[3 marks]

PDF created with pdfFactory trial version www.pdffactory.com