### Can seem to figure this out.

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)

 ``123456789101112131415161718192021222324252627282930313233`` `````` #ifndef APOWER_H // Preprocessor #define APOWER_H #include #include 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 here is the .cpp file
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include 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(); }; ``````

Error: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

This is the error I am getting, I just can not seem to solve this issue, I am kind of stuck and any help would be outstanding, thanks
Line 10 you are trying to use an argumented constructor no such constructor exist. Your next error will be line 23 you are calling a function that doesn't exist.

Also line 26 you are not dereferencing your pointer and then you will run into the << operator has no idea what to do with an Apower object.

 ``1234567891011121314151617`` `````` 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)); } }``````

You are going to get a warning from this that not every path returns a value, might want to rethink your logic
Last edited on
Topic archived. No new replies allowed.