0% found this document useful (0 votes)
39 views1 page

Question-1: Create A Class Rational Which Represents Two Data Members Num and Dnum With

This document provides two questions to create classes in C++. For question 1, it asks to create a Rational class with data members for the numerator and denominator. It should include default and overloaded constructors, member functions to get/set values and display in fraction format, and a function to add two rational numbers. For question 2, it asks to create a TIME class with data members for hours, minutes, seconds and constructors to initialize to zero or a constant. It also includes member functions to add two time objects and display the time in HH:MM:SS format. The main function is used to demonstrate adding and displaying times.

Uploaded by

Adnan Ahmed
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
0% found this document useful (0 votes)
39 views1 page

Question-1: Create A Class Rational Which Represents Two Data Members Num and Dnum With

This document provides two questions to create classes in C++. For question 1, it asks to create a Rational class with data members for the numerator and denominator. It should include default and overloaded constructors, member functions to get/set values and display in fraction format, and a function to add two rational numbers. For question 2, it asks to create a TIME class with data members for hours, minutes, seconds and constructors to initialize to zero or a constant. It also includes member functions to add two time objects and display the time in HH:MM:SS format. The main function is used to demonstrate adding and displaying times.

Uploaded by

Adnan Ahmed
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/ 1

Question-1: Create a class Rational which represents two data members Num and Dnum with

type integer. Create members function that gets the Num and Dnum from the user and
ShowRational () member function that displays the rational number in p/q format. Create a
default constructor that automatically sets the rational data members to 0 and 1. Create an
additional overloaded constructor for this class. This constructor receives integers as parameters
and assigns the values to the class data members. The class also includes a member function
AddRational (Rational, Rational) to add two rational objects. Create a main () function that
declared three objects of rational, add two rational no’s and then show the sum of two rational by
the main function. Demonstrates each function works correctly.
Question-2: Create a class called 'TIME' that has
- three integer data members for hours, minutes and seconds
- constructor to initialize the object to zero
- constructor to initialize the object to some constant value
- member function to add two TIME objects
- member function to display time in HH: MM: SS format
Write a main function to create two TIME objects, add them and display the result in
HH: MM: SS format.

You might also like