1. Write a program to read an integer number in n and a base (2,8,16 ) in newBase. Convert n from base 10 to newBase . Must use the "STACKPAC.h" library.

Sample run
Enter a number at base 10: 35
Enter a new base(2,8,16): 2
35 base 10 is 100011 base 2
CONTINUE(y/n)? y
Enter a number at base 10: 355
Enter a new base(2,8,16): 8
355 base 10 is 453 base 8
CONTINUE(y/n)? y
Enter a number at base 10: 442
Enter a new base(2,8,16): 16
442 base 10 is 1BA base16
CONTINUE(y/n)? n

2. Use STACKPAC.h to determine whether a given phrase is a palindrome or not.

Sample run
How many phrases would you like to try? 3

Enter a phrase: Eva, can I see bees in a cave
This phrase is a palindrome

Enter a phrase: No Lemon, no Melon
This phrase is a palindrome

Enter a phrase : Have fun
This phrase is not a palindrome

3.Write a recursive function to compute: 32+42+52+ .........+n2 . Test your program for n=8

4. Write a recursive function to return the nth Fibonacci number. Test your program for n=10, and n=45

5. (a) Store 10 random integers <30 in stack NUM, (b) store 10 random uppercase letters in stack ALPHA, (c) store the name of 10 month (choose them randomly) in stack MONTHS. Display the content of all three stacks Sample output

Numbers : 11 7 ......

Uppercase letters: P N R ......

Months: DEC JAN MAR ......

6. Trace the following by hand and show their final output

a. void f( int n)
{ if (n>=1)
{
f( n-1);
f(n-2);
cout <<< n;
}
}

Calling statement: f(4);
b.int g(int n, int m)
{
if( n==m) return 3;
else return n+ f(n+1,m);
}

Calling statement:
cout << g(5, 9);
c.void h( int n)
{
cout< if( n>=1 ) h(n-1);
cout << n;
}

Calling statement: h(4);

7.Given arrays : int a[3][4], b[3][4]; . Write a program to do the following

a.Generate 3*4=12 random integers <20 and store them all in array a
b.Display array a
c.Think of an algorithm to reverse (must use stack) the order of numbers in array a and store them in array b
d.Display array b

Sample output> Suppose the generated random numbers are 1,2,3,…..,12
This is array a
1 2 3
4 5 6
7 8 9
This is array b
9 8 7
6 5 4
3 2 1

STACKPAC

#ifndef STACKPAC
#define STACKPAC

template < class T, int n>
class Stack
{
private:
T Element[n];
int counter;

public:
Stack()
{
counter = 0;
}

void clearStack()
{
counter = 0;
}

bool emptyStack()
{
if (counter == 0) return true;
else return false;
}

bool fullStack()
{
if (counter == n) return true;
else return false;
}

void pushStack(T x)
{
Element[counter] = x;
counter++;
}

T popStack()
{
counter--;
return Element[counter];
}
};

#endif
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.