Need help with c++ classes.

I'm supposed to re write a previously written small program using c++ classes. This program two functions to convert temperature units.

The program should consist of three files. a header file. and a file containing all the functions and another file containing the main method.

This is my conversions.h file:

1
2
3
4
5
6
7
8
9
10
11
12
#ifndef CONVERSIONS_H
#define CONVERSIONS_H

class conversions
{
public:
	conversions();
	double fahrenheitToCelsius (double fValue);
	double celsiusToKelvin (double cValue);
};

#endif 


and here is the file containing function bodies.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "conversions.h"
#include <iostream>
using namespace std;

double conversions::fahrenheitToCelsius(double fValue)
{
	double cValue = 0.0;
	cValue = (fValue-32)*5/9;
	return cValue; 
}

double conversions::celsiusToKelvin(double cValue)
{
	double kValue = 0.0;
	
	kValue = cValue + 273.15;
	
	return kValue;
}


can someone please explain how to write the other file containing the main method and to use this converting functions in the .h file?
just add a file like "main.cpp". Now use include "conversions.h" in the main.cpp
Use your class like always and then compile BOTH of the cpp files.

Like this:
g++ main.cpp conversions.cpp
Command gives a executable file (like a.out)
It seems strange that you're supposed to do this sort of problem with classes, where functions would do fine.
Classes are supposed to declare a type.
Can you think of a program where this 'conversation' can be used as a type?
Last edited on
Thanks eraggo, finally I wrote it and now its working :)

@manasij it has been previously written by myself using functions. Now I have to re write it using classes, and this is kinda the first homework i got in OOP
If it is an homework, that means the person who gave it does not have a good understanding about the application of OOP.
Don't forget to destruct conversions();
Topic archived. No new replies allowed.