Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Assignment 2

The document describes Assignment 2 for CS 115 which involves writing C++ code to model distances and boxes. Students must write a Distance class with feet and inches data members and conversion functions. A Box class must be written with Distance data members for dimensions, constructors, comparison functions, and a volume calculation function. The main program tests Box objects, compares volumes, and outputs box details. Validity checks on distances and dimensions are required. The assignment is worth 20 marks and is due by the specified deadline.

Uploaded by

Mikhail V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 2

The document describes Assignment 2 for CS 115 which involves writing C++ code to model distances and boxes. Students must write a Distance class with feet and inches data members and conversion functions. A Box class must be written with Distance data members for dimensions, constructors, comparison functions, and a volume calculation function. The main program tests Box objects, compares volumes, and outputs box details. Validity checks on distances and dimensions are required. The assignment is worth 20 marks and is due by the specified deadline.

Uploaded by

Mikhail V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 115: Object-Oriented Design

Assignment No. 2

Deadline: As specified on UR Courses


Total Marks: 20

Instructions:
• Make sure that you read and understand each instruction.
• The assignment contains a single problem divided into three subtasks.
• Write all your code in a single .cpp file.
• Name the .cpp file as IDNumber.zip (e.g., 200449669.zip).
• Submit the .cpp file on UR Courses within the deadline.
• Start early otherwise you will struggle with the assignment.
• Not following instructions will result in deduction of marks.
• Write your own solutions. A copied solution will result in a zero mark for both parties
involved.

1. Write a class named Distance with the following specifications:


• Two data members: feet(int) and inches(float)
• Two overloaded constructors: one that takes no argument and the other that takes two
arguments. Zero argument constructor initializes data members from 0 whereas two
argument constructor initializes data members from the passed arguments.
• Two getters and two setters corresponding to two data members.
• A member function named toDecimal that converts a distance to decimal, e.g., if a
distance equals 2 feet and 6 inches then it would become 2.5 in decimal.
• A member function named toString that returns a string representation of a distance,
e.g., if a distance equals 2 feet and 6 inches then the corresponding string
representation should be 2’-6”.

2. Write a class named Box with the following specifications:


• Three data members: length, width, and height. All data members are of type Distance.
• Two overloaded constructors: one that takes no argument and the other that takes
three arguments. Zero argument constructor initializes data members from 0 whereas
three argument constructor initializes data members from the passed arguments. At
least one of the constructors should use an initializer list.
• A copy constructor.
• Three getters and three setters corresponding to three data members.
• A member function named volume that returns the volume of a Box object, i.e.,
length*width*height.
• Three member functions named greaterThan, lessThan and equalTo to compare two Box
objects based on their volume. Each function must return a Boolean value.
• A static data member count(int) which is used to count Box objects active at any time.
• A getter for count.
• The class must contain a few constant functions (decide which of the above functions
are good candidates for that)

3. In your main program:


• Create 4 Box objects (at least one should be created using copy constructor).
• Display number of boxes in the program.
• Display dimensions of all boxes.
• Display whether any of those boxes are equal in volume.
• Display dimensions of the largest box.
• Display dimensions of the smallest box.
• Allow one or more boxes to go out of scope (end their lifetime) and display the
remaining boxes.

A sample output of main program is shown below:

There are 4 Boxes in this program.

Box 1 dimensions: length = 5'-3", width = 2'-7.5", height = 3'-8" and volume = 50.53125
Box 2 dimensions: length = 4'-6", width = 9'-3", height = 2'-4" and volume = 97.125
Box 3 dimensions: length = 4'-6", width = 9'-3", height = 2'-4" and volume = 97.125
Box 4 dimensions: length = 3'-3", width = 9'-3", height = 2'-4" and volume = 70.145828

Box 2 and Box 3 are equal.

The largest box has dimensions: length = 4'-6", width = 9'-3", height = 2'-4" and volume = 97.125
The smallest box has dimensions: length = 5'-3", width = 2'-7.5", height = 3'-8" and volume = 50.53125

Now there are 2 Boxes left in this program.

Your code should have the following validity checks:


• Feet or inches can not be negative.
• Inches cannot be greater than or equal to 12.
• A single dimension of a box cannot exceed 1000 feet.

Apply these checks in constructors as well as setters.


Marks Distribution:

Marks
Distance class, its data members and member functions 4
Box class, its data members and member functions 8
Main function and its code 4
Validity checks 2
Code organization and readability 2
Total 20

You might also like