Answer to Question #196101 in C++ for Navya kala

Question #196101

6)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 method calculates the price based on Rs.75 per scoop, with an additional Rs.40 for a waffle cone. Write a C++ program to calculate the price.


1
Expert's answer
2021-05-20T18:20:43-0400
#include<iostream>
#include<string>
using namespace std;
class IceCreamCone
{
private :
    string flavor;
    int numScoops;
    string coneType;
    double price;

public:
    IceCreamCone(string ="Vanilla",int =1,string ="sugar");
    void calculate();
    void print();
};


IceCreamCone::IceCreamCone(string flavor,int numScoops,string coneType)
{
    this->flavor=flavor;
    this->numScoops=numScoops;
    this->coneType=coneType;
    calculate();
}


void IceCreamCone::calculate()
{
    const int CENTS_PER_SCOOP=70;
    const int CENTS_PER_WAFFLE=40;
    if(coneType=="waffle")
        price=numScoops*CENTS_PER_SCOOP+CENTS_PER_WAFFLE;
    else
        price=numScoops*CENTS_PER_SCOOP;
}


void IceCreamCone::print()
{
    cout<<"\nIceCreamCone object details";
    cout<<"\nFlavor : "<<flavor;
    cout<<"\nNumber of scoops : "<<numScoops;
    cout<<"\nType of Cone : "<<coneType;
    cout<<"\nCost : "<<price;
}


int main()
{
    IceCreamCone icecream1;
    icecream1.print();
    IceCreamCone icecream2("Strawberry",5,"waffle");
    icecream2.print();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog