1.    The purpose of this question is to check that you can write a complete working program in C or C++.

 

A number is considered “big” if it four digits or more, “medium” if it has two or three digits, or “little” if it has only one digit. Write a program that reads a sequence of numbers typed by the user, for each number the program must print a simple report indicating whether it is big, medium, or little, and whether it is odd or even. The program should continue until the user enters a negative number.

 

Example run: (what the user types is underlined)

 

Enter numbers, terminated by a negative...

? 37

37 is a medium odd number.

? 25846

246 is a big even number.

? 7

7 is a little odd number.

? 124

124 is a medium even number.

? –1

 

Write your program so that it would duplicate this sample output as nearly as possible.


2.    The purpose of this question is to check that you can define and properly use functions.

 

Define a function that takes two integers as its parameters, and returns the product of (i.e. multiplies together) all the integers between those two numbers (inclusive).

 

Examples showing how your function should behave:

 

product(1,4) should return     24 because 1´2´3´4=24

product(5,10) should return 151200 because 5´6´7´8´9´10=151200

product(6,6) should return      6 because 6=6

product(7,5) should return    210 because 7´6´5=210

 

Write your function in C or C++, and show the correct way for a program to call your function.

 

Look carefully at all four examples given above; make sure your program will behave as indicated.


3.    The purpose of this question is to check that you can use arrays correctly.

 

Write the part of a program that allows the user to enter a list of up to 10000 positive integers.  The user will indicate the end of the inputs by entering –1. Once the data has all been entered, your program should print out all the numbers that appeared between the largest and smallest of the numbers, in the same order as they were entered. For a clarification, see the example below. You may be assured that there will be no duplicates in the input (i.e. no number will appear more than once).

 

Example run: (what the user types is underlined)

 

Enter a bunch of numbers, terminated by -1.

7

6

10

3

8

9

12

4

21

14

5

–1

Smallest to Largest: 3 8 9 12 4 21

 

Try to write your program so that it could duplicate this sample output as nearly as possible.

 

Explanation of the example: The smallest number that appeared in the input is 3, which was the 4th input (the -1 is not one of the inputs, it is just the end-of-input marker). The largest number that appeared is 21, which was the 9th input. so we just have to print everything from the 4th input to the 9th input: 3, 8, 9, 12, 4, 21. The smallest and largest are themselves included in the output, only because that makes it a little easier to answer.