terça-feira, 18 de janeiro de 2011

Termómetro em C++ que permite saber a temperatura

#include <iostream>
using namespace std;
class Termometro{
int temp;
int inf, sup;
public:
    Termometro(int i=0, int s=100, int t=0){
        inf = i;
        sup = s;
        if(t<inf) temp = inf;
        else if(t>sup) temp = sup;
            else temp = t;
    }

    void aumentar(int a){
        if(a<0) return;
        temp += a;
        if(temp>sup) temp = sup;
    }

    void diminuir(int a){
        if(a<0) return;
        temp -= a;
        if(temp<inf) temp = inf;
    }

    int get(){
        return(temp);
    }
};

void main(){
    Termometro t;
    Termometro t1(0, 100, 20);
    t1.diminuir(5);
    cout << t1.get() << endl;
    system("pause");
}

Sem comentários:

Enviar um comentário