Answer to Question #315906 in C++ for khan

Question #315906

Create an IceCreamCone c++ class with fields for flavor, number of scoops, cone type, 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.


1
Expert's answer
2022-03-23T13:45:46-0400
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


class IceCream {
public:    
    IceCream(string flavor="Vanila", int n_scoops=1, string cone_type="Sugar");
    void print(ostream& os);


private:
    string flavor;
    int num_scoops;
    string cone_type;
    double price;
};


IceCream::IceCream(string fl, int n_s, string cone)
{
    flavor = fl;
    num_scoops = n_s;
    cone_type = cone;


    price = 0.75 * num_scoops + 0.40;
}


void IceCream::print(ostream& os)
{
    os << num_scoops << " " << flavor << " scoop(s) in "
       << cone_type << " cone: ";
    cout << fixed << setprecision(2) << "$" << price << endl;
}


int main() {
    IceCream iceCream;
    iceCream.print(cout);


    return 0;
}

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