Objective: Write a class called Beer with the following Instance Variables Name
ID: 3726662 • Letter: O
Question
Objective:
Write a class called Beer with the following
Instance Variables
Name
Alcohol content. Beer is around 0.05 or 5%
MethodsAccessors and Mutators for the instance variables
Make sure in the mutator for the alcohol content contains a check to make sure the value is between 0 and 1 exclusively.
Intoxicated
Takes in a parameter of type double corresponding to weight
Calculates the number of drinks required to make a person intoxicated based on this formula (0.08 + 0.015) x Weight / (12 x 7.5 x Alcohol)
Returns the number of beers it would take before they are intoxicated
Next write a test class
Contains a main method
Creates two instances of the type Beer
Have the user enter in the names and alcohol contents for both
Next enter in a weight value and it calculates how many drinks it would take for a person at that weight to become intoxicated
Print out the results
Example Output:
Let’s Party! Responsibly...
What’s the name of the first beer?
Pabst Blue Hipster
What’s the alcoholic content?
0.05
What’s the name of the second beer?
Moo Brew
What’s the alcoholic content?
0.08
What’s the weight of the person consuming said beverages?
150
It would take 3.166 Pabst Blue Hipster beers to become intoxicated.
It would take 1.979 Moo Brew beers to become intoxicated.
Later Tater
Explanation / Answer
Screenshot:-
--------------------------------------------------------------------------------------------------------------------------------
Code:-
#include<iostream>
#include<string>
//namespace for I/O
using namespace std;
//class creation
class Beer {
//Member variables
private:
string name;
float aContent;
double weight;
public:
//constructor
Beer() {
}
//Accessors
string getName() {
return name;
}
float getaContent() {
return aContent;
}
double getWeight() {
return weight;
}
//Mutator
void setBeer(string uName, float alCon,double w) {
//Check the alcohol content between 0 t0 1 else error message
if (alCon > 0 && alCon < 1) {
aContent = alCon;
name = uName;
weight = w;
//Number of drinks calculation
double num_drinks = (0.08 + 0.015) * weight / (12 * 7.5 * alCon);
//Display output
cout << "It would take " << num_drinks <<" " <<name<< " beers to become intoxicated ." << endl;
}
else {
cout << "Alcohol content should be less than 1"<<endl;
}
}
};
//main method
int main() {
//object creation
Beer b1,b2;
//variables to take user input
string name,name1;
float content,content1;
double weight;
//Ask user for input
cout << "Let’s Party! Responsibly..." << endl;
cout << "What’s the name of the first beer ?" << endl;
cin >> name;
cout << "What’s the alcoholic content ? " << endl;
cin >> content;
cout << "What’s the name of the second beer ?" << endl;
cin >> name1;
cout << "What’s the alcoholic content ? " << endl;
cin >> content1;
cout << "What’s the weight of the person consuming said beverages?" << endl;
cin >> weight ;
//class beer maccessor , mutator to get set values
b1.setBeer(name,content,weight);
b2.setBeer(name1, content1,weight);
cout << "Later Tater"<<endl;
return 0;
}
---------------------------------------------------------------------------------------------------------------------
Note:-
I am using visual studio 2017 c++
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.