Inheritance x Polymorph is m

download Inheritance x Polymorph is m

of 1

Transcript of Inheritance x Polymorph is m

  • 7/25/2019 Inheritance x Polymorph is m

    1/1

    1.

    Write a base class named MenuItems that includes a method printToScreen that prints name of

    items to the screen. It should have a set method or constructor or both related member variable

    name. Write two derived classes, Beverage and Snack. For Beverage class, it should have 3 prices:

    for small, mediun and large sizes. It should have a method named printToScreen. Write a

    constructor to handle the prices of the thre sizes, Snack has 1 member variable: price and also

    PrintToScreen and a constructor to handle the price of a snack object. In the main method,declare an array of 7 objects of MenuItem. The use 4 elements to store information of 4 elements

    for the drinks and 3 snack items for snack items. Then display the menu items similar below.

    2.

    Create a base class and it as Employee. It should have a member variable empName, a constructor

    so that the employee name can be saved for each object and a method calcPaidCheck. Create a

    derive class named HourlyWorker and create a method calcPaidCheck where in Paid amount =

    hourly rate X hours worked. Create again a derived class named SalaryWorker and create a

    method calcPaidCheck wherein paid amount = annual salary / 12.

    In the main method create an array of Employee and test with 2 workers employees and 2 salary

    employees.