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.
#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;
}
Comments
Leave a comment