Question: Must be written in C++. Create a class named Ice Cream Cone with fields for flavor, number of scoops, type of cone, and price. Unless

Must be written in C++.

Create a class named Ice Cream Cone 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. Save the file as IceCreamCone.cpp.

Here is what I have but it's not working..

//IceCreamCone.cpp

#include

#include

using namespace std;

class IceCreamCone

{

private:

string flavor;

int scoops;

string cone;

double price;

public:

IceCreamCone();

IceCreamCone(string flavor, int scoops, string cone, double price);

void calculate();

void print();

};

IceCreamCone::IceCreamCone()

{

flavor="Vanilla";

scoops=1;

cone="Sugar";

}

IceCreamCone::IceCreamCone(string flavor, int scoops, string cone)

{

this->flavor=flavor;

this->scoops=scoops;

this->cone=cone;

calculate();

}

void IceCreamCone::calculate()

{

const double perScoop=0.75;

const double waffle=0.40;

if(cone=="waffle")

price=perScoop+waffle;

else

price=scoops*perScoop;

}

void IceCreamCone::print()

{

cout << "IceCreamCone" << endl;

cout << "flavor : " << endl;

cout << "scoops : " << endl;

cout << "cone :" << endl;

cout << "cost : $" << endl;

}

int main()

{

IceCreamCone icecream1;

icecream1.print();

IceCreamCone icecream2("mint",2,"waffle");

icecream2.print();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!