Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1 - Create a class Create a class called cuboid. The class has the attributes ( data members ) length, width and height, each

Task 1- Create a class
Create a class called cuboid. The class has the attributes (data members) length, width
and height, each of which defaults to 1. It has methods (member functions) that calculate
the perimeter, surface area and volume of the cuboid. It has set and get functions for
length, width and height. The class in your program should be written based on the class
definition in Listing 1. The cuboid.h file can be downloaded from Ulwazi.
Listing 1: cuboid.h
1 #ifndef CUBOID_H
2 #define CUBOID_H
3
4 class cuboid
5{
6 public: //It is good practice to ensure only functions are public members and variables are private
members
7 cuboid(double l =1.0, double w =1.0, double h =1.0);
8 void setLength(double l); //Used to set a user defined vaklue for the length
9 void setWidth(double w); //Used to set a user defined vaklue for the width
10 void setHeight(double h); //Used to set a user defined vaklue for the height
11 double getLength(); //Used to get the value of the length.
12 double getWidth(); //Used to get the value of the width
13 double getHeight(); //Used to get the value of height
14 double perimeter(); //Used to calculate the perimeter of the cuboid
15 double surfaceArea(); //Used to calculate the surface area of the cuboid
16 double volume(); //Used to calculate the volume of the cuboid
17
18 private: //These are private attributes. They can only be accessed using the get and set functions
19 double length;
20 double width;
21 double height;
22};
23
24 #endif
The program should read from the input.txt shown in Listing 2. For each line in the
input.txt file, the first value represents the length, the second value is the width and the
third value is the height. For example, in the first line the length =4, the width =5 and the
height =6. The other lines in the input text file can be read in the same way. An output
in the form shown in Listing 3 should be generated by your program, where the printed val-
ues for the length, width and height are obtained using the getLength(), getWidth() and
getHeight() methods (functions) in the cuboid class. This output should be written to a
file called output.txt.
Listing 2: input.txt
1456
2723
312825
49.515.2318.9
523.1835.49
66.173
7202122.59
81116.0819.5
91.112.223.33
105.239.518.59
Page 2 of 6
Listing 3: output.txt
1 Length =4.00 Perimeter =60.00
2 Width =5.00 Surface Area =148.00
3 Height =6.00 Volume =120.00
4
5 Length =7.00 Perimeter =48.00
6 Width =2.00 Surface Area =82.00
7 Height =3.00 Volume =42.00
8
9 Length =12.00 Perimeter =180.00
10 Width =8.00 Surface Area =1192.00
11 Height =25.00 Volume =2400.00
12
13 Length =9.50 Perimeter =174.52
14 Width =15.23 Surface Area =1224.16
15 Height =18.90 Volume =2734.55
16
17 Length =23.18 Perimeter =150.33
18 Width =5.40 Surface Area =764.87
19 Height =9.00 Volume =1126.69
20
21 Length =6.10 Perimeter =64.40
22 Width =7.00 Surface Area =164.00
23 Height =3.00 Volume =128.10
24
25 Length =20.00 Perimeter =254.36
26 Width =21.00 Surface Area =2692.38
27 Height =22.59 Volume =9487.80
28
29 Length =11.00 Perimeter =186.32
30 Width =16.08 Surface Area =1409.88
31 Height =19.50 Volume =3449.16
32
33 Length =1.11 Perimeter =26.64
34 Width =2.22 Surface Area =27.11
35 Height =3.33 Volume =8.21
36
37 Length =5.23 Perimeter =133.28
38 Width =9.50 Surface Area =647.03
39 Height =18.59 Volume =923.64

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

2. Prevent fights by avoiding crowded work spaces.

Answered: 1 week ago