Assignment 05
Home ] Up ]

 

CSIS 250 2002 Spring

Assignment 05

Date Assigned: 04/10/2002

Date Due: 04/19/2002

 

Add the following two functions to the pizza04.cpp:

 

reverse1(int a[], int low, int high)

A repetitive (non-recursive) function to reverse the elements of an array a.

reverse2(int a[], int low, int high)

A pureley recursive function to reverse the elements of an array a.

 

For each function, include detailed documentation and properly indented source code.

Submit the following:

§         Printed source code of the working program (to get any credit the function has to work)

§         Printed output

§         Self-evaluation table

 

Your Name:

 

Self-evaluation Table for CSIS 250 Project 05

 

 

Max Score

Score

Reverse1

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Local variables used

1

 

Source code

1

 

Properly indented source code

5

 

Output from 10 iterations

10

 

Reverse2

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Local variables used

1

 

Source code

1

 

Properly indented source code

5

 

Output from 10 iterations

10

 

Total Score

50

 

 

The main driver should be as follows:

 

void main(void)

  {

  srand(time(NULL));

  int a[MAX_COUNT], low, high;

 

  for (int i=1; i<=10; i++)

    {

    buildArray(a, low, high);

    cout << "Original array:\n";

    displayArray1(a, low, high);

    reverse1(a, low, high);

    cout << "After reverse1(a, low, high):\n";

    displayArray1(a, low, high);

    cout << "=================================\n";

    }

 

  for (i=1; i<=10; i++)

    {

    buildArray(a, low, high);

    cout << "Original array:\n";

    displayArray1(a, low, high);

    reverse2(a, low, high);

    cout << "After reverse2(a, low, high):\n";

    displayArray1(a, low, high);

    cout << "=================================\n";

    }

  }

 

The output from the program should be similar to the following:

Original array:

79 55 76 31

After reverse1(a, low, high):

31 76 55 79

=================================

Original array:

63 92 71 91 31 61 18 15 94

After reverse1(a, low, high):

94 15 18 61 31 91 71 92 63

=================================

Original array:

45 84

After reverse1(a, low, high):

84 45

=================================

Original array:

56 27 69 14 76

After reverse1(a, low, high):

76 14 69 27 56

=================================

Original array:

52 78 71 25 63 64

After reverse1(a, low, high):

64 63 25 71 78 52

=================================

Original array:

14 71 11 53 52

After reverse1(a, low, high):

52 53 11 71 14

=================================

Original array:

79 95 45 13 45 87

After reverse1(a, low, high):

87 45 13 45 95 79

=================================

Original array:

69 61 91 44 40 71 19

After reverse1(a, low, high):

19 71 40 44 91 61 69

=================================

Original array:

55 19 12 94 82 82 65 47

After reverse1(a, low, high):

47 65 82 82 94 12 19 55

=================================

Original array:

93 79 95 72 59 63 26

After reverse1(a, low, high):

26 63 59 72 95 79 93

=================================

Original array:

30 65 59 34 89 49 29 68 46 16

After reverse2(a, low, high):

16 46 68 29 49 89 34 59 65 30

=================================

Original array:

27

After reverse2(a, low, high):

27

=================================

Original array:

94 69 76 82 61

After reverse2(a, low, high):

61 82 76 69 94

=================================

Original array:

22 37 92 55

After reverse2(a, low, high):

55 92 37 22

=================================

Original array:

80 82 26 73 85 91 85 57 35

After reverse2(a, low, high):

35 57 85 91 85 73 26 82 80

=================================

Original array:

87 95 96 61 23

After reverse2(a, low, high):

23 61 96 95 87

=================================

Original array:

58 11

After reverse2(a, low, high):

11 58

=================================

Original array:

85

After reverse2(a, low, high):

85

=================================

Original array:

22 48 35 32 41

After reverse2(a, low, high):

41 32 35 48 22

=================================

Original array:

12 45 21 66

After reverse2(a, low, high):

66 21 45 12

=================================