LAB WORK 4: PRACTICE LOOP, SELECTION, and ARRAY (if any)

Ngunguto, a high school student with a keen interest in programming, found himself inspired during a computer science class project. His teacher challenged the students to create a tool that could help with academic performance tracking. Motivated by this challenge, Ngunguto decided to develop a program that would calculate and display the average scores and corresponding grades for five of his classmates based on their performance in four subjects: Mathematics, Science, English, and History.

To begin, Ngunguto gathered the scores of his classmates, ensuring he had accurate data for each subject. He structured the data in a clear format, creating a list that included the names of the students and their respective scores. This organization was crucial, as it would allow him to efficiently process the information later.

Next, Ngunguto set about writing the program. He started by defining a function that would calculate the average score for each student. To make the program user-friendly, he included comments to explain each part of the code. He implemented a grading scale that would categorize the average scores: an A for scores between 90 and 100, a B for 80 to 89, a C for 70 to 79, a D for 60 to 69, and an F for scores below 60.

After coding the logic, Ngunguto ran several tests with sample data to ensure the program worked correctly. He was thrilled to see that it not only calculated the averages accurately but also determined the correct grades for each student. To enhance the output, he formatted the results to display each student’s name, average score, and corresponding grade neatly.

Encouraged by his success, Ngunguto decided to present his project to the class. During his presentation, he explained the process he followed, the challenges he faced, and how he overcame them. His classmates were impressed with the program’s functionality, and many expressed interests in using it for their own academic tracking.

This project not only solidified Ngunguto’s programming skills but also fostered a sense of collaboration among his peers. They discussed potential improvements, such as adding features for tracking progress over time or incorporating a graphical user interface. Inspired by the feedback, Ngunguto felt motivated to continue enhancing the program, turning it into a valuable tool for academic success. Through this experience, he learned the importance of data management, problem-solving, and the power of technology in education.


Solution Implementation

Write a complete C++ program that solves Ngunguto’s problem.

Explain how loops are used in this C++ program.

How are selection statements implemented in the C++ grading system?

What data structures are used in this C++ solution and why?

Sample Output: