Assignment 1 - Basic Structures and Classes
Assignment 1 - Basic Structures and Classes
Assignment No. 1
Attention
• Make sure that you read and understand each and every instruction. If you have
any questions or comments you are encouraged to discuss with your colleagues
and myself.
• Each problem solution must be provided in a separate CPP file. For instance, you
must name the file containing solution of the first file as ’q1.cpp’ and the second
as ’q2.cpp’ and so on. A total of three submissions must therefore be made for this
assignment.
• Any submissions after deadline will not be accepted.
• Please start early with the assignment so you can submit it on time.
• Good coding practices will earn a higher grade. For e.g. ensuring your
code detects any incorrect inputs and handles any other type of
possible errors efficiently will earn a higher grade.
You are required to use structures/classes and functions for all the
questions. Your main function should be as small as possible.
Question 1: Defining classes
Define a class Student with private attributes: name, rollNumber, and grade. Provide
public methods to set and get these values. Write a main() function to create two
Student objects, set their values, and display the information of both students.
Design a Library Management System that tracks books and members, allowing
members to borrow and return books.
Requirements:
1. Book Class:
o Attributes:
▪ title (string): Title of the book.
▪ borrowerID (int): Member ID of the borrower (-1 if not borrowed).
o Methods:
▪ borrowBook(int memberID): Marks the book as borrowed.
▪ returnBook(): Marks the book as returned.
▪ isBorrowed(): Returns true if the book is borrowed, false otherwise.
2. Member Class:
o Attributes:
▪ memberID (int): Unique ID of the member.
▪ name (string): Member's name.
3. Static Variables:
o totalBooks (int): Total number of books.
o totalMembers (int): Total number of members.
4. Functionality:
o Add books and register members, updating static counters.
o Implement borrowing and returning of books.
o In main(), demonstrate adding books, registering members, borrowing,
and returning books.
END OF ASSIGNMENT