Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming: class hierarch Create a simple program which uses a class hierarchy Class Hierarchy Parent class: fruit . o has these member variables string producing

image text in transcribedimage text in transcribed

Programming: class hierarch Create a simple program which uses a class hierarchy Class Hierarchy Parent class: fruit . o has these member variables string producing area: 1 e.g..Havaii, California, etc float price o has the following member function prototype: void printData) note: only prototype in this class. You will define it for each child class. e must be an abstract class Three different child classes . e must be difterent specific fruits; member variables must have ditterent values from those in other child classes e must inherit void printData) and the function must print the following information. Name of the child class (name of fruit) . A string stored in producing area . A value stored in price .Each class must have its own .cpp and h file, including constructors and destructors. The main function Write a main function which performs the following Create instances of all the child classes. Create two data containers C++ has the standard template library (STL), offering a variety of data structures. Store addresses of your objocts into vector and map as their parent class: fruit*. Research details of usage of these containers. . . e vector: it is a kind of dynamic array. Store your items dynamically by adding the address of each (Eruit*). e map: you can store and access an element by a kay which can be any data type. In this assignment, use strings of fruit name as keys, e.g., "apple", "melon", "pear", and so on. note: use string class. do not use char as a key, or you could face a segmentation fault in some cases Define a function named inspectFruit which calls the polymorphic function, printData ()of the given fruit. f This is not a member function in any class. r function in any classlis void inspectFruit(fruitv) v->printData ) Call the inspectFruit function by each element of the containers. Now you have vector and map containers each of which has addresses of your objects. For each element stored in them, call the inspectFruit function. You can use iterator to access the elements if you want. As a resuit, in the output, each object will be printed twice in total. Notes Make sure that the output explains cleary what you are doing, e g., which container you are now accessing it is not acceptable ifit shows only a sequence of output by printData(). Programming: class hierarch Create a simple program which uses a class hierarchy Class Hierarchy Parent class: fruit . o has these member variables string producing area: 1 e.g..Havaii, California, etc float price o has the following member function prototype: void printData) note: only prototype in this class. You will define it for each child class. e must be an abstract class Three different child classes . e must be difterent specific fruits; member variables must have ditterent values from those in other child classes e must inherit void printData) and the function must print the following information. Name of the child class (name of fruit) . A string stored in producing area . A value stored in price .Each class must have its own .cpp and h file, including constructors and destructors. The main function Write a main function which performs the following Create instances of all the child classes. Create two data containers C++ has the standard template library (STL), offering a variety of data structures. Store addresses of your objocts into vector and map as their parent class: fruit*. Research details of usage of these containers. . . e vector: it is a kind of dynamic array. Store your items dynamically by adding the address of each (Eruit*). e map: you can store and access an element by a kay which can be any data type. In this assignment, use strings of fruit name as keys, e.g., "apple", "melon", "pear", and so on. note: use string class. do not use char as a key, or you could face a segmentation fault in some cases Define a function named inspectFruit which calls the polymorphic function, printData ()of the given fruit. f This is not a member function in any class. r function in any classlis void inspectFruit(fruitv) v->printData ) Call the inspectFruit function by each element of the containers. Now you have vector and map containers each of which has addresses of your objects. For each element stored in them, call the inspectFruit function. You can use iterator to access the elements if you want. As a resuit, in the output, each object will be printed twice in total. Notes Make sure that the output explains cleary what you are doing, e g., which container you are now accessing it is not acceptable ifit shows only a sequence of output by printData()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions