In: Computer Science
Objective:
Create a program that has a class to represent a cup of coffee that combines the properties: name and caffeine content. The class should also have a method that calculates the number of cups that would be maximally risky to consume in a short period of time. The program should create two instances of the class coffee where the user enters their properties and should output the amount of coffees that consumed would be risky.
Requirements:
Write a class called Coffee with the following
Next write a test class
HERE IS THE CODE FOR THE COFFEE PROGRAM AS IT LOOKS IN MY SYSTEM :--
THE ORGINAL CODE THAT YOU CAN COPY DOWN AND TRY ON YOUR SYSTEM :--
#include<iostream>
#include<string.h>
using namespace std;
class Coffee{
public:
string name;
//stirng name for the name of coffee
int caffine_content; //contains the
caffine content in coffee
public:
void take_inp()
{
cout<<"Enter the coffee
name"<<endl;
cin>>name;
cout<<"enter the caffeine
content"<<endl;
cin>>caffine_content;
}
int mutators() //to
check whether the value of caffeine is within the limit or
not
{
if(!(caffine_content>=50
&& caffine_content<=300))
return 0;
else
return 1;
}
void calc_cups()
//to calculate the no. of cups that will be
risky
{
int cups=0;
//integer variable as no. of
cups will be an integer
cups= 180.0/((caffine_content /
100.0)*6.0);
cout<<"The maximal number of
cups beyond which it will become risky
="<<cups<<endl;
}
};
int main()
{
Coffee c1,c2;
// Two instance of coffee variable
c1.take_inp();
c2.take_inp();
//Now we need to call the mutator function
int x,y;
x=c1.mutators();
y=c2.mutators();
if(!x)
cout<<"The caffeine content
of "<<c1.name<<" is not in the desired
range"<<endl;
else
{
c1.calc_cups();
}
if(!y)
cout<<"The caffeine content
of "<<c2.name<<" is not in the desired
range"<<endl;
else
{
c2.calc_cups();
}
return 0;
}
OUTPUT CASE 1 :--
Enter the coffee name
AFFOGATO.
enter the caffeine content
250
Enter the coffee name
CAPPUCCINO
enter the caffeine content
270
The maximal number of cups beyond which it will become risky
=12
The maximal number of cups beyond which it will become risky
=11
OUTPUT CASE 2:--
Enter the coffee name
ESPRESSO
enter the caffeine content
120
Enter the coffee name
ESPRESSO
enter the caffeine content
270
The maximal number of cups beyond which it will become risky
=25
The maximal number of cups beyond which it will become risky
=11