#include "Ratio.h"
#include <iostream>
usingnamespace std;
class Ratio{
public:
//constructor
Ratio(int n, int d){
setNum(n, d);
}
//function to set the number to numerator and denominator
void setNum(int n = 1, int d = 1){
numerator = n;
denominator = d;
}
//function to display numerator and denominator
void getNum(){
cout << numerator << "\n" << denominator << endl;
}
private:
int numerator;
int denominator;
};
#ifndef RATIO_H
#define RATIO_H
#include <iostream>
usingnamespace std;
class Ratio{
public:
//constructor
Ratio(int n, int d);
//function to set the number to numerator and denominator
void setNum(int n = 1, int d = 1);
//function to display numerator and denominator
void getNum();
private:
int numerator;
int denominator;
};
#endif
Hate to break it to you, but you're redefining the class. Your Ratio.cpp looks almost identical to the .h. Also, in your header file: you usually don't want to use "namespace std;" in there, and you can likely delete the <iostream> include, since nothing iostream is being used.
You're getting a "Redefinition of Ratio" error because you are redefining Ratio :)
Your implementation file, Radio.cpp, should not re-declare the Ratio class ( class Ratio { ... }; ), because that is already in the header.
You should be doing it like this instead:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//constructor
Ratio::Ratio(int n, int d) {
setNum(n, d);
}
//function to set the number to numerator and denominator
void Ratio::setNum(int n, int d) {
numerator = n;
denominator = d;
}
//function to display numerator and denominator
void Ratio::getNum() {
cout << numerator << "\n" << denominator << endl;
}