Dinesh is working in a supermarket and he is developing a program to calculate the cost of different types of items. Help him write the program that does the following:a) Create a base class, ItemType, with one virtual function double calculateAmount()b) Create a class called wooden that extends ItemType class with a number of items and cost as its private attributes. Obtain the data members and override the virtual function and calculate the total amount.c) Create a class called electronics that extends ItemType class with cost as its private attribute. Obtain the data member and override the virtual function and calculate the amount with 20% discount.Note: This question helps in clearing Infosys tests.Input format :The first line consists of an integer choice (1 or 2) representing the choice of item type.If the choice is 1 (wooden items), the next line consists of two space-separated integers: noOfItems and cost, representing the number of wooden items and their individual cost, respectively.If the choice is 2 (electronics), the next line consists of a single floating-point number cost, representing the cost of the electronic item.Output format :The output prints a floating-point number representing the calculated total cost of the chosen item type rounded off to two decimal places.Code constraints :10 < cost < 1060 < noOfItems < 20Sample test cases :Input 1 :15 840.5Output 1 :4202.50Input 2 :21800.56Output 2 :1440.45Note :
Question
Dinesh is working in a supermarket and he is developing a program to calculate the cost of different types of items. Help him write the program that does the following:a) Create a base class, ItemType, with one virtual function double calculateAmount()b) Create a class called wooden that extends ItemType class with a number of items and cost as its private attributes. Obtain the data members and override the virtual function and calculate the total amount.c) Create a class called electronics that extends ItemType class with cost as its private attribute. Obtain the data member and override the virtual function and calculate the amount with 20% discount.Note: This question helps in clearing Infosys tests.Input format :The first line consists of an integer choice (1 or 2) representing the choice of item type.If the choice is 1 (wooden items), the next line consists of two space-separated integers: noOfItems and cost, representing the number of wooden items and their individual cost, respectively.If the choice is 2 (electronics), the next line consists of a single floating-point number cost, representing the cost of the electronic item.Output format :The output prints a floating-point number representing the calculated total cost of the chosen item type rounded off to two decimal places.Code constraints :10 < cost < 1060 < noOfItems < 20Sample test cases :Input 1 :15 840.5Output 1 :4202.50Input 2 :21800.56Output 2 :1440.45Note :
Solution
Here is a Python solution for the problem:
class ItemType:
def calculateAmount(self):
pass
class Wooden(ItemType):
def __init__(self, noOfItems, cost):
self.noOfItems = noOfItems
self.cost = cost
def calculateAmount(self):
return self.noOfItems * self.cost
class Electronics(ItemType):
def __init__(self, cost):
self.cost = cost
def calculateAmount(self):
return self.cost * 0.8 # 20% discount
def main():
choice = int(input())
if choice == 1:
Similar Questions
You're tasked with designing an employee management system for a company. You've created a base class Employee with virtual functions calculateSalary() and displayDetails(). Now, you need to implement derived classes FullTimeEmployee and PartTimeEmployee. How would you utilize virtual functions to calculate the salary and display details for each type of employee?
Create a class Car. Car has its data members speed and colour under private. Void speed(int car_speed) and void colour(string car_colour) are the member functions in class Car. Create one more class Audi. Audi wants to access the private data members of Class Car. Along with the inherited method, Audi has 5 airbags and so it has additional member function void air_bag_count( ). There is one more class Audi_a6 which is the latest version and inludes all the features of audi along with additional ones. It has additional vent for AC ...and so it has additional member function Car_ac( ) .Identify the type of inheritance..Create object for each class, supply value to all classes and display speed and colour for car, speed, colour and airbag details for audi. And car speed, colour, airbag detail, ac details for Audi_A6?
Write a program to demonstrate multiple inheritance. Consider two base classes worker(int code, char name, float salary), HR who calculates the different allowances like (float DA, HRA). You have another class manger with calculates (float TA(is 10% of salary), gross salary) where the properties of worker and HR is used in this class. Write a test application class to create an array of 10 workers and display their details with gross salary.
Ce cuvant cheie trebuie utilizat pentru a crea o metoda virtuala intr-o clasa ? What keyword should be used to create a virtual method within a class ?Un punctoverwriteoverridevirtual=0abstract
/** A simulated cash register that tracks the item count and the total amount due.*/public class CashRegister{ // private data--see the "Designing the Data Representation" section /** Adds an item to this cash register. @param price the price of this item */ public void addItem(double price) { // implementation--see the "Implementing Instance Methods" section } /** Gets the price of all items in the current sale. @return the total amount */ public double getTotal() { // implementation--see the "Implementing Instance Methods" section } /** Gets the number of items in the current sale. @return the item count */ public int getCount() { // implementation--see the "Implementing Instance Methods" section } /** Clears the item count and the total. */ public void clear() { // implementation--see the "Implementing Instance Methods" section }}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.