Question
c++ So we should create a class named Fruit. we need to do the Fruit class's interface and implementation seperatly. Interface of the Fruit class
c++ So we should create a class named Fruit. we need to do the Fruit class's interface and implementation seperatly. Interface of the Fruit class would be Fruit.h and implentation would be Fruit.cpp. We need 3 private members: fruit's cost (double), fruit's ID(int or long), fruit's description(not more than 100 character lengh and ability to use spaces inside of it, we can use string type)
we should create public getters and setters for each of the members. We also need constructors.
default constructor should initialize fruit's ID to a serial increasing number - one more than the last object created using this constructor (we should use a static member), Initialize fruit's desc to empty string and cost should be initilized to 0.
we need to have a copy constructor( not the default copy constructor).
we need to have a conversion constructor which is accapting a long for the fruit's ID, the default values of the empty string for the fruit's desc, and 0 for cost.
and another constructor which takes argument for each of the members: fruit ID, fruit desc, fruit cost.
we need a destructor which deletes memory allocated for the character pointer.
we need addition operators. every function must return a value with the same data type as the cost varibale. Example: s = fruit1 + fruit2, s is the cost of the 2 fruits, s = fruit2 + m, m can be scalar variable, constant, or expression, s = fruit2 + m
we also need subtraction operators. every function must return back a value with the same data type as the cost variable.
s = fruit1 - frui2, s is the unit cost of frui1 - fruit2. s = frui2 - m, s = m - frui2
We need comparison operators ==, >, <, and all should compare the cost of fruit1 obj to the cost of fruit2 obj with the boolean return value.
Insertion(<<) operator needs to be overloaded and print this: "Info for fruit s:" (s is the fruits ID)
"Desc:
"Cost:
Extraction>> operator also needs to be overloaded, and print this: " Enter Fruit ID:
"Enter fruit desc: < fruit desc needs to be entered here>"
"Enter fruit cost: < cost needs to be entered here>" this method should create a console dialog to allow entering all of the information for the fruit obj.
Finally, we need to provide an overloaded assignment operator which does member-wise assignmt. (we cannot use default memberwise assgnmt provided by the complier).
THere should be no inline methods/functions for the class
If possible you can create testing class that tests this code and specifically the use of insertion<< and extraction>> operators.
Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started