The following needs to be done in C++. Please make sure that all conditions desc
ID: 668985 • Letter: T
Question
The following needs to be done in C++. Please make sure that all conditions described are met. Thanks for your help!
Create a class named IceCreamCone with fields for flavor, number of scoops, type of
cone, and price. Unless arguments are supplied, flavor defaults to “Vanilla”, number of
scoops defaults to 1, and cone type defaults to “Sugar”. The constructor calculates the
price based on 75 cents per scoop, with an additional 40 cents for a waffle cone. Write
a main()function demonstrating that the class works correctly.
Explanation / Answer
#include <iostream>
using namespace std;
class IceCreamCone
{
private:
std::string cone;
int scoops;
std::string flavor;
public:
IceCreamCone (): cone("Sugar"), scoops(1), flavor("Vanilla"){ } // Constructor without no argument
IceCreamCone (string c, int s, string f): cone(c), scoops(s), flavor(f){ } // Constructor with two argument
int PriceCalculation() {
if (cone=="waffle"){
return (scoops * 75 + 4o);
}
else{
return (scoops * 75);
}
}
};
int main()
{
IceCreamCone A1,A2("waffle",2,"Vanilla");
cout<<A1.PriceCalculation()<<endl;
cout<<A2.PriceCalculation()<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.