programming exercises

Programming Exercises: Arrays and Methods

These are some programming exercises that can test your brain. These programming exercises are generic and simple that could be done using any programming language you like. These involves problems that Arrays and Methods should be applied.

  1. Write a program that prompts a professor to input grades for five different courses for 10 students. Prompt the professor to enter one grade at a time using prompt “Enter grades for student #1: “. Verify that the professor enters only A,B,C,D or F for grades (A is the highest grade, F fail). Use variables for student numbers (1 through 10) and grade numbers (1 through 5). Create a menu for Search. If the user select search it will prompt for a letter corresponding to grade. Display all students with the selected grade. If the user just enter, display all students with their grade sorted highest to lowest.
  2. Write a program that displays a multiple choice quiz of 10 questions with topics related to your course. Each question has one correct answer and three possible answers. Verify that the users enters only A, B, or C as the answer. Store correct answers in an array. Store the user’s answers in a second array. If the user responds to a question correctly, display “Correct!”; otherwise display “The correct answer is” and the letter of the correct answers. After showing the answer, prompt the user if he want to take the exam again.
  3. Write a program that lets the user enter numbers (1 through 9) one at a time, and then prints the numbers the user entered. Allow the user to enter up to 10 numbers. If the user tries to enter a 11th number, display a message that no more numbers can be entered. Allows the user to delete a number, which is the user will be prompt to specify which number to remove. Verify that the user enters a valid number (1 through 9) and then change that removed number in array to 0. Include a menu that shows the options to enter, remove and display a number or quit program.
  4. Write program for student record. Add menu for [1] Add, [2] Modify, [3] Display and [4] Quit program. When the user select 1, it will allow the user to enter new student with ID number and last name, it should not accept more than 10 students. After adding a new student, the program will go back to the menu. If user choose modify the program will prompt to specify what student ID to modify, otherwise display student not found, then return to menu. If student ID found, ask for new ID and Last name. If the user doesn’t enter anything no changes will be made and will bring you back to the menu. Display will just display all students with their corresponding ID and Last names.
  5. Create a program that stores 10 products and their corresponding prices in an array, such as 2.34, 7.89, 1.34, and so on. Display the sum of all the prices. Display all products which values less than 5.00. Calculate the average of the prices, and display all values higher than the calculated average value. You must create separate methods for all the computations. Include a menu that will prompt user to Sort the products by price or alphabetically. Display all products with their prices according to what type of sorting the user choose.


Sharing is caring!