Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to do the testing for the following methods. Make sure you also have a method to handle input validation (positive integer, n

Write a program to do the testing for the following methods. Make sure you also have a method to handle input validation (positive integer, n > 0).

1. A method to find the sum of digits in any integer (iterative method)

2. A method to find the sum of digits in any integer (recursive method)

3. A method to display a number in binary (iterative method)

4. A method to display a number in binary (recursive method)

5. A method to return the string representation of a number in any base (iterative method)

6. A method to return the string representation of a number in any base (recursive method)

SAMPLE OUTPUT:

Enter a positive integer: weqrwer

WRONG TYPE! Not a positive integer! REENTER: 123.45

WRONG TYPE! Not a positive integer! REENTER: -12345

INVALID! Should be positive! REENTER: 1024

Enter a positive integer for base: 2

Sum of digits for 1024 is 7 (iterative solution)

Sum of digits for 1024 is 7 (recursive solution)

1024 in binary code is 10000000000(iterative solution)

1024 in binary code is 10000000000(recursive solution)

1024 in base 2 is 10000000000 (iterative solution)

1024 in base 2 is 10000000000 (recursive solution)

Do you want to continue (y/Y): y

Enter a positive integer: 256

Enter a positive integer for base: 4

Sum of digits for 256 is 13 (iterative solution)

Sum of digits for 256 is 13 (recursive solution)

256 in binary code is 100000000(iterative solution)

256 in binary code is 100000000(recursive solution)

256 in base 4 is 10000 (iterative solution)

256 in base 4 is 10000 (recursive solution)

Do you want to continue (y/Y): y

Enter a positive integer: 123456789

Enter a positive integer for base: 1234

Sum of digits for 123456789 is 45 (iterative solution)

Sum of digits for 123456789 is 45 (recursive solution)

123456789 in binary code is 111010110111100110100010101(iterative solution)

123456789 in binary code is 111010110111100110100010101(recursive solution)

123456789 in base 1234 is 819225 (iterative solution)

123456789 in base 1234 is 819225 (recursive solution)

Do you want to continue (y/Y): y

Enter a positive integer: 257

Enter a positive integer for base: 4

Sum of digits for 257 is 14 (iterative solution)

Sum of digits for 257 is 14 (recursive solution)

257 in binary code is 100000001(iterative solution)

257 in binary code is 100000001(recursive solution)

257 in base 4 is 10001 (iterative solution)

257 in base 4 is 10001 (recursive solution)

Do you want to continue (y/Y): n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions