CIS

rick07

1.         Chapter 2 – Exercises, pages 81-82: 7.

 

#7)

"The mystery numbers are defined recursively as

myst (0) = 2

myst (1) = 1

myst (n) = 2 * myst (n – 1) + myst (n – 2)      for n > 1

(a) Draw the calling sequence for myst (4).       (b) What is the value of myst (4)?"

 

 

 

2.         Chapter 2 – Problems, pages 82-85: 10; 12; 16; 18.

 

 

#10)

Write a C++ program that inputs an integer and outputs whether the integer is even.

Sample Input                                Sample Output

       15                                                 15 is not even

 

 

 

 

 

 

#12)

Write a C++ function

int rectArea (int len, int wid)

that returns the area of a rectangle with length len and width wid. Test it with a main program that inputs the length and width of a rectangle and outputs its area. Output the value in the main program, not in the function.

Sample Input

6 10

Sample Output

The area of a 6 by 10 rectangle is 60.

 

 

 

 

#16)

Write a recursive void function called rotateLeft that rotates the first n integers in an array to the left. To rotate n items left, rotate the first n – 1 items left recursively, and then exchange the last two items. For example, to rotate the five items

50 60 70 80 90

to the left, recursively rotate the first four items to the left:

60 70 80 50 90

and then exchange the last two items:

60 70 80 90 50

Test it with a main program that takes as input an integer count followed by the values to rotate. Output the original values and the rotated values. Do not use a loop in rotateLeft. Output the value in the main program, not in the procedure.

Sample Input

5 5060708090

Sample Output

Original list: 50 60 70 80 90 Rotated list: 60 70 80 90 50

 

 

 

 

#18)

The program in Figure 2.40 creates a linked list whose elements are in reverse order compared to their input order. Modify the first loop of the program to create the list in the same order as the input order. Do not modify the second loop.

Sample Input

10 20 30 40 -9999

Sample Output

10 20 30 40

 

 

  • 10 years ago
  • 8
Answer(0)
Bids(0)