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

AssignmentAdvancedC 2023

Uploaded by

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

AssignmentAdvancedC 2023

Uploaded by

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

Assignment

1. Define a class named Money that stores a monetary amount. The class should have
three private integer variables, one to store the number of thousands, other to store
hundreds and another to store tens.
- Add a constructor
- Add accessor and mutator functions to read and set both member variables.
- Add a function that returns the monetary amount as an integer.
- Add a function that add two money (while adding two money, if the number of
hundreds is greater or equal to one thousand or the number tens is equal or greater
than hundred you have to perform conversion )

Write a program that tests all of your functions with at least three different Money objects

2. Define a class Flight in C++ with following description: [10 marks]


Private Members
A data member Flight number of type integer
A data member Destination of type string
A data member Distance of type float
A data member Fuel of type float
A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call
function CALFUEL() to calculate the quantity of Fuel
A function SHOWINFO() to allow user to view the content of all the data members

3. Write two versions of a function that takes two integers x and y as parameters and returns the first
integer raise to the power of the second (xy). You may assume that the second argument is positive.

3.1. The first version of the function should be recursive

3.2. The second version of the function should be iterative (using a loop)
4.
5. The greatest common divisor, or GCD, of two positive integers n and m is the Largest number j, such
that n and m are both multiples of j. Euclid proposed a simple algorithm for computing GCD(n,m),
where n > m, which is based on a concept known as the Chinese Remainder Theorem. The main idea of
the algorithm is to repeatedly perform modulo computations of consecutive pairs of the sequence that
starts (n,m, . . .), until reaching zero. The last nonzero number in this sequence is the GCD of n and m.

For example, for n = 900 and m = 384, the sequence is as follows:

900 mod 384 = 132

384 mod 132 = 120

132 mod 120 = 12

120 mod 12 = 0

So, GCD of 900 and 384 is 12. Write a short function to

compute GCD(n,m) for two integers n and m.

5.1. The first version of the function should be recursive

5.2. The second version of the function should be iterative (using a loop)

You might also like