KEMBAR78
OOP Final Spring'23 | PDF | Object Oriented Programming | Software Engineering
0% found this document useful (0 votes)
24 views6 pages

OOP Final Spring'23

The document outlines the final examination details for the Object Oriented Programming course at the National University of Computer & Emerging Sciences, Karachi, scheduled for May 22, 2023. It includes instructions for students, a list of questions covering programming tasks, class diagrams, and requirements for implementing a chatbot system. The exam consists of multiple questions that assess students' understanding of object-oriented programming concepts and their application in coding scenarios.

Uploaded by

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

OOP Final Spring'23

The document outlines the final examination details for the Object Oriented Programming course at the National University of Computer & Emerging Sciences, Karachi, scheduled for May 22, 2023. It includes instructions for students, a list of questions covering programming tasks, class diagrams, and requirements for implementing a chatbot system. The exam consists of multiple questions that assess students' understanding of object-oriented programming concepts and their application in coding scenarios.

Uploaded by

k240807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

National University of Computer & Emerging Sciences, Karachi

School of Computing (BSCS, BSCS-R, BSCY, BSSE, BSAI)


FINAL EXAMINATION SPRING-2023
22nd May 2023, 12:00 noon – 03:00 pm
Course Code: CS1004 Course Name: Object Oriented Programming
Instructors Name: Dr. Farooque Hassan Kumbhar, Dr. Abdul Aziz, Mr. Zain-ul-Hassan, Ms.
Abeer Gauher, Mr. Basit Ali, Ms. Sobia Iftikhar, Ms. Aqsa Zahid, Ms. Sumaiyah, Ms.
Abeeha Sattar, Ms Javeria Farooq, Mr. Shahroz Bakht, Ms. Eman Shahid
Student Roll No: Section No:

Instructions:

 Return the question paper and make sure to keep it inside your answer sheet.
 Read questions completely before answering. There are 5 questions, 6 sides on 3 pages.
 In case of any ambiguity, you may make assumptions. But your assumption should not
contradict any statement in the question paper.
 You are not allowed to write anything on the question paper (except your ID and section).
Time: 180 minutes. Max Marks: 104 Marks
Q1: [30 min, 20 Marks, CLO 1] Write on the answer sheet the output of the following programs,
when they are executed. There are no compilation errors in the programs.
A. #include<iostream> B. #include<iostream>
using namespace std; using namespace std;
class Point { int func(int n){
private: if(n==0){
int x, y; cout<<"The value is
public: zero"<<endl;
Point(){Point(1,1);} return 10;}
Point(int i, int j); if(n>0){
Point(const Point &t); cout<<"The value is
}; greater than zero"<<endl;
Point::Point(int i, int j) { throw 'e';}
x = i; if(n<0){
y = j; cout<<"The value is less
cout << x<<" "<<y<<"Normal than zero"<<endl;
Constructor called\n"; throw 9.9f;}
} }
Point::Point(const Point &t) { int main(){
y = t.y; try {
cout << y <<" "<<"Copy func(0); func(10); func(-10);
Constructor called\n"; } catch (int x) {
} cout << "Catching Integer\n";
int main() func(10);
{ } catch (float f) {
Point *t1, *t2; cout << "Catching Float\n";
t1 = new Point(10, 15); func(10);
t2 = new Point(*t1); } catch (char c) {
Point t3 = *t1; cout << "Catching Character\n";
Point t4; func(10);
t4 = t3; }
return 0; }
}

1 OF 6
C. #include <iostream> D. #include<iostream>
class Base { using namespace std;
public: class A
static int count; {
Base() {count++;} public:
virtual ~Base() {count--;} A (){ cout << "\n A's
static void printCount() { constructor"; }
std::cout << "Count: " << A (const A &a) { cout << "\n A's
count << std::endl; Copy constructor";}
} A& operator = (const A &a)
}; {
class Derived : public Base { if(this == &a) return *this;
public: cout << "\n A's Assignment
Derived() {count++;} Operator"; return *this;
~Derived() {count--;} }
}; };
int Base::count = 0; class B
int main() { {
Base::printCount(); A a;
{ public:
Base obj1; B(A &a) { this->a = a; cout << "\n
Derived obj2; B's constructor"; }
Base::printCount(); };
} int main()
Base::printCount(); {
return 0; A a1;
} B b(a1);
return 0;
}

Q2: [30 min, 20 Marks, CLO 2] Considering the output given, complete the following code snippets.

A. #include <iostream> Output: 30


class Base {
private:
int data;
public:
Base(int value) : data(value) {}
void printData() {
std::cout << "Data: " << data << std::endl;
}
______________________
______________________
______________________
};
int main() {
Base obj1(10);
Base obj2(20);
Base result = obj1 + obj2;
result.printData();
return 0;}

2 OF 6
B. #include<iostream> Output:
______________________ Maximum of 5
______________________ and 10: 10
______________________ Maximum of
int main() {
3.14 and 2.71:
int intMax = maximum<int>(5, 10);
3.14
std::cout << "Max of 5 and 10: " << intMax <<
std::endl;
Maximum of 'a'
double doubleMax = maximum<float>(3.14, 2.71); and 'z': z
std::cout << "Max of 3.14 and 2.71: " << doubleMax
<< std::endl;
char charMax = maximum<char>('a', 'z');
std::cout << "Max of 'a' and 'z': " << charMax <<
std::endl;
return 0;
}

C. #include <iostream> Output:


#include <fstream> Data saved to
#include <string> file with
details:
class Person { Ali
protected: 21
std::string name; FAST NUCES
int age;
public:
Person(const std::string& name, int age) :
name(name), age(age) {}
virtual void saveToFile(const std::string&
filename) const = 0;
};
class Student : public Person {
private:
std::string university;
public:
______________________
______________________
______________________
______________________
______________________
______________________
______________________
};
int main() {
Student student("Ali", 21, "FAST NUCES");
student.saveToFile("student.txt");
return 0;
}

3 OF 6
D. #include <iostream> Output:
template<typename T> Sum: 12
class Pair { Average: 6
private:
T first;
T second;
public:
Pair(T f, T s) : first(f), second(s) {}
T sum() const {
return first + second;
}
______________________
______________________
______________________
______________________
______________________
int main() {
Pair<int> p(5, 7);
std::cout << "Sum: " << p.sum() << std::endl;
std::cout<<"Average: "<<average(p)<< std::endl;
}

Market
Stock
-*stock: Stock
-symbol: string
-numStocks: int
-companyName: string
+addStock(Stock* stock):
-price: double
void
-availableQuantity: int
+tradeStocks(): void
-maxQuantityPerInvestor: int
-stockCategoryQuantity: int

Investor +getSymbol(): string


-name: string +getCompanyName(): string
-CNIC: string +getPrice(): double
-email: string +isEligibleToBuy(int purchaseQuantity): bool
-availableFunds: int +displayInfo(): void
-hasLoan: bool +operator!= (Stock& other): bool

+canBuyStock(Stock&
stock, int
purchaseQuantity)=0: bool PharmaStock TechStock

+isEligibleToBuy(int +isEligibleToBuy(int
purchaseQuantity):bool purchaseQuantity):bool

DayTrader LongTermInvestor

+canBuyStock(Stock& stock, +canBuyStock(Stock& stock,


int purchaseQuantity): bool int purchaseQuantity): bool

Q3: [25 min, 10 Marks, CLO 3] Consider the above given class diagram that demonstrates a stock market
scenario. You are required to write the skeleton of the classes (i.e., member variables and function
signatures) as shown in the above given class diagram. The parameterized constructor in all inherited classes
must call parent’s constructor to initialize variables. Create getter methods for all the attributes in all the
classes. You are also required to define following functions:

4 OF 6
 Stock::displayInfo() const: Displays the information about the stock. Prints the symbol, company
name, price, available quantity, max quantity per investor, and category quantity of the stock.
 Market::getNumStocks() const: Gets the number of stocks currently in the market. Returns An
integer representing the number of stocks in the market.
Q4: [50 min, 10+10+4 Marks, CLO 4] Use the class diagram and your answer of Q3 as reference
and write programs for the following.
A. Implement functions as described below.
Stock::isEligibleToBuy() const: Following checks must be confirmed to check the buying eligibility of a
stock. A stock is eligible for purchase if all conditions are met.
 Purchase quantity should not exceed maximum quantity limit per investor. Also, purchase
quantity should not exceed the available quantity of the stock. If the purchaseQuantity is less
than or equal to zero, then display an error message stating that the purchase quantity is invalid
and return false.
TechStock::isEligibleToBuy(): Along with all parent class conditions, eligibility to buy of TechStock
includes following checks.
 The purchase quantity must be a multiple of 10 for TechStock. If not, it displays an error message
and returns false. Also, if the purchaseQuantity is greater than 100, it will display an error
message stating that the maximum purchase quantity for TechStock is 100 and return false.
PharmaStock::isEligibleToBuy(): Along with all parent class conditions, eligibility to buy of PharmaStock
includes following checks.:
 The purchase quantity must be at least 50 for PharmaStock. If not, it displays an error message
and returns false. If the purchaseQuantity is not a multiple of 5, it will display an error message
indicating that the quantity must be a multiple of 5 for PharmaStock and return false.
B. Implement functions as described below.
Investor::canBuyStock() is pure virtual function.
DayTrader::canBuyStock(): Checks if the investor can buy a given stock based on their financial status. If
the investor has availed a loan, it displays an error message and returns false. The function should also
calculate the total price of the stock purchase and check if it exceeds the available funds of the day trader.
If so, it displays an error message and returns false. Finally, uses isEligibleToBuy() method of the stock
and returns its response.
LongTermInvestor::canBuyStock(): Checks if the investor can buy a given stock based on their financial
status. If the LongTermInvestor has availed a loan and has availableFunds less than 50000, it displays an
error message and returns false. The function should also check that the purchaseQuantity does not
exceed the maxQuantityPerInvestor limit. If it does, then it displays an error message and returns false.
Finally, uses isEligibleToBuy() method of the stock and returns its response.
C. Overloaded inequality operator to compare stocks based on their symbols¸ i.e. the following statement
should work: bool isNotEqual = stockObject1 != stockObject 2.
A stock is not equal to another stock if either the name of the stock company or the stock symbol is different
from the other stock.

Q5: [45 min, 10+10+10 Marks, CLO 5] Consider a chatbot system designed to provide responses to
users' queries. The system consists of four chatbot variants tailored for medical, technology, legal, and
general queries. Your task is to implement an object-oriented program that fulfills the following
requirements:

A. Design a User class to store user data, including attributes such as username, country, interest, and age.
User have a method Ask() which takes a string as a query and generates a specific response.
 The medical chatbot should respond if the query's prefix (first word) is "doc". The legal chatbot
should respond if the query begins with "attorney". The technology chatbot should respond only
if the query starts with "guru".

5 OF 6
 If a query begins with "special", check the user's interest, and forward the query to the relevant
chatbot variant based on their interest.
 If a query does not match the relevant prefix, it must throw a custom exception object of type
"Bot_Exception" with an error message.
B. Implement a Chatbot class as the base class for all chatbot variants. Each chatbot variant
(MedicalChatbot, TechnologyChatbot, LegalChatbot, GeneralChatbot) should be inherited from the
Chatbot class. Make sure that each chatbot class should keep track of the number of instances created
throughout the program.
 Each chatbot variant should have a method string generate_response(string query, User u) to
generate responses based on user queries. It should store the name of the most recent user that
interacted with it and maintain a total user count, tracking the number of users who have ever
interacted with it.
 Provide functionality to access the total user count for each chatbot variant at any given time.

C. As specified in part A, when a chatbot variant throws a "Bot_Exception", an error message should notify
the user that the query is invalid. Capture the username and query of the user causing the exception and
write it to the "error_log.txt" file. The "error_log.txt" file should contain a list of usernames + queries for
users who caused exceptions to be thrown. Also, you need to write a function “Analysis()” that will open
the file “error_log.txt” in read mode and will perform the following analysis:

o It will print the username who caused the maximum number of exceptions.
o It will print the total count of words from each query stored.

Note: Ensure that your program demonstrates proper usage of object-oriented principles such as
inheritance, encapsulation, exception handling, generics, and file handling. Implement appropriate methods
and attributes in each class to fulfill the requirements outlined above.

BEST OF LUCK!

6 OF 6

You might also like