This needs to be done in C++ and be able to be compiled in Visual Studio (I have
ID: 669048 • Letter: T
Question
This needs to be done in C++ and be able to be compiled in Visual Studio (I have 2012). PLEASE read through the problem and make sure everything is included, as I have asked this question a couple of times and have gotten grossly incorrect answers and no replies when I have asked for clarification on something. The program needs to default to the following if nothing is supplied: Vanilla for a cone flavor, 1 for the number of scoops, and Sugar for the cone type. It needs to ask for the number of cones. For each cone, it needs to ask for the cone type and number of scoops. For each scoop, it needs to ask for a flavor. Price needs to be calculated by the number of scoops, with an extra charge for the waffle cone (amounts are specified in the problem below). If you have any questions, PLEASE ask before answering with any code:
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. Save the file as
IceCreamCone.cpp.
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class IceCreamCone
{
string flavor;
int noOfScoops;
string tyOfCone;
float price;
public :
IceCreamCone()
{
flavor = "Vanilla";
noOfScoops = 1;
tyOfCone = "Sugar";
price = 75;
}
IceCreamCone(string f, int nos, string toc)
{
flavor = f;
noOfScoops = nos;
tyOfCone = toc;
price = (75*nos);
if(tyOfCone == "Waffle" || tyOfCone == "waffle" || tyOfCone == "WAFFLE")
{
price+=40;
}
}
void print()
{
cout<<" flavor "<< flavor <<" ";
cout<<" no Of Scoop : "<< noOfScoops <<" ";
cout<<" type of cone : "<< tyOfCone <<" ";
cout<<" price "<< price <<" ";
}
};
int main()
{
string flavor;
int noOfScoops;
string tyOfCone;
float price;
int noOfCones;
int i=0,j=0,k=0;
IceCreamCone *cone = new IceCreamCone[1000];
IceCreamCone *coneForPricing = new IceCreamCone[1000];
cout<<" Enter the number of cones "; cin>>noOfCones;
while(noOfCones--)
{
cout<<"What is the Type of cone ? "; cin>>tyOfCone;
cout<<"What is the no of scoops for the cone ? "; cin>>noOfScoops;
coneForPricing[k++] = IceCreamCone("Default flavor", noOfScoops, tyOfCone);
for(i=1; i<=noOfScoops; i++)
{
cout<<" Enter the flavor for scoop"<<i<<" "; cin>>flavor;
cone[j++] = IceCreamCone(flavor, 1, tyOfCone);
}
}
cout <<" Displaying details of all the cones (covering all the flavors) ";
for(int i=0; i<j; i++) { cout<<" "; cone[i].print(); }
cout <<" Displaying prices of cones on the basis of TypeOfCone & NoOfScoops ";
for(int i=0; i<j; i++) { cout<<" "; coneForPricing[i].print(); }
return 0;
}
Please let me know if you have any questions ?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.