Tutorial-12
Case study:
In the realm of software development, the Online Library Management System (OLMS)
emerges as a cutting-edge solution designed to modernize library operations in the digital
age. During the Object-Oriented Analysis phase, key classes were identified as the backbone
of the system: 'Book,' 'Member,' 'Librarian,' 'Transaction,' and 'Category’ with following
details:
Class Attributes Methods
title: String addBook(title: String, author: String, availability: boolean): void
Book author: String removeBook(bookId: int): void
availability: updateAvailability(bookId: int, newAvailability: boolean): void
boolean
bookId: int
name: String borrowBook(bookId: int): void
Member returnBook(bookId: int): void
contact: String payFines(amount: double): void
borrowingHistory:
Transaction[]
fines: double
memberId: int
adminId: int addBookToInventory(title: String, author: String): void
Librarian booksInInventory: manageMember(memberId: int, action: String): void
Book[] notifyOverdueMembers(): void
membersList:
Member[]
transactionId: int recordBorrowTransaction(memberId: int, bookId: int):
Transactio borrowDate: Date void
n returnDate: Date recordReturnTransaction(memberId: int, bookId: int):
member: Member void
book: Book
categoryName: addBookToCategory(bookId: int, category: String): void
Category String removeBookFromCategory(bookId: int, category: String):
booksInCategory: void
List<Book>
Relationships were established, such as the association between 'Member' and 'Transaction'
for borrowing and returning transactions, and the aggregation between 'Book' and
'Category' for systematic book organization. Inheritance relationships were introduced, with
'FictionBook' and 'NonFictionBook' inheriting from the 'Book' class. The UML structure
visually represents these static aspects.
Ques 1. Based on above case study design a class diagram with all details provided in the
case study.
Ques 2. Select the structure that is model by the Objects diagram
(A). object
(B). class
(C). Use Case
(D). activity
(E). Both A and B
Ques 3. Which of the following is true about a dependency relationship in UML?
A. It is a stronger form of association than aggregation
B. It is a bidirectional relationship
C. It represents a using relationship between two classes
D. It represents a part-whole relationship between two classes
Ques 4. Which of the following is true about a composition relationship in UML?
A. It is a weaker form of association than aggregation
B. It is a bidirectional relationship
C. It represents a part-whole relationship between two classes
D. It represents a using relationship between two classes
Ques 5. Complete the code- Handle exceptions using try, catch and throw.
.#include <iostream>
using namespace std;
int main() {
double numerator, denominator, divide;
cout << "Enter numerator: ";
cin >> numerator;
cout << "Enter denominator: ";
cin >> denominator;
//COMPLETE THE CODE
return 0;
}
Ques 6. Write the output of the following code:
#include <iostream>
using namespace std;
int main()
{
int x = -10;
try {
cout << "Before Error\n";
if (x < 0) {
throw x;
cout << "After Error\n";
}
}
catch (int x) {
cout << "Exception Caught \n";
}
cout << "After catch \n";
return 0;
}
Ques 7. Complete the code as mentioned in the comments.
#include <iostream>
using namespace std;
int main() {
double numerator, denominator, arr[4] = {0.0, 0.0, 0.0, 0.0};
int index;
cout << "Enter array index: ";
cin >> index;
try {
// throw exception if array out of bounds
cout << "Enter numerator: ";
cin >> numerator;
cout << "Enter denominator: ";
cin >> denominator;
// throw exception if denominator is 0
// not executed if denominator is 0
arr[index] = numerator / denominator;
cout << arr[index] << endl;
}
// catch "Array out of bounds" exception
// catch "Divide by 0" exception
// catch any other exception
return 0;
}
Ques 8. Find the output of the following code.
#include<iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived d;
try {
throw d;
}
catch(Base b) {
cout<<"Caught Base Exception";
}
catch(Derived d) {
cout<<"Caught Derived Exception";
}
return 0;
}