class in c++
parameterized constructor CoffeeCup(string t, float temp float vol, int sug)
1.void heatUp(): //this method represents the process of heating the coffee, the current
temperature of coffee goes up by one degree if it is below 100 and stays the same otherwise
2.void cooldown(): the process of cooling down. The temperature goes down by one degree but
will not go below 0
3.bool isSweet():// returns true if this coffee has any amount of sugar in it and 0 if not at all
4.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.
5.bool isEmpty(): // returns true if a person can take a sip from this cup and false otherwise
6.bool takeASip():// this method represents the actual act of sipping.
#include <iostream>
using namespace std;
class CoffeeCup{
private:
string r;
float Temp;
float V;
int Sugar_level;
public:
CoffeeCup(string t, float temp, float vol, int sug){
r=t;
Temp=temp;
V=vol;
Sugar_level=sug;
}
void setTemperature(float temp){
Temp=temp;
}
float getTemp(){
return Temp;
}
void setSugar(int sug){
Sugar_level=sug;
}
void coolDown(){
int te;
cout<<"\nEnter the temperature: ";
cin>>te;
if(te<100){
cout<<"Temperature is: "<<(te-1);
}}
void heatup(){
int tempe;
cout<<"\nEnter the temperature: ";
cin>>tempe;
if(tempe<100){
cout<<"Temperature is: "<<(tempe+1);
}
}
int getSugar(){
return Sugar_level;
}
void setVolume(float vol){
V=vol;
}
float getVolume(){
return V;
}
void setType(string t){
r=t;
}
string getType(){
return r;
}
bool isSweet(){
int ss;
cout<<"\nEnter the amount of sugar 0 or 1: ";
cin>>ss;
if(ss==1){
cout<<"True";
}
else if(ss==0){
cout<<"False";
}
}
bool hasMore(){
if(V>=0.3)
return true;
else
return false;
}
bool isEmpty(){
if(V>=0.3)
return true;
else
return false;
}
bool takeASip(){
if(V>=0.3){
V-=0.3;
return true;
}
else
return false;
}
void display(){
cout<<"\nType: "<<r;
cout<<"\nTemperature: "<<Temp;
cout<<"\nVolume: "<<V;
cout<<"\nSugar: "<<Sugar_level;
}
};
int main()
{
CoffeeCup n("Him",28,6.3,8);
n.display();
n.heatup();
n.coolDown();
n.isSweet();
n.hasMore();
n.isEmpty();
n.takeASip();
return 0;
}
Comments
Leave a comment