Repetition Statements In this homework, you will design a program to perform the
ID: 3568521 • Letter: R
Question
Repetition Statements
In this homework, you will design a program to perform the following task:
Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered. You also do not know how many courses each of the students completed. Design your program to calculate the Grade Point Average (GPA) for each student based on each of their final grades. The program should output the Student name along with the GPA.
There are 5 components of your submission including:
Explanation / Answer
You are not specific with the question, how do you want to assign gpa to the grade, means which formula. I can give you the basic structure, you should use 2 loops to solve your biggest problem, which is you don't know how many students or subjects are there I can give you a rough psuedocode.
ask how many student are there first
store that value in a variable x
make a loop so the loop executes x times.
in the loop 1
first get student's name, and store it as a character string
then ask how many subjects he is taking save that in a variable y
run the following loop y times
in loop 2 ask the grade store it in another variable.
you will get y number of grades for each student and then count the gpa in the loop itself.
then count his gpa and store it in another variable.
at last print the name and gpa.
basically two loops one inside another
the bigger loop runs x number of times if there are x students
for each student there is loop two which runs y number of times if he has taken y number of classes
store all the values you get from the user and display whichever value you want to
my first programming language is C++ not c I don't know c very well, but my response should make sense to you
Psuedo code
list of variables used in this program.
1 int studentnumber
2 int loop1counter
3 character string for name
4 int number of subjects
5 int subject loop counter
6 char grade in letter
7 int grade in number
8 float total grade(accumulator) = 0.0
9 int gpa
print-- please enter the number of students
get& store value in variable 1
{
create a for loop variable 2 = 0; variable 2 <= variable 1; variable 2++
print-- enter your name
get -- variable 3
print-- how many classes do u wish to count for gpa
get-- variable 4
{
create another for loop variable 5 = 0; variable 5 <= variable4 ; variable 5++
print-- enter your grade please
get-- variable 6
switch- case statement
case A: var 7=4
case B: var 7=3
...............
so on
then
veriable 8 = variable 8 + variable 7
}
variable9(gpa)= variable 8 / variable4
print-- hey "variable3" your GPA is "variable9"
}
end of the program......
For your teachers question number two, you need to write that it is a for loop, means a counter loop so it will execute as many times the user wants so no sentinels needed for this code.