I need serious help with an assignment.
Create a class called Integer and another called Double. These classes should have separate header and .cpp file
In order for you to be successful you will need to determine what the data section of the class consists of. Each of these classes should have the following functions (methods) equals - This is a void function function that sets the value of the object. For example, an instance of Double should set a double value
Double d;
d.equals(12.34);
add
sub
mul
div
Each of these functions should take its type as an argument and return the same. For instance, a Double should work on Doubles, an Integer should work on Integers
The Integer class should have a function called
toInt
Which returns a primitive integer. Basically, this is the data section that gets returned.
The Double class should have a function called
toDouble
Which returns a primitive double
In your main funciton write code to test instance of your classes
now, I have a few questions. I'm sorry if it seems.... well, silly, but I am relatively new to C++, and I'm having a little difficulty understanding what i'm supposed to do, and how to do it. of course I'm not looking for anyone to do the assignment for me, I do want to learn how to do it on my own, but I do realize I need some help.
from what I gather, the assignment is asking that I create two cpp files, one demonstrating integer and the other double, and i need to then call the files to the main.
however, I feel like something isn't quite clicking. I can't seem to call the cpp files to the main, and this is actually the first time I've worked with multiple cpp files, so I'm having a little difficulty understanding where to start.
again, I apologize if this seems silly, but I could really use some help
I have one last issue with this. I just can't find the problem in this code, and I don't know what it wants from me.
//main.cpp
#include <cstdlib>
#include <iostream>
#include "DoubClass.h"
#include "intClass.h"
using namespace std;
int main() {
toDouble doubleObject;
toInterger intergerObject;
}
//DoubClass.h
#ifndef DOUBCLASS_H
#define DOUBCLASS_H
class DoubClass {
public:
toDouble();
};
#endif /* DOUBCLASS_H */
//DoubClass.cpp
#include <iostream>
#include "DoubClass.h"
using namespace std;
DoubClass::toDouble() {
double Dn1 = 19.83;
double Dn2 = 28.74;
cout << "The sum of " <<Dn1<< " and " <<Dn2<< " is " <<Dn1 + Dn2<< endl;
cout << "The difference of " <<Dn1<< " and " <<Dn2<< " is " <<Dn1 - Dn2<< endl;
cout << "The quotient of " <<Dn1<< " and " <<Dn2<< " is " <<Dn1 / Dn2<< endl;
cout << "the product of " <<Dn1<< " and " <<Dn2<< " is " <<Dn1 * Dn2<< endl;
}
The err code i get is
In file included from DoubClass.cpp:9:0:
DoubClass.h:13:14: error: ISO C++ forbids declaration of ‘toDouble’ with no type
DoubClass.cpp:13:21: error: ISO C++ forbids declaration of ‘toDouble’ with no type
make[2]: *** [build/Debug/Cygwin_4.x-Windows/DoubClass.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
I didn't include the intClass (yes, I know one isn't capitalized and the other is, mistake on my part), but it's almost perfectly identical, just for int rather than double.
Does anyone have any idea what is happening?