Hello, I need some help with this problem. I am not proficient in C++ and need some advice
Here are the instructions:
The Power function calculates the power of a base "a" raised to an exponent "n". Write a class which that you will call Power class in a header file called APower.h with a method "Apowerfun(a,n)" that prints the corresponding power value. Remember to use "float" for a and "long" for n and the returned value to be a "float" because the number is a real number
Example:
APowerfun(5.0,2)=(5.0)2= 25.0
APowerfun(5.0,-2)=(5.0)-2 = (1/25)=0.04.
Remember the values of n can be postive or negative. Your code should be able to deal with both cases. Remember to limit the value of n to the value 40 maximum.
The Assignment will require you to create 2 files:
1- APower.h which contain the details of creating the Power class and the method Apowerfun() which should calculate the power of any number a raised to the exponent n. Remember that you are writing a recursive function for Apowerfun().
2- APower.cpp which reads in a long number n, and a float number a, and prints the corresponding power result which is a float.
Here are my files:
APower.h:
#ifndef APOWER_H
#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));
}