Docsity

2025 computer programming, Assignments of Computer Programming

Toggle sidebar
bg1
CMPG 121 Structured Programming 1 of 4
2025
Assignment: Practical 4
Week 4 - Arrays
General requirements
I. Add your name, surname, and student number as a comment line at the top of each of your programs.
II. Use sensible comments to explain your program logic where necessary.
III. Save your C++ project, and upload only the main.cpp to CodeGrade
Instructions
You are required to develop a menu-driven program for managing a classroom quiz tournament. The program must allow the
user to input student names and scores, manipulate the list, identify top scores, and award bonus points. The program must
use arrays to store both names and scores and run inside a loop until the user chooses to exit.
You must implement the following functionalities:
Prompt the user to enter the number of students participating in the tournament. This number must be between 1 and 100
(inclusive). Validate the input: if the number entered is outside the allowed range, display an error message and prompt again
until a valid number is entered. Store the student names in a string array and their scores in an int array. Prompt for each
student's name and their score (integer).
If the number is invalid:
After all the names and scores have been entered, randomize the order of students and their corresponding scores using the
rand() function. Ensure that names and scores remain correctly paired after shuffling.
Example (order before shuffle): Example (order after shuffle):
Display a menu in the following format every time the user return to the main menu:
====== Menu ======
1. Display Students and Scores
2. Find Top Scorer
3. Swap Student Positions
4. Award Bonus Points to Specific Student
5. Exit
How many students do you want to input (max 100)? 3
Student 1 name: Alice
Score for Alice: 85
Student 2 name: Bob
Score for Bob: 90
Student 3 name: Carol
Score for Carol: 78
How many students do you want to input (max 100)? 150
Invalid number! Enter between 1 and 100: 3
1. Alice - 85 points
2. Bob - 90 points
3. Carol - 78 points
1. Bob - 90 points
2. Carol - 78 points
3. Alice - 85 points
pf3
pf4

Partial preview of the text

Download 2025 computer programming and more Assignments Computer Programming in PDF only on Docsity!

Assignment: Practical 4

Week 4 - Arrays

General requirements

I. Add your name, surname, and student number as a comment line at the top of each of your programs. II. Use sensible comments to explain your program logic where necessary. III. Save your C++ project, and upload only the main.cpp to CodeGrade

Instructions

You are required to develop a menu-driven program for managing a classroom quiz tournament. The program must allow the user to input student names and scores, manipulate the list, identify top scores, and award bonus points. The program must use arrays to store both names and scores and run inside a loop until the user chooses to exit. You must implement the following functionalities: Prompt the user to enter the number of students participating in the tournament. This number must be between 1 and 100 (inclusive). Validate the input: if the number entered is outside the allowed range, display an error message and prompt again until a valid number is entered. Store the student names in a string array and their scores in an int array. Prompt for each student's name and their score (integer). If the number is invalid: After all the names and scores have been entered, randomize the order of students and their corresponding scores using the rand() function. Ensure that names and scores remain correctly paired after shuffling. Example (order before shuffle): Example (order after shuffle): Display a menu in the following format every time the user return to the main menu: ====== Menu ======

  1. Display Students and Scores
  2. Find Top Scorer
  3. Swap Student Positions
  4. Award Bonus Points to Specific Student
  5. Exit How many students do you want to input (max 100)? 3 Student 1 name: Alice Score for Alice: 85 Student 2 name: Bob Score for Bob: 90 Student 3 name: Carol Score for Carol: 78 How many students do you want to input (max 100)? 150 Invalid number! Enter between 1 and 100: 3

1. Alice - 85 points

2. Bob - 90 points

3. Carol - 78 points

1. Bob - 90 points

2. Carol - 78 points

3. Alice - 85 points

Use a do-while loop to repeatedly display this menu until the user chooses to exit by selecting option 5. Menu Option Functionalities: Option 1 - Display all students and their scores in a numbered list. Use formatted output with setw() to align names and scores as follows: Option 2 - Determine the highest score in the list. If only one student has this score, display their name and score. If there is a tie (multiple students have the highest score), list all tied students. From the tied students, randomly select one for a bonus question. Ask the user if the selected student answered correctly (y or n). If yes, award 10 points to their score. Example (Single Top Scorer): Example (Tie and Bonus Awarded): Option 3 - Display the current list with position numbers. Prompt the user to select two positions to swap (value between 1 and size). Swap both names and scores for the selected students. Display the updated list after swapping. Validate the position entered and display an error if out of range. Option 4 - Prompt the user for the name of the student to receive a bonus. Search for the student in the array (case-sensitive exact match). If found, prompt for the number of bonus points to add and update their score. If not found, display an error message: "Student not found. Please make sure you typed the correct name." Student List with Scores:

  1. Bob - 90 points
  2. Carol - 78 points
  3. Alice - 85 points Top scorer is Bob with 90 points. There is a tie! 2 students have 90 points:
  • Bob
  • Alice Randomly selected student for a bonus question: Alice Did Alice answer correctly? (y/n): y Correct! 10 points awarded. New score for Alice: 100 points. Current Student List:
  1. Bob - 90 points
  2. Carol - 78 points
  3. Alice - 85 points You can swap two students' positions. Please enter the number of the FIRST student to swap (1 to 3): 1 Please enter the number of the SECOND student to swap (1 to 3): 3 Swap successful! Updated Student List:
  4. Alice - 85 points
  5. Carol - 78 points
  6. Bob - 90 points

Grading Criteria

Item Description Mark

Allocation

1. Code Quality

Static analysis with clang-tidy (readability and good programming

practices)

2. Input and

Output Tests

Program compiles and runs. Auto-tests provides input and program's

output is matched with expected output. Program responds correctly to

prompts. Note, syntax errors will result in zero marks for this item and

possibly others.

3. Library

imports and

declarations

3a. Import header for random number generation

3b. Import header for output manipulators.

3c. Max size constant

3d. Random Seeding

4. Main menu

control structure

4. If/Else Menu Implementation Inside Do–While Loop /

5. Student input

handling and

validation

5a. Looped Input for Student Names and Scores (For)

5b. Range-Checking Input Validation Loop (While)

6. Scoring and

Ranking Logic

6. Iterative Top Scorer Calculation (For) /

7. Data Swapping

Logic

7. Position-Based Student Swap Implementation /

8. Bonus Points

Award Logic

8. Search by Name and Apply Bonus to Matching Student (For & if) /

TOTAL /