OOP in C# Tasks
OOP in C# Tasks
Lab Manual 4
Introduction
After a week of rigorous coding, Welcome back!
You have learned all about the Classes, Constructors, and member
functions in the previous lab manuals. Let's move on to the next,
new, and interesting concepts.
Students, Recall this question from the class that you attempted and developed CRC
cards.
Problem Statement 01:
Solution
– CRC Card
Student
name: string
rollNumber: int
cgpa: float
matricMarks: int
fscMarks: int
ecatMarks: int
homeTown: string
isHostelite: bool
isTakingScholarship: bool
claculateMerit(): float
isEligibleforScholarship(float meritPercentage): bool
Self Assessment Task: Implement the Class Student by using the CRC card that you
developed in the class and use the driver program to test your member functions.
Solution
CRC Card
Book
title: string
author: string
pages: int
chapters: List<string>
bookMark: int
price: int
isAvailable: bool
Book(parametrized)
isBookAvailable(): bool
getChapter(chapterNumber: int): string
getBookMark(): int
Self Assessment Task: Implement the Class Student by using the CRC card that you
developed in the class and use the driver program to test your member functions.
Great Work Students !!! You guys are doing an excellent job. Well
done. Take a two-minute break. Well deserved.
Solution
CRC Card
This code creates the Customer class Data Members, Constructor, and Member
Function for adding products to the list.
This code creates the Product class Data Members and Member Function for
calculating tax.
Self Assessment Task 01: Implement this program by using the CRC card that we have
developed and then use the driver program to test your member functions.
Self Assessment Task 02: Implement the member function in the appropriate class for
calculating the tax of all the products that a customer has purchased.
Challenge # 01:
Some of the characteristics of a book are the title, author(s), publisher, ISBN, price,
stock and year of publication.
Design a class named Book that defines the book.
1. Attributes: Each object of the class Book can hold the following information
about a book: title, up to four authors, publisher, ISBN, price, and number of
copies in stock. To keep track of the number of authors, add another member
variable.
2. Member Functions: Include the member functions to perform the various
operations on objects of type Book. For example, the usual operations that can be
performed on the title are to show the title, set the title, and check whether a title is
the same as the actual title of the book. Similarly, the typical operations that can be
performed on the number of copies in stock are to show the number of copies in
stock, set the number of copies in stock, update the number of copies in stock, and
return the number of copies in stock. Add similar operations for the publisher,
ISBN, book price, and authors. Add the appropriate constructors
3. Driver Program: Write a menu driven program that uses the class Book and tests
various operations on the objects of the class Book. Declare an array of 100
components of type Book. Some of the operations that you should perform are to
add a book, search for a book by its title, search by ISBN, and update the number
of copies of a book.
Challenge # 02:
In this exercise, you will design a class Member.
1. Attributes: Each object of the Member can hold the name of a person, member
ID, List of books bought, number of books bought, moneyInBank and
amount spent.
2. Member Functions: Include the member functions to perform the various
operations on the objects of the Member—for example, modify, set, and show a
person’s name. Similarly, update, modify, and show the number of books bought
and the amount spent. Add the appropriate constructors.
3. Driver Program: Write a menu driven program to test various operations of your
class Member.
Challenge # 03:
4. Using the classes designed in Programming Challenges 1 and 2, write a program
to simulate a bookstore. The bookstore has two types of customers: those who are
members of the bookstore and those who buy books from the bookstore only
occasionally (for non-Member people store the memberID attribute as 0). Each
member has to pay a $10 yearly membership fee and receives a 5% discount on
each book purchased. For each member, the bookstore keeps track of the number
of books purchased and the total amount spent. For every eleventh book that a
member buys, the bookstore takes the average of the total amount of the last 10
books purchased, applies this amount as a discount, and then resets the total
amount spent to 0. Your program should contain a menu that gives the user
different choices to effectively run the program; in other words, your program
should be user driven.
a. Add a Book:
i. Gather information for a new book (title, authors, publisher, ISBN,
price, stock, year of publication).
ii. Add the book to the bookstore's inventory (i.e., List of Books in the
Main).
b. Search for a Book by Title:
i. Enter a book title to search for.
ii. Display information about the book if found.
c. Search for a Book by ISBN:
i. Enter an ISBN to search for.
ii. Display information about the book if found.
d. Update Stock of a Book:
i. Enter the title or ISBN of the book to update.
ii. Provide an option to increase or decrease the stock of the book.
e. Add a Member:
i. Gather information for a new member (name, member ID).
ii. Add the member to the bookstore's list (i.e., List of Members in the
Main).
f. Search for a Member by Name or ID:
i. Enter the name or ID of a member to search for. In Case of
non-member only search based on the name.
ii. Display information about the member if found.
g. Update Member Information:
i. Enter the name or ID of a member to update. In Case of a
non-member, only enter the name.
ii. Provide options to modify the member's name, ID, or both.
h. Purchase a Book:
i. Enter the name and member ID or specify as non-member (0) for
occasional buyers.
ii. Select a book to purchase, and enter the quantity.
iii. Apply discounts for members and process the purchase.
Challenge # 04:
Read the following question carefully.
Identification of Classes
By looking at the above-mentioned self-assessment you can extract the following
possible class-like structures from the given statement.
● Student
● Subject
● Degree Program
Note: Create a separate class in the same BL(Business Logic) folder of your program.
After creating your Class diagram you have to write the Driver Program
by using your Classes.
You have made it through all that. Excellent work students !!!
You guys are successfully en route to be Kamyab Programmers.