Starting from:
$35

$29

Programming Assignment 5 Recursion Solution




Write a C++ program that does the following :

1. Accepts array size from the keyboard. Size must be a positive integer that

is = 10 and <= 1000.

2. Use the size from step 1 in order to create an integer array. Populate the

created array with random integer values between 10 and 1000

inclusive

3. Display the first 10 elements of the generated array.

4. Write a function that uses recursion in order to display squares of

integers in ascending order, starting from 1 to last number in the array.

5. Write a function that uses recursion to raise a number to a power. The

function should take two arguments, the number to be raised to the

power is the first number in array and the power is 2.

6. Write a recursive function that returns the maximum elements in the

array

7. Using quick sort , write a function that uses recursion to sort the array in

descending order. Calculate and print the CPU time before each step

starts and after each completed step then calculate actual CPU time for

the completion of each step. Use the last value as a pivot value.

8. Write a recursive function that that takes an integer ( first number in the

sorted arrays ) as a parameter and returns the sum of digits of that

integer.




Write a recursive function that determines whether or not every number

in the sorted array is a prime number.

The program displays a menu on the screen allowing the user to enter the a

choice to enter the size of an array or to terminate the program.

NOTES:









Just one .cpp file with at least 6 individual recursive functions plus main for

testing.

Do not use global variable , arrays ... etc.

Validation on the menu selection and the array size.

Replace My name (Husain Gholoom) with your first and last name.




Style Guidelines:

At the beginning of your program ( and before the #include statement ), include the following :

Header comments (file documentation block) should be at the top of each file and

should contain: Author / s, Due Date, Assignment Number, Course number and

section, Instructor, and a brief description of the purpose of the code in the file. For

example :

//

//

//

//

//

//

//

//

//

//

//

Roster Number / s :

xxxxxxxxx

Author / s : (Your name here!!)

Due Date :

Programming Assignment Number 5

Spring 2018 - CS 3358 - Your Section Number

Instructor: Husain Gholoom.

<Brief description of the purpose of the program

Variable names :







Must be meaningful.

The initial letter should be lowercase, following words should be capitalized, no other

caps or punctuation ( i.e. weightInPounds

).

Each variable must be declared on a separate line with a descriptive comment.

Named constants :







Use for most numeric literals.

All capitals with underscores ( i.e. TX_STATE_SALES_TAX

Should occur at top of function, or global (only if necessary)

)

Line length of source code should be no longer than 80 characters (no wrapping of

lines).

Indentation :







Use 2-4 spaces (but be consistent throughout your program).

Indent blocks, within blocks, etc.

Use blank lines to separate sections.




Comments for variables :

All variable definitions should be commented as follows:

int

gender;

// integer value for the gender,

// 1 = Male , 2 = Female ,

Rules :

1. Your program must compile and run. The program will be tested using the latest

version of Codeblocks for windows.

2. Your program must be properly documented according the style above . See the

website for the sample programming style program.

3. Must properly format the output by use the appropriate library. See the output below

. Also , Replace my first / last name with your own first / last name.

4. You must name your program as :

You must name your program as :

o PG5_3358_0_LastName_FirstName.cpp ( Section 0 )

o PG5_3358_1_LastName_FirstName.cpp ( Section 1 )

o PG5_3358_2_LastName_FirstName.cpp ( Section 2 )

Where LastName is your Last Name and FirstName is your First Name. For example ,

the file name should look something like : PG5_3358_0_Gholoom_Husain.cpp ( not

.cbp )

5. Every one must upload the electronic version of the program no later than the starting of class

time on the due date. No late assignments will be accepted. DO NOT send your assignment

solution via email. Group members must upload identical copy of the assignment.

Use TRACS To upload electronic version of your program

6. You must also turn in hard copy of your source code no later than the starting of class time on

the due date . should the hard copy consist of more than one page , then , the hard copy must

be stapled. if you are unable to turn in a printout during class, you can take the program to the

computer science department and hand it to the front desk personal (Comal 211 ) before the

deadline. Make sure that the front office stamps the program. Make sure that include the date

and time. Finally ,make sure that they place the program in my mailbox. Only one copy per

group.

DO NOT slide your program under my office door – It will NOT be accepted




The following points will be deducted if :

• Compilation errors , Incorrect file format such as uploading .cbp instead of

.cpp , missing electronic copy , missing the hardcopy , different copies of the

assignment per group , not using 6 or more different recursion functions , not

using the indicated sort algorithm, more than one file such as using .h , .cpp

file

( - 10 points )

• Each logical error : ( - 1.25 points )

• Other : ( 1.5 points )











if any of the following takes a place :

Unable to read the source code due to unclear printing

Incorrect Output format.

Incorrect program file name.

Hard copy is not stapled.

Incorrect Style such as but not limited to Missing Header , footer ,

comments or program documentations , missing roster number ,

missing section number ... etc

Sample Output

Thinking Recursively

The function of this program is to

use recursion in order to perform the following operations

1.

2.

3.

4.

5.

6.

:-

Display squares of integers in ascending order from 1 to the

last element in the array

Raise the first number to a power 2

Find the array's max value.

Sort the array in descending order

Calculating sum of digits

Determine if a number is prime (processes all array values)




Select from the following menu

A.

Enter Array Size that is 4.

X.

Terminate The Program.

B

***

Invalid Option

***

Select from the following menu

A.

Enter Array Size that is 4.

X.

Terminate The Program.

3

***

Invalid Option

***

Select from the following menu

A.

Enter Array Size that is 4.

X.

Terminate The Program.

A

Enter Array Size: P

*** Invalid Array Size Value ***

Enter an integer not a char: 3

***

***

Invalid Array Size Value ***

Enter Array Size That is = 10 and <=

1000 : 9

The generated array is:

433

411

430

370

295

20

143

461

441

64

Table of square values 1 - 64

N

1

2

3

4

5

6

7

8

9

10

11

12

13

14

N Squared

1

4

9

16

25

36

49

64

81

100

121

144

169

196

More products