This is what I am trying to accomplish...You need to implement a recursive function namely Apowerfun. Apowerfun is a
power function which receives the value of a real number āaā raised to the
power of a non negative integer ānā.
Write a header file which that you will call Apower.h. The file contains a
recursive method Apowerfun that has two parameters:
1- First parameter is a of type float
2- Second parameter is n of type long
and returns the an
value as a float.
Write a C++ file which you will call Apower.cpp that reads in a long non
negative number n, and a float number a, and prints the corresponding a
number. And my code is below with the error(s)
here is the header file
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
|
#ifndef APOWER_H // Preprocessor
#define APOWER_H
#include <iostream>
#include <iomanip>
using namespace std;
class Apower
{
public:
float apowerfun(float a, long n)
{
if (a==0)
{
return (0);
}
if (n==0)
{
return (1);
}
else if (n > 0)
{
return (a * apowerfun(a,n-1));
}
}
};
#endif
|
And the .cpp file
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
|
#include <iostream>
#include <iomanip>
using namespace std;
#include "APower.h" //implementation of the employee class
void main()
{
Apower ap1(float a, long n);
float a;
long n;
cout << "Enter base as an integer: ";
cin >> a;
cout << "Enter exponent as an integer: ";
cin >> n;
Apower* apowerfun = new Apower(ap1(a,n));
cout << "\nResult: " << apowerfun << endl;
cin.get();
cin.get();
};
|
And here is the error(s):
1>Apower.obj : error LNK2019: unresolved external symbol "class Apower __cdecl ap1(float,long)" (?ap1@@YA?AVApower@@MJ@Z) referenced in function _main
1>C:\Users\Friedmann\Desktop\Data Structures\Assignment 7\Apower\Debug\Apower.exe : fatal error LNK1120: 1 unresolved externals
I know part of the issue is I need to create a new object to link it to the header file but the issue is I am not exactly sure how to do it correctly. I have tried some different things but none of them have worked. Any help would be awesome, thanks