Lab 11 question
Lab 11 question
Question 1
void displaySides()
Display values of a, b and c.
C) In main()
Create an object of class PythagorasTriangle using the new operator.
Get user input in the main function for 2 sides (side a and side b) of a Pythagoras Triangle and pass
it to the setData(..) function as arguments. Invoke the setData(..) function through the dynamic
object .
Using the same object, call calcHypotenuse() and displaySides().
Deallocate the memory for the object.
[Note: refer to sample output screen below]
1/3
DCP5201 | OBJECT ORIENTED PROGRAMMING LAB 11
Question 2
Modify main function of Question 1 solution so that the program will repeat as long as user wants to. Use a
do-while loop.
[Note: refer to sample output screen below]
Question 3
2/3
DCP5201 | OBJECT ORIENTED PROGRAMMING LAB 11
C) In main():
(i) Prompt the user to enter the number of types of canned food.
(ii) Create pointer tp of class canFood
(iii) Use the pointer tp to create a dynamic array of canFood using new operator. (the size of the array
will be the number of types of canned food entered by the user earlier)
(iv) In a for-loop that loop through the array, using pointer tp:
Call get_Product( )
Call calculate_Total( )
(v) In another for-loop that loop through the array, using pointer tp:
Call display_product( )
(vi) Deallocate the memory of the dynamic array.
Product ID : 1001
Total price : RM150
Product ID : 1002
Total price : RM135
3/3