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 Provide these methods 1. parameterized constructor CoffeeCup(string t, float temp float vol, int sug) 2. Provide setters for temperature, and sugar and volume. 3. Provide getters of temperature, sugar, volume and type. 4. 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 5. void cooldown(): the process of cooling down. The temperature goes down by one degree but will not go below 0 6.
#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;
}
void heatUp(){
if (temperature==100)
temperature=100;
else
temperature=temperature+1;
}
void cooldown(){
if (temperature==0)
temperature=0;
else
temperature=temperature-1;
}
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();
c.heatUp();
c.display();
c.cooldown();
c.display();
return 0;
}
Comments
Leave a comment