week 4

I have been terrible at posting in this blog, so I am some weeks behind with my blog right now.

This post is about the Kelvin/Fahrenheit/Celsius converter I did during week 3. I did write a fully functional code but realized that I just used ordinary functions, when the assignment was to create a class.

I had some problems understanding classes and splitting code into header and cpp files before, but completing this assignment greatly helped me understand how this worked. The assignment weren’t really that hard, but I have found that while I sometimes can understand the code the teacher shows us during the lectures it still can be a challenge to use that knowledge.

Here is the code I wrote in my header file:

#pragma once

class TemperatureConverter
{
float x;
float answer;
public:
/*int convert;*/
TemperatureConverter();

/*int choose(int);*/

float Farenheit_Celsius(float);
float Farenheit_Kelvin(float);
float Celsius_Farenheit(float);
float Celsius_Kelvin(float);
float Kelvin_Celsius(float);
float Kelvin_Farenheit(float);
int getType1(int);
void GetValue();
void Answer();
};

 

And just an example of how I used it:

cpp:

float TemperatureConverter::Farenheit_Celsius(float y )
{
x = (y – 32.0f) * 5.0f / 9.0f;
return x;

}

main:

if (choose == 1)
{
tmp.Farenheit_Celsius(temp);
tmp.GetValue();
}
else if (choose == 2)

 

Lämna en kommentar