Hi,Im having a hard time understanding the fundamentals of Object oriented programming.Ive made a really simple program that allows a user to enter a number, and then i have a function that doubles this number and returns it.
But im still having the same errors that i had when i tried to do my labwork,im wondering if you guys could take a look and see what mistakes im making.
Many thanks
MAIN.CPP
// program that prompts user to enter a numer
// function then called to double number
// and return it
#include <iostream>
#include "Number.cpp"
using namespace std;
main(){
Number* number; // i have no idea what this does!I think its a variable declared.
int input;
cout << "Welcome to the double your number program." << endl;
cout << "Begin by entering a number: ";
cin >> input;
// create a new object of class
number = new Number();
// call the function
number->doubleNumber(input);
cout << "Your number doubled is: " << endl;
}
HEADER FILE
#ifndef NUMBER_H
#define NUMBER_H
class Number(){
public:
Number(); // Default constructor
int doubleNumber(int);
private:
int num; //will be used for the doubleNumber function
}
#endif
SOURCE FILE FOR FUNCTION
#include "Number.hpp" // MUST INCLUDE HEADER FILE
Number::Number() {
num = 0;
}
Number::doubleNumber(int input) {
num = input; // numnber passed in(input variable),is assigned to num variable.
num = num*2; // algo
return num;
}