100% found this document useful (1 vote)
246 views2 pages

Lab09 Home Task Manual

The document describes two homework tasks involving class inheritance and polymorphism in C++. The first task involves defining a Rectangle class with length and width attributes, and deriving a Cuboid class from Rectangle that adds a height attribute. Both classes have getter/setter methods and methods to calculate their respective areas. The second task involves defining a GraduateStudent class with student attributes, deriving a SpecializationField class that adds a specialization attribute, and implementing methods to display attributes and check specialization validity. It also describes defining a PlanePoint class with x,y coordinates and deriving a SpacePoint class that adds a z coordinate, along with methods to calculate distances between points.

Uploaded by

Ehtasham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
246 views2 pages

Lab09 Home Task Manual

The document describes two homework tasks involving class inheritance and polymorphism in C++. The first task involves defining a Rectangle class with length and width attributes, and deriving a Cuboid class from Rectangle that adds a height attribute. Both classes have getter/setter methods and methods to calculate their respective areas. The second task involves defining a GraduateStudent class with student attributes, deriving a SpecializationField class that adds a specialization attribute, and implementing methods to display attributes and check specialization validity. It also describes defining a PlanePoint class with x,y coordinates and deriving a SpacePoint class that adds a z coordinate, along with methods to calculate distances between points.

Uploaded by

Ehtasham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

5.

Homework before Lab


5.1 Problem Solution Modeling

Draw UML class diagrams of the following task. You are required to bring this design with you and
submit to your lab instructor.

5.1.1 Problem description:

Design a class named Rectangle that includes


•Data members for the length and width of a rectangle,
•Respective mutator and accessor functions to set and get values of length and width, and
•A member function named recArea() to compute the area of rectangle (length x width)

From the Rectangle class, derive a class named Cuboid that contains
•A data field named height in addition to length and width,
•Two functions named setHeight and getHeight() to set and get value of height data field, and
•A member function named cuboidArea() to calculate the area of a cuboid (length x width x height)

Draw UML diagram for each class and show inheritance relationship between these classes.

5.2 Practices from Home


5.2.1 Task-1

Consider a class named GraduateStudent that includes


 4 data members i.e.
 studentID (e.g. BI121007)
 studentName (e.g. Bilal Akhtar)
 studentCGPA (e.g. 3.98), and
 studentCreditHours (e.g. 135).
 A parametrized constructor assigning the values to all the data members as per the user’s
requirement.

Derive a class named SpecializationField from GraduateStudent class, which contains

•An additional data field named SpecializationArea


•A parameterized constructor to initialize its own data member along with data members of the base
class inherited in derived class
•SpecializationField class also contains a member function named setSpecializationArea to modify the
value of its own data field
•A function named display to show the values of its own attribute along with the attributes of its base
class
•A function named specializationValidity to display the result of validation (if the number of entered
specialization courses is 5 or more then the specialization is valid in that particular field) for a particular
graduated student.

Implement both classes and in the main() function, create an instance of SpecializationField class. Invoke
appropriate functions to display all attribute values as well as the validation of the specialization for this
particular instance.

5.2.2 Task-2

Representing a point in the plane, a class named PlanePoint has


•Two data members i.e. X and Y (correspond to x and y coordinates) of integer type,
•Two accessor functions named as getX() and getY() to get values of data members X and Y
•A function named planeDistance() that calculates and returns the distance between two points in a
plane

Derive a class named SpacePoint to imagine a point in a three-dimensional space and has following
additional features:
•A data member Z of type integer to represent the z-coordinate of a point in space
•A no-argument constructor that constructs a point with coordinates (0,0,0)
•A constructor with three arguments that constructs a point with three specified coordinate values
•An accessor function, which returns the value of data field Z
•A function named spaceDistance to return the distance between two points in the space

Implement both the classes and in the main() create two points with different dimensions and invoke
appropriate function to display the distance between these two points.

You might also like