Answer to Question #256598 in C++ for pinkoo

Question #256598

You are required to build a class to represent the a cup of coffee. Call your class 

CoffeeCup. A coffee cup will have following characteristics 

1. type (sting) // can be mocha, cupaccino, etc 

2. temperature (float): represents the measure of 

temperature in degrees 

3. volume (float):// the volume of coffee in the cup in ml 

liters 

4. sugar (int):// no of teaspoons of sugar added to the coffee 

5. bool hasMore(): //this method checks if the cup has coffee in it that a person can take a sip 

from. For the implementation assume that one sip consumes a volume of 0.3 ml. So you will do 

some calculations in this method to check if it has any sips left depending upon the volume 

available. 

6. bool isEmpty(): // returns true if a person can take a sip from this cup and false otherwise 

7. bool takeASip():// this method represents the actual act of sipping. One sip is taken i.e. the 

volume equivalent to one sip is taken away. 

8. Provide a method print, that displays the status of the cup with respect to all data members. 



1
Expert's answer
2021-10-25T16:54:19-0400
#include <iostream>
using namespace std;

class CoffeeCup{
 private: 
 string type;
 float Temperature;
 float Volume;
 int Sugar;
 
 public:
 CoffeeCup(string y, float temp, float vol, int sug){
 type=y;
 Temperature=temp;
 Volume=vol;
 Sugar=sug;
 }


 void setTemperature(float temp){
 Temperature=temp;
 }
 float getTemperature(){
 return Temperature;
 }
 void setSugar(int sug){
 Sugar=sug;
 }
 int getSugar(){
 return Sugar;
 }
 void setVolume(float vol){
 Volume=vol;
 }
 float getVolume(){
 return Volume;
 }
 void setType(string y){
 type=y;
 }
 string getType(){
 return type;
 }
 bool hasMore(){
 if(Volume>=0.3)
 return true;
 else
 return false;
 }
 bool isEmpty(){
 if(Volume>=0.3)
 return true;
 else
 return false;
 }
 bool takeASip(){
 if(Volume>=0.3){
 Volume-=0.3;
 return true;
 }
 else
 return false;
 }
 void display(){
 cout<<"\nType: "<<type;
 cout<<"\nTemperature: "<<Temperature;
 cout<<"\nVolume: "<<Volume;
 cout<<"\nSugar: "<<Sugar;
 }
 
};
int main()
{
 CoffeeCup c("Cuppaccino",20.45,4.3,4);
 c.display();
 




 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
APPROVED BY CLIENTS