Create a class called Number and another called Double. These classes should have separate header and .cpp file
Each of these classes should have the following functions (methods)
greater - This is a void function function that sets the value of the object. ex: double should have a double value
Double c;
c.greater(2.25);
plus
minus
times
divide
-Each of these functions should take its type as an argument and return the same.
-The Integer class should have a function called
aInt() returns a primitive integer ,it is the data section that gets returned.
-The Double class should have a function called aDouble this returns a primitive double
-the main funciton should have the code thattests the instance of your classes
Can anyone provide me an example on how I would set something similar up?
This is what I have so far and I am so lost. I started it but I think it is way off. I really need help on at least an example on how to do the integer class. I don't understand where to place the aint() function or what it does. If someone could show me where to place that in the code it would help alot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
//Number.h (header)
#ifndef NUMBER
#define NUMBER
class NUMBER
{
private:
int num1;
int num2;
public:
void setGreater (int n, int p);
Number plus(Number &n);
Number minus (const Number &n);
Number times (const Number &n);
Number div ( const Number &n);
};
//cpp file
#include <iostream>
#include "Number.h"
using namespace std;
void Number::setNumber(int n, int p)
{
num1=n;
num2=p;
}
Number Number::plus(const Number&n)
{
Number tmp;
tmp.num=(num1+num2);
return tmp;
}
Number Number:: minus (const Number &n)
{
Number tmp;
tmp.num=(num1-num2);
return tmp;
}
Number Number::times(const Number &n)
{
Number tmp;
tmp.num=num1*num2;
return tmp;
}
Number Number:: div (const Number &n)
Number.tmp;
tmp.num=num1/num2;
}
//main file
#include <iostream>
#include "Number.h"
using namespace std;
int main()
{
Number n1,n2,n3;
n1.setNumber (1,2);
n2.setNumber (1,2);
n3.printNumber;
return 0;
}
|