Object Oriented Programming BS Computer Science UOG — University of Gujrat 2024
Discussion
Ask a question about this paper, or help someone else with theirs. Answers are emailed to whoever asked.
No questions yet — be the first to ask.
Need a paper or stuck on a question? Ask here — students reply and you get an email.
Ask about a paper-
ICT 1st sister paper
0 replies Reply → -
BS Islamic Studies, 5th semester, ISL-511 Translation of Holy Quran (3) — Government College University Faisalabad (GCU…
0 replies Reply → -
Civics course code GCCE101
1 reply Reply → -
BS 4the semester2025 civics and community engagement past paper According UOs
0 replies Reply → -
Bs public administration 1st semester mid term past papers
0 replies Reply →
Paper text
University of Gujrat
DEPARTMENT OF COMPUTER SCIENCE
Mid-Term Examination (Morning)
Course: Object Oriented Programming (CS-205)
Time: 1:30 Hrs
Spring-2024
Total Marks: 25(5X5)
Q1) Consider we want to create a class ATM, which can store currency notes of Rs 500, 1000 and, 5000.
Implement class ATM with the following user requirements:
• User login is NOT required.
• The machine has capacity of storing only 100 notes of each value.
• A user can withdraw a maximum of Rs. 10000 at one time.
• Withdraw function can accept only one parameter (amount) which must be a multiple of 500. It
always gives largest notes first.
• Deposit require three int parameters, deposit(int note500, int note1000, int note5000)
• Display function prints number of notes for each value and total cash.
• Number of notes can also be passed to constructor.
Q2) Identify at least three exceptions in the ATM class (Q1) and create your own exception classes. Re-
write withdraw and deposit functions to throw exceptions. Write a main method to call the withdraw and
deposit methods with invalid values and show the exception messages.
Q3) Inheritance is a strong concept used to increase re-usability of code. Suppose we want to extend the
functionality of ATM class created in Q1 by including some operator overloading functions:
• operator += adds a note of Rs 500
• operator ++- add a note of Rs 500 and a note of Rs. 1000
• operator --- decreases each note by 1
Implement all three overloaded methods in light of requirements defined in Q1 and handle exceptions.
No need to re-write parent class.
Q4) Why multi-class inheritance is not recommended? Consider the following class diagram and answer the
questions:
Time
-hr
-min
-sec
+setTime(int hr, int min, int sec)
+displayTime()
RingAlram
+ringAlarm()
Alram
-int hr
-int min
-int sec
+setTime(int hr, int min, int sec)
+displayTime()
+getHr()
+getMin()
+getSec()
• Implement setTime, setAlarmTime and display methods in RingAlarm class.
• The method setTime should call setTime from Time class.
• setAlarmTime should call setTime from AlarmClock class.
• The display method should first call display from Time class and then from AlaramClock class to
show both current time and alarm times.
Q5) Consider you are hired to design a management system for Hayat Stationers, which deals in stationary
items for students of UoG. Draw only CLASS DIAGRAM of the system identifying at least four(4)
classes clearly showing data members, member functions and class associations. Identify and show at
least one example of aggregation/composition where one class contains instance of another class.
(Created using Libre office 7.6 on Ubuntu 23.10)