C++ Prac

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Practical 5

Create a C++ project called Surname_studentNumber_Prak5


A group of 10 students need to present their programming projects for marks.
1. Declare an array of type string called arrNames with the names of 10 students.
Declare another array of type string called arrPresent to keep the names of the
students in the order that they will present their projects.
Declare an array of type integer called arrMarks to keep the marks of the students.

2. Write a function called displayArray() to receive the arrNames array and display a
numbered list of the content of the array.
3. Example of out if the function is called:

4. The order of presenting projects must be generated randomly.


Fill up the arrPresent with the names of students from the arrNames array.
As names are selected from the arrNames array the names must be cleared from the
arrNames array (replaced by “ ”).
Do this as follows:
Use a for loop as the outer loop to refer to each element of the arrPresent
array. Inside the for loop do the following:
Use a do while loop inside the for loop to generate a random value in
the range from 0 to 9 to until the name that is found in the arrNames
array using the random value is not a blank space.

Assign the name in the random index position from the arrNames
array to the arrPresent using the counter of the for loop.
Assign “ “ in the random index position in the arrNames to clear the
name from arrNames.

NOTE: arrNames should be filled with empty strings once the for loop is done. All the
names should then be assigned to arrPresent in random positions in the array.

1
Call the displayArray() function passing the arrPresent array to the function to see
the shuffled list of names.
Example of shuffled list of names in the arrPresent array:

NOTE: The list will be different each time when the code is executed due to random
selection of names.

5. Write code to allow the user to swap names in the arrPresent array.
Use a while loop which asks the user whether a swap needs to be done or not. If Y,
call the displayArray() function to display the numbered list of names from the
arrPresent array.
Ask the user to enter the number of the student on the list who wants to swap.
Ask the user to enter the number of the student on the list who is willing to swap.
Write code to swap the two names.

Call the displayArray() function to show the updated list.

Ask if another swap must be done.


Repeat this process until the user enters n – no more names to be swapped.

How to swap two elements in an array:


Three steps:

Example of input and output to swap two names. The program must be able to swap
more names until the user enters n.

2
6. Write code to allow the user to enter the marks of the students as they present their
projects using a for loop. Use the arrPresent array to display the name and enter the
mark.

Example of input of marks:

NOTE: The arrPresent array and the arrMarks array are parallel arrays because the
elements of the arrays are related.

7. Write a function called displayMarks() that will receive the arrPresent array and the
arrMarks array and display a numbered list of the names and marks of the students.

Call the displayMarks() function from the main function.


8. Write a function called findBestProject() that will receive the arrMarks array. Find
and return the index value of the best mark in the arrMarks array.
Exmple of display of names and marks:

3
Call the findBestProject() function from the main function and display the name of
the student with the best mark and the mark using the index value that was returned
by the function..

Example of output:

4
Rubric Mark
Array Declaration and Initialization (3 Marks)
3 pts: Arrays (arrNames, arrPresent, arrMarks) are correctly declared and
initialized as per instructions. 3
2 pts: Arrays are declared and initialized with minor issues.
1 pts: Arrays are declared but incorrectly initialized.
0 pts: Arrays are not declared or initialized correctly.

DisplayArray() Function (3 Marks)


3 pts: The displayArray() function correctly displays a numbered list of names. 3
2 pts: The function displays the list but with minor issues (e.g., formatting errors).
1 pts: The function displays the list but with significant issues.
0 pts: The function is incorrect or not implemented.

Random Order Generation for Presentation (3 Marks)


3 pts: Names are correctly assigned to arrPresent in a random order with
arrNames cleared as per instructions. 3
2 pts: Random order generation works with minor issues.
1 pts: Random order generation is implemented with major flaws.
0 pts: Random order generation is incorrect or not implemented.

Swapping Names in arrPresent (3 Marks)


3 pts: Code allows correct swapping of names in arrPresent, with the list updated
and displayed properly. 3
2 pts: Swapping is implemented but with minor issues.
1 pts: Swapping is implemented but with major issues.
0 pts: Swapping functionality is incorrect or not implemented.

Entering and Storing Marks (2 Marks)


2 pts: Marks are correctly entered and stored in the arrMarks array corresponding
to the students in arrPresent. 2
1 pts: Marks are stored but with issues related to input or indexing.
0 pts: Marks are not stored correctly or functionality is missing.

displayMarks() Function (2 Marks)


2 pts: The displayMarks() function correctly displays a numbered list of names
with corresponding marks. 2
1 pts: The function is implemented with minor issues.
0 pts: The function is incorrect or not implemented.

FindBestProject() Function (2 Marks)


2 pts: The findBestProject() function correctly identifies and returns the index of
the highest mark. 2
1 pts: The function is implemented with minor issues.
0 pts: The function is incorrect or not implemented.
Overall Program Execution and Output (2 Marks)
2 pts: The program executes correctly without errors and meets all requirements
of the assignment. 2
1 pts: The program executes with minor errors or misses a few requirements.
0 pts: The program fails to execute correctly or misses significant requirements.

No comments - Deduct 5 marks


Hardcoding - Deduct 10 Marks
Subtotal 20
Grand Total 10

You might also like