0% found this document useful (0 votes)
7 views

Assignment _ 2

Uploaded by

May Thet Tun
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment _ 2

Uploaded by

May Thet Tun
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Define a C++ class Fraction that represents numerator and denominator.

Overload the *
operator to multiply two fractions. In the main () function, we create two Fraction objects
(f1 and f2) and perform multiplication, displaying the result.

2. Write a function calculate() that takes a pointer to an array, its size, and two pointers (sum
and average) as parameters. In the main function that creates an array of integers, initializes it
with values and calculates the sum and average of its elements using calculate() function.
After the function call, display the sum and average of the array in the main function.

3. Your task is to implement the classes Book, FictionBook and NonFictionBook using
inheritance. A base class Book represents basic book attributes like title, author, and
publication year. It also has a display method to print these attributes. Define the two derived
classes, FictionBook and NonFictionBook, inheriting from the Book class. These derived
classes add their own unique attributes (genre for fiction and topic for non-fiction) and
override the display method to include these attributes. In the main function, we create
instances of both FictionBook and NonFictionBook and call their respective display methods
to see how inheritance allows us to reuse and extend the functionality of the base class.

4. Create an Employee class with private attributes (name, basicSalary, houseAllowance,


grossSalary) and then has member functions getData() to get name and basic salary from
user and calculateGS() to calculate the gross salary. All these data are stored in employee.dat
file with binary mode.
Gross salary calculates according to the following:
basic salary <= 200000 : gross salary = basic salary + house allowance (25%)
basic salary > 200000 : gross salary = basic salary + house allowance (30%)

You might also like