0% found this document useful (0 votes)
10 views4 pages

Object Oriented Programming Assignment 5

Uploaded by

bsce23017
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)
10 views4 pages

Object Oriented Programming Assignment 5

Uploaded by

bsce23017
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

CE101T – Object Oriented Programming

Section: Assignment # 5 Total marks: 35


Name : __________________ Roll number : __________________

Submission:
• Email instructor or TA if there are any questions. You cannot look at others’ solutions or use others’
solutions, however, you can discuss it with each other. Plagiarism will be dealt with according to the
course policy.
• Submission after due time will not be accepted.

Follow this naming convention for your report, it should highlight difficulties you faced and things you
learned in this assignment. Naming Pattern ( Roll#_Assignment#.pdf e.g BSCE23000_Assignment3.pdf )
In this assignment you have to do following tasks:
Task 1: Ensure that you have installed all three softwares in your personal computer (Github, Cygwin
& CLion). Now, accept the assignment posted in Google Classroom and after accepting, clone the
repository to your computer. Make sure you have logged into the github app with your account.
Task 2: Open Cygwin app, Move to your code directory with following command “cd
<path_of_folder>”
<path_of_folder> can be automatically populated by dragging the folder and dropping it to the
cygwin window.
Run the code through Cygwin, use command “make run”, to get the output of the code
Task 3: Solve the given problems, write code using CLion or any other IDE.
Task 4: Keep your code in the respective git cloned folder.
Task 5: Commit and Push the changes through the Github App
Task 5: Write the code in separate files (structure_name.h, structure_name.cpp) for each struct, declare
struct variables, and call functions from [Link]. Ensure that file names are in lowercase.
Task 6: Run ‘make run’ to run C++ code
Task 7: Run ‘make test’ to test the C++ code

Object Oriented Programming


CE101T-Spring 2024
Problem Statement: Group Collaboration and GitHub Branches

Task 1: Cash Register Program


Implement a CashRegister class with the following private data members and public member
functions:

Data members:
item_count (int)
total_price (double)

Member functions:
Default Constructor: Dynamically allocates memory for data members, it also reset item count
and total price.
Setter Method: A method named setItem that takes price as parameter, adds an item to the
current sale with the specified price.
Getter Methods:
A default method named getTotal that returns the total amount due for the current sale.
A default method named getCount that returns the total item count for the current sale.
Destructor: Release the dynamically allocated memory.

Non member function:


A method named display that takes a const CashRegister& parameter and displays the item
count and total amount
Display Format:
Item count: 2
Total amount due: $5.5

Object Oriented Programming


CE101T-Spring 2024
Task 2: Construct Rectangle Program
Implement a class called Rectangle with the following private data members and public member
functions:

Data members:
width (int)
height (int)

Member functions:

Default Constructor: Allocates memory for data members and resets width and height.
Setter Method: A method named setRectangle that takes width and height as parameters and
constructs a rectangle.
Getter Methods:
A method named getWidth returns the width.
A method named getHeight returns the height.
Destructor: Releases the dynamically allocated memory.

Non-member function:

A method named displayAfterResize that takes a const Rectangle& parameter and a int type
factor, and resizes the rectangle by multiplying the width and height by the given factor.
Display Format:
Resized Rectangle: width = 6, height = 8

Object Oriented Programming


CE101T-Spring 2024
Task 3: Modelling Email Message Program
Implement a class called Message with the following private data members and public member
functions:

Data members:

sender (string)
receiver (string)
message_body (string)

Member functions:

Default Constructor: Dynamically allocates memory for data members and resets them.
Setter Method: A method named setMessageAttributes that takes sender, receiver, and
message_body as parameters and initializes the class attributes.
Getter Methods:
A method named getSender that returns the sender.
A method named getReceiver that returns the receiver.
A method named getMessage that returns the message.
Destructor: Releases the dynamically allocated memory.

Non-member function:

A method named displayMessage that takes a const Message& parameter and prints the
message.
Display Format:
Sender: sender
Receiver: receiver
Message: message_body

Object Oriented Programming


CE101T-Spring 2024

Common questions

Powered by AI

Resizing a rectangle using the displayAfterResize function modifies the width and height attributes by a specified factor, illustrating encapsulation and reuse of methods in object-oriented programming . This operation demonstrates how internal state modifications can be performed on an instance without exposing internal data directly, while also highlighting potential pitfalls such as unintentionally altering original dimensions needed elsewhere in the application .

Dynamic memory allocation in the CashRegister class allows it to manage memory efficiently by allocating memory for private data members only when needed, during instance creation, and releasing it during destruction, which optimizes resource usage . However, potential concerns include memory leaks if the destructor fails to release all allocated memory or if there is improper management of pointers, impacting application stability if not carefully handled .

Having separate files for structures in C++ encapsulates implementation details and fosters modularity, allowing independent development and testing of each component . It supports easier maintenance and scalability as changes in one structure do not impede others, and promotes reuse in different parts of the application or across projects .

The non-member display function for the CashRegister class enhances separation of concerns by keeping display logic outside the class, promoting cleaner design and potential reuse in different contexts . Challenges include maintaining consistency across various displays since any change in format requires updates in multiple places, and the need to manage access to private data, even though the method takes the class object as a constant reference .

While collaboration is encouraged, potential drawbacks include the risk of implicit plagiarism if students inadvertently incorporate peers' ideas without proper attribution, or reliance on others leading to unequal learning experiences among students . Moreover, it may encourage surface-level understanding rather than deep learning if students depend heavily on group knowledge rather than individual comprehension .

The GitHub workflow streamlines version control by enabling clear tracking of code changes, fostering collaboration through branching, and supporting rollback to previous states if necessary . Benefits include facilitated team collaboration and enhanced code management; however, challenges involve a learning curve in mastering Git operations and potential merge conflicts requiring resolution to integrate contributions effectively .

The destructor in the Rectangle class is critical for preventing memory leaks by ensuring that all dynamically allocated memory is released when an object goes out of scope . It maintains application performance and stability by managing memory resources efficiently, ensuring the system does not exhaust memory available to other processes or components . However, improper implementation could lead to resource leaks and degrade system performance .

Encapsulation in the Message class is demonstrated through setter and getter methods by controlling access to private data members, ensuring data integrity by allowing controlled modification and retrieval of values . This prevents unauthorized access and manipulation of internal data, highlighting encapsulation's role in enforcing security and integrity in object-oriented programming design .

The naming convention for assignment submissions standardizes the format, aiding in easy identification and retrieval of documents, which streamlines organization and evaluation for instructors . It ensures that each submission is uniquely identifiable by combining roll number and assignment number, minimizing the chances of misplacement or confusion during the grading process .

Default constructors in the Rectangle and Message classes play a crucial role in object initialization by allocating and resetting memory for instance variables, ensuring the objects are in a consistent initial state before use . They automate the setup process and prevent errors associated with uninitialized variables, enhancing reliability and predictability of object behavior .

You might also like