0% found this document useful (0 votes)
13 views

2024.6.10_SCS 3106_Object Oriented Programming_EXAM

This document outlines the examination details for the University of Nairobi's second semester exams for the Bachelor of Science in Computer Science, specifically focusing on Object Oriented Programming. It includes various programming questions related to C++, covering topics such as inline functions, compiler vs linker, late binding, and class implementations for a stock trading application and vehicle tracking system. Additionally, it addresses concepts like polymorphism, function overloading, and data structures for managing inventory and student information.

Uploaded by

elmusnigel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views

2024.6.10_SCS 3106_Object Oriented Programming_EXAM

This document outlines the examination details for the University of Nairobi's second semester exams for the Bachelor of Science in Computer Science, specifically focusing on Object Oriented Programming. It includes various programming questions related to C++, covering topics such as inline functions, compiler vs linker, late binding, and class implementations for a stock trading application and vehicle tracking system. Additionally, it addresses concepts like polymorphism, function overloading, and data structures for managing inventory and student information.

Uploaded by

elmusnigel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
aa UNIVERSITY OF NAIROBI SECOND SEMESTER EXA! TIONS 2023/2024 FIRST YEAR EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN ‘COMPUTER SCIENCE, SCS3106 - Object Oriented Programming Date: June 10, 2024 Time: 09:00AM — 11:00AM Instructions: Answer Question ONE and any other TWO questions Question 1 (20 Marks) 8) Use the following code snippet to answer the questions that follow. 1 class Widget { 2 public: 3 int setValue(int newValue) { 4 int oldValue = value; 5 value = newValue; 6 return oldValue; Z } 8 private: 9 friend void wasteTime(); 10 void doNothing() {} " int value; 14 void wasteTime() { 8 Widget x; 6 x, doNothing (); 7 x.value = 57 1) 2 void func() { a Widget x; 2 x.setValue (5) 7 = // sets x.value to 5 4 x.value = 5; 2% x. doNothing (); i, The function in line 3 is implicitly inline. Explain what this means and why this function is considered so. (2 Marks) Rewrite the function in line 3 to make it explicitly inline. (2 Marks) Identify and explain two errors in the above program. (4 Marks) Differentiate between a compiler and a linker as used in Programming (2 Marks) Explain the concept of late binding and its importance in Object Oriented Programming (2 Marks) 4) A stock trading application is required that monitors acti ities in the Nairobi Securities Exchange and allows users to choose a stock they want to track. The application should notify users of the changes in stock prices and keep history of the changes. Additionally, it should allow users to choose how they want to be notified (for example, via email or text message). Use C+ to implement a snippet of this program ensuring it meets all the details in the narrative and how to setup the notification strategies. (8 Marks) Question 2 (15 Marks) Acar manufacturer uses a C++ application to track current vehicles being built. The diagram below shows an excerpt of the current software structure. You should assume the presence of other appropriate fields and methods. Each car can be built to one of three trim levels: base, luxury or sport. They can also be configured with an electric or petrol engine, At various points in the manufacturing process the customer can choose to change the trim level. [accelerate () [+getFuetLevel() [+getTrintevel() A BaseCar a) Explain the relationship between the Car and the Engine described above. (2 Marks) b) Provide a complete definition of SportCar and ElectricEngine classes. (2 Marks) ¢) The manufacturer decides to offer a vehicle with a hybrid engine that is both an electric engine and a petrol engine, Show the appropriate implementation of the following classes 2 in order to meet this new objective: Engine, ElectricEngine, PetrolEngine and HybridEngine. (4 Marks). 4) Using examples from (c) above explain what an abstract class is in C++. (2 Marks) ©) Using a menu driven approach, write the C+ program that is required to show the number of each type of vehicle that is Hybrid Luxury and Base Cars from the system. (5 Marks) Question 3 (15 Marks) a) Explain the meaning of polymorphism, clearly outlining its advantages (3 Marks) b) Suppose we have a class, call it Server, which has some desired functionality. Suppose further that we want to be able to replace it with another class, OtherServer, which performs the same task but in a different way. It must be possible to switch between Server and OtherServer without having to recompile the classes that call them. Write a C++ program which solves this problem with the help of polymorphism. (6 Marks) ©) Using example C+ code, illustrate the following concepts: function overloading, function overriding and variable shadowing. (6 Marks) Question 4 (15 Marks) An online retailer uses custom C++ software to manage their inventory and sales. Each product sold is represented using a Product object. Product objects are requested through a Product .getProduct(long code) method, which retums a reference to a Product object given a valid product code. Product information is often re-requested as customers make their selections so the 10,000 most recently accessed Product objects are cached in memory. Uncached Product objects are created with information retrieved from a file when requested. a) Using appropriate data structures in C++, and assuming that the inventory is stored in a file named “products.txt” write a program that uses a class named Store to actualize the cache described above, (9 Marks) b) A customer's basket of items, represented by a class Basket, can be viewed as a list of products. Assuming that each product has a float data member called price, which shows the value of that product. Write a function that calculates the amount that is payable by a customer based on the goods in his/her basket. (6 Marks) Question 5 (15 Marks) A Lecturer wishes to create a program that lists his students sorted by the number of practical assignments they have completed. The listing should be greatest number of assignments first, sub- sorted by name in lexicographical order (A to Z). A class Studentinfo stores the name and number of assignments completed for a student. Amongst other methods, it contains a void setCompleted{int n) method that allows changes to the number of completed assignments. (a) Provide a C++ program that implements the class StudentInfo with an equals() method and natural ordering that matches the given requirement. (10 Marks) (b) Improve your program to be able to write a list of student details into a text file of your choice. (5 Marks)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy