Department of Electrical Engineering: CS212 Object-Oriented Programming
Department of Electrical Engineering: CS212 Object-Oriented Programming
Subject: CS212 Object-Oriented Programming Deadline: 23:59 PKT, Sunday 7 November, 2021
[CLO2] - Demonstrate the ability to carry out mapping of OOP constructs to real world scenarios.
Good Luck!
Problem 01:
(This is an extension of Assignment 01. You have to solve this problem using procedural language
i.e. without using the classes and highlight the difference between the OOP and procedural
language)
(5 marks) Write a C++ program that models a virtual pet. We will assume the pet will have
a weight and can be in a state of being hungry or not hungry. The pet can be fed which will
in turn effect the pet’s hunger state according to the following statements:
1. If the food weight is greater than or equal to one half of the pet’s weight, the pet
will not be hungry, otherwise it will be hungry.
2. The weight added to the pet will be one quarter of the food weight.
3. Write a driver’s program to test your class for member functions.
Instructions for Problem 02 & Problem 03
Separate the program interface from class implementation by using the scope resolution operator
and include the appropriate header file. You are encouraged to use good programming conventions
by entering appropriate comments, using indentations, and using descriptive variable names in
your programs.
Problem 02:
(10 marks) Create a class TicTacToe that will enable you to write a complete program to play
the game of tic-tac-toe.
• The class contains as private data a 3-by-3 two-dimensional array of integers.
• The constructor should initialize the empty board to all zeros.
• Allow two human players. Wherever the first player moves, place a 1 in the
specified square. Place a 2 wherever the second player moves. Each move must be
to an empty square. After each move, determine whether the game has been won or
is a draw.
Problem 03 (Elevator System Specification)
(15 marks) Make use of the Object-Oriented Programming constructs to develop a program in
C++ to monitor the behavior of an elevator system described below:
A basic elevator system is described below. For simplicity we assume that there is one door (rather
than two (one attached to the floor and one to the cab) which close on top of each other), no weight
sensors, no emergency bells, and no buttons except those to summon the lift to a particular floor,
and those for requesting a floor from inside the cab.
(Invariant properties that must be obeyed throughout the execution of your program)
Other Properties
Property 1. when a button (summon or floor request) is pressed, the elevator eventually services the
request.
Property 2. Multiple presses of the same button in between servicing are considered as a single request
Property 3. If an elevator is moving through a floor for which a summons button has been pressed, the
elevator should service that floor. Otherwise, the elevator closest to the requested floor should service
it.
Property 4. Door opening/closing signals always alternate each other; there should never be two
consecutive door opening / two consecutive door closing.
Property 5. If the summon button is pressed for a floor where the door is closing, the door
should open again
Time Properties
Time 1. Upon a request, after the door closes, the elevator starts moving in less than 3
seconds
Time 2. After the door has been open for 3 seconds, it closes automatically