You are on page 1of 2

Array and Structures Exercises

1. Write a program that asks the user to type 10 integers of an array. The program must compute
and write how many integers are greater than or equal to 10.
2. Suppose you want to keep track of your books in a library. You might want to track the following
attributes about each book: title, author, subject and book Id. Create a structure to hold two
books information and print books information.
3. Write a program which takes 2 arrays of 4 integers each, a and b. C is an array with 8 integers.
The program should put into c the appending of b to a, the first 4 integers of c from array a, the
latter 4 from b. Then the program should display c.

Function Exercises

4. Write a C++ program that will display the calculator menu. The program will prompt the user to
choose the operation choice (from 1 to 5). Then it asks the user to input two integer vales for the
calculation. See the sample below.
MENU
1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus
Enter your choice: 1
Enter your two numbers: 12 15
Result: 27
Continue? Y
The program also asks the user to decide whether he/she wants to continue the operation. If
he/she input ‘y’, the program will prompt the user to choose the operation gain. Otherwise, the
program will terminate.
5. Write a program that will ask the user to input three integer values from the keyboard. Then it
will print the smallest and largest of those numbers
6. Write a C++ program to pass an array containing age of person to a function. This function
should find average age and display the average age in main function.
7. Write a program that asks for an index and a number. Then it includes the number at the
indicated index of the array ={1,2,3,4,5,6} and moves a position forward (from u to u+1) each
element after the selected index.

Pointer Exercise

8. Write block of code that take an input from the user and display the same value using pointer.
9. Write a program that asks the user to enter integers as inputs to be stored in the variables 'a'
and 'b' respectively. There are also two integer pointers named ptrA and ptrB. Assign the values
of 'a' and 'b' to ptrA and ptrB respectively, and display them.
10. Write a C++ program to accept five integer values from keyword and print the elements of the
array in reverse order using a pointer.
11. Write a function countEven(int*, int) which receives an integer array and its size, and returns the
number of even numbers in the array.
12. Write two functions void cubeByPtr1 ( int * numPtr ) and void cubeByPtr2 ( int & numPtr ) which
returns a cube of a number.
13. Given the string "A string." Print on one line the letter on the index 0, the pointer position and
the letter t. undate the pointer to pointer +2. Then, in another line print the pointer and the
letters r and g of the string (using the pointer).

You might also like