Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- //tutorial 5 Section B
- #include <iostream>
- using namespace std;
- class Temperature
- {
- private:
- // Declare private data members here
- double tempCel;
- double tempFar;
- public:
- Temperature(char name, double val){ // complete this constructor
- tempCel = 0;
- tempFar = 32;
- if (name == 'c'|| name == 'C'){
- tempCel = val;
- tempFar = (9.0/5.0)*tempCel + 32;
- }
- else if(name == 'f' || name == 'F'){
- tempFar = val;
- tempCel = (tempFar - 32)/(9.0/5.0); //need to add .0 since double
- }
- else{
- cout << "Enter a valid value: ";
- }
- }
- double getCels(){
- return tempCel;
- }
- double getFar(){
- return tempFar;
- }
- // Declare/define other public members/functions here,
- // as per the instructions given in the abovementioned
- // question.
- };
- // Driver program
- int main()
- {
- Temperature t1('C',100),t2('F',100);
- cout<<"t1 = "<< t1.getCels()<<" C\n";
- cout<<"t1 = "<< t1.getFar()<<" F\n";
- cout<<"t2 = "<<t2.getCels()<<" C\n";
- cout<<"t2 = "<<t2.getFar()<<" F\n";
- t1 = t2;
- cout<<"After assigning t2 to t1"<<endl;
- cout<<"t1 = "<<t1.getCels()<<" C\n";
- cout<<"t1 = "<<t1.getFar()<<" F\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement