Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got answers already. Can anyone help me to get a test file for the below codes, it will be a separate file so that

I got answers already. Can anyone help me to get a test file for the below codes, it will be a separate file so that i can test below codes successfully. Also it is an assignment of data structure on recursive function "You will implement and test four short recursive functions. With the proper use of recursion, none of these function should require more than a dozen lines of code. rec_fun.cxx: This file should contain the implementations of the four functions described below. You might also want to put the functions prototypes in a separate file rec_fun.h and write a test program that includes rec_fun.h."

ansewr:

#include
#include "rec_fun.h"
int main(){
std::ostream a(std::cout.rdbuf());
unsigned int b;
unsigned int c;
std::cin >> b;
std::cin >> c;
//recursion::binary_print(a,b);
//std::cout << " ";
//recursion::triangle(a, b, c);
std::cout << " ";
std::cout<
std::cout << " ";
//recursion::indented_sentences(b, c);
return 0;

}

void recursion::binary_print(std::ostream& outs, unsigned int n)

{

if (n <= 1)
{
outs << n;
return;
}
binary_print(outs,n >> 1);
outs << n%2;
return;
}
void recursion::triangle(std::ostream& outs, unsigned int m, unsigned int n){
if (m > n)
{
return;
}
outs.width(m);
outs.fill('*');
outs << "" << std::endl;
triangle(outs, m + 1, n);
outs.width(m);
outs.fill('*');
outs << "" << std::endl;
return;
}
double recursion::pow(double x, int n){
double p;
if (x == 0)
{
assert(n > 0);
return 0;
}
if (n == 0)
return 1;
if (n < 0)
return 1 / pow(x, -n);
if (~n&1)
{
p = pow(x, n >> 1);
return p*p;
}
return x*pow(x, n - 1);
}
void recursion::indented_sentences(size_t m, size_t n){//m == number of spaces; m=0==no spaces;m=1==1 space; etc. Function definition does not preclude 0
if (m > n)
{
return;
}
std::cout.width(35+m);
std::cout.fill(' ');
std::cout << "This was written by calling number ";
std::cout << m <<"."<< std::endl;
indented_sentences( m + 1, n);
std::cout.width(40+m);
std::cout.fill(' ');
std::cout << "This was ALSO written by calling number ";
std::cout << m << "." << std::endl;
return;

}

#include
#include
#include
class recursion{
public:
static void binary_print(std::ostream& outs, unsigned int n);
static void triangle(std::ostream& outs, unsigned int m, unsigned int n);
static double pow(double x, int n);
static void indented_sentences(size_t m, size_t n);
};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions