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

Assignment 1 - Basic Structures and Classes

Uploaded by

Anus Babar
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)
12 views

Assignment 1 - Basic Structures and Classes

Uploaded by

Anus Babar
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/ 4

CLO - 3

Object Oriented Programming

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.

Note: Punishment for the plagiarism is to award a straight zero in this


(or all) assignments. Both the parties involved in the plagiarism (with or
without the knowledge of the plagiarism), will be considered equally
responsible and be penalized.

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.

Question 2: Implementing Classes with Constructors in C++


You are tasked with designing a Book class to represent information about books in a
library system. The Book class should contain the following private attributes:
• title (string): The title of the book.
• author (string): The author of the book.
• price (float): The price of the book.
• yearPublished (int): The year the book was published.
Your task is to:
• Default Constructor:
Implement a default constructor that initializes the title as "Unknown", author
as "Unknown", price as 0.0, and yearPublished as 0.
• Parameterized Constructor:
Implement a parameterized constructor that allows the user to initialize the
title, author, price, and yearPublished when creating a Book object.
• Getters and Setters:
Implement public get and set methods for all attributes.
• Display Function:
Implement a public method displayDetails() that prints all the details of the
book in a readable format.
• Testing the Class:
In the main() function:
o Create a Book object using the default constructor and display its
details using the displayDetails() method.
o Create a second Book object using the parameterized constructor,
passing appropriate values for the title, author, price, and year
published. Display the details of this object as well.
Question 3:

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

You might also like