Question

In: Computer Science

Objective: Create a program that has a class to represent a cup of coffee that combines...

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

  • Instance Variables
    • Name
    • Caffeine content. Coffee is around 50 to 300mg of caffeine
  • Methods
    • Accessors and Mutators for the instance variables
      • Make sure in the mutator for the caffeine content contains a check to make sure the value is between 50 and 300 inclusively
    • RiskyAmount
      • Calculates the number of coffee’s to before it would be dangerous to consume more within a short time frame, and it is based on this formula:

        cups amount = 180.0/((caffeine content / 100.0)*6.0)
      • Returns the number of coffees it would take before they could be at a health risk.

Next write a test class

  • Contains a main method
  • Creates two instances of the type Coffee
  • Have the user enter in the names and caffeine contents for both
  • Print out the results

Solutions

Expert Solution

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


Related Solutions

Objective: Create a program that has a class to represent a cup of coffee that combines...
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...
Before each class, I either drink a cup of coffee, a cup of tea, or a...
Before each class, I either drink a cup of coffee, a cup of tea, or a cup of water. The probability of coffee is 0.7, the probability of tea is 0.2, and the probability of water is 0.1. If I drink coffee, the probability that the lecture ends early is 0.3. If I drink tea, the probability that the lecture ends early is 0.2. If I drink water, the lecture never ends early. 1) What’s the probability that I drink...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
A person eats a grapefruit and drinks a large cup of coffee AND a cup of...
A person eats a grapefruit and drinks a large cup of coffee AND a cup of orange juice for breakfast (I guess they were thirsty). All these items are acidic! How will the respiratory and renal systems respond? Include a description of how the respiratory system detects the error signal and activates its response.
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Create a java program that: - Has a class that defines an exception -Have that exception...
Create a java program that: - Has a class that defines an exception -Have that exception throw(n) in one method, and be caught and handled in another one. -Has a program that always continues even if incorrect data is entered by the user -has a minimum of 2 classes in it
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game that involves betting on the sum of two dice. The player will start out with some initial total amount of money. During each round, the player can bet some money that the sum of the two dice will be equal to a certain number. If the player wins the bet, that player adds the amount of the bet to his or her current total....
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
In a coffee-cup calorimeter experiment, if we ignored the heat lost to the Styrofoam cup and...
In a coffee-cup calorimeter experiment, if we ignored the heat lost to the Styrofoam cup and the air, does this cause the heat gained by the total solution at the end to be too big or too small. Could you please explain.
A machine in the student lounge dispenses coffee. The average cup of coffee is supposed to...
A machine in the student lounge dispenses coffee. The average cup of coffee is supposed to contain 7.0 ounces. A random sample of eight cups of coffee from this machine show the average content to be 7.4 ounces with a standard deviation of 0.70 ounce. Do you think that the machine has slipped out of adjustment and that the average amount of coffee per cup is different from 7 ounces? Use a 5% level of significance. What is the value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT