In C++ Make a class CoffeeCup. A coffee cup will have following characters: type (string): mocha, cupaccino, etc. Temperature (float): represents the measure of temperature in degrees. Volume (float):volume of coffee in the cup in ml. Sugar (int): no. of teaspoons of sugar added to coffee. Provide parameterized constructor CoffeeCup(string t, float temp float vol, int sug). Provide setters & getters of temperature, sugar, volume and type. bool hasMore(): this method checks if the cup has coffee in it that a person can take a sip from. Assume that one sip consumes a volume of 0.3 ml. So do some calculations in this method to check if it has any sips left depending upon the volume available. bool isEmpty(): returns true if a person can take a sip from this cup and false otherwise. 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. Provide a method print, that displays the status of the cup with respect to all data members
#include <iostream>
using namespace std;
class CoffeeCup{
private:
string type;
float Temperature;
float Volume;
int Sugar;
public:
CoffeeCup(string t, float temp, float vol, int sug){
type=t;
Temperature=temp;
Volume=vol;
Sugar=sug;
}
//setters & getters of temperature, sugar, volume and type
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 t){
type=t;
}
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("mocha",23.45,2.3,3);
c.display();
return 0;
}
Comments
Leave a comment