Question

In: Computer Science

write C++ program using functions (separate function for each bottom) Write a program to find if...

write C++ program using functions

(separate function for each bottom)

Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. .

the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is palindrom or not
Sample Input:

A number is called a word if it's represented in its bottom. e.g. Let  bottom1 = 6 and bottom2 = 2 as it is not a word in base 5(1010)(as the reciprocal of the number isnt a palindrome).
bottom is base of a number
take bases as input from user
bases can go from decimal-hexadecimal.

for bottom1 = 3 & bottom2 = 4, then the number 130 (in base 10) will be called a large_word, as it is word in bottom 3 (11211) as well as in bottom 4 (2002). However, it is not a large_word for bottom1 = 3 and bottom2 = 5 as it is not a word in bottom 5(1010).

Number: 51

bottom(base) 1: 6

bottom(base) 2: 2

Sample Output:
51 is not large word

hint:
bottom is basically base of a number

A large _word is a word, phrase, number, or other sequence of characters which reads the same reverse or straightward.

word==palindrome

use function in the program at all time

Solutions

Expert Solution

Code-

#include <stdio.h>

#include <iostream>

#include <string.h>

using namespace std;

char val(int n)// to return the charcter of the number accordingly

{

if(n>=0 && n<=9)

return (char)(n+'0'); // returns the normal charcter from 0-9

else

return (char)(n-10+'A');// returns char from A-F accordingly

}

string reverse(string s)// to reverse the string

{

string rev="";

for(int i=s.length()-1; i>=0; i--)

rev+=s[i];

return rev;

}

int base1(int b1,int num)// to convert to base 1

{

string s1;

while(num>0)

{

s1+=val(num%b1);

num=num/b1;

}

if(s1==reverse(s1))// compare reverse with original

return 1;

else

return 0;

}

int base2(int b2,int num)// to convert to base 2

{

string s2;

while(num>0)

{

s2+=val(num%b2);

num=num/b2;

}

if(s2==reverse(s2))//compare reverse with original

return 1;

else

return 0;

}

int main()

{

cout<<"Number: ";

int num,b1,b2;

cin>>num;

cout<<"bottom base 1: ";

cin>>b1;

cout<<"bottom base 2: ";

cin>>b2;

if(base1(b1,num)==1 && base2(b2,num)==1)// checking for large word

cout<<num<<" is a large word";

else

cout<<num<<" is not a large word";

return 0;

}

Indentation-

Output-


Related Solutions

C++ program to perform each of the area calculations in separate functions. Your program will take...
C++ program to perform each of the area calculations in separate functions. Your program will take in the relevant information in the main (), call the correct function that makes the calculation, return the answer to the main () and then print the answer to the screen. The program will declare a variable called “choice” of type int that is initialized to 0. The program will loop while choice is not equal to 4. In the body of the loop...
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
java In one program, write 3 separate functions, and use them. 1) Write the function body...
java In one program, write 3 separate functions, and use them. 1) Write the function body for each: int squareInteger s( int x) double squareDouble( double d) float squareFloat ( float f) They basically do the same thing, square a number, but use different argument datatypes. 2) Test Each function with: Using int 4, double 4.9, float 9.4 What happened when you use the correct numerical data type as input ? What happened when you use the incorrect numerical data...
Please write program in c++ with using pointer. create a function that can find the number...
Please write program in c++ with using pointer. create a function that can find the number of even numbers that are between the maximum and minimum elements of an given array.The program have to use pointer. example 8 -1 2 2 1 9 2 4 0 output: 2
Write a C++ program which consists of several functions besides the main() function. The main() function,...
Write a C++ program which consists of several functions besides the main() function. The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. A value-returning function called Power(int a, int b) that...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Write a C++ program using separate void which asks the user to input side of a...
Write a C++ program using separate void which asks the user to input side of a square, radius of a circle , height and base of a triangle and finds the area of squares, circles and triangles. Then using main function display the area of square, circle and triangle
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT