Question

In: Computer Science

Write a program that asks a user how many classes they are taking this term, the...

Write a program that asks a user how many classes they are taking this term, the name of each class, the credit hours for each class, and their final letter grade for each class, and then calculates their term GPA. Use either a list for each course or a single list-of-lists. The grading system and examples can be found on the TAMU website: http://registrar.tamu.edu/Transcripts-Grades/How-to-Calculate-GPA

Solutions

Expert Solution

I am going to be using python as you have mentioned lists and list of lists.

number_of_classes = int(input("Enter the number of classes you have taken this term : "))

classes = []

print("")

# Loop number_of_classes times to take information about each class.
# Store the classe info in the classes list of list.
for i in range(1,number_of_classes+1):
    
    class_name = input("Enter name of class " + str(i) + " : ")
    class_credits = int(input("Enter credit hours for this class : "))
    class_gpa = input("Enter the letter grade for this class : ")

    class_gpa = class_gpa.upper()

    class_info = [class_name, class_credits, class_gpa]

    classes.append(class_info)
    print("")

# I am going to be using the formula which is given in the website you have provided.

# Intitialize grade points and credit hours to zero
total_grade_points = 0
total_credit_hours = 0

for class_info in classes:
    letter_grade = class_info[2]
    class_credit = class_info[1]

    # Added appropriate amounts to grade points and credit hours as per letter grade.
    if(letter_grade == "A"):
        total_grade_points += 4*class_credit
        total_credit_hours += class_credit
    elif(letter_grade == "B"):
        total_grade_points += 3*class_credit
        total_credit_hours += class_credit
    elif(letter_grade == "C"):
        total_grade_points += 2*class_credit
        total_credit_hours += class_credit
    elif(letter_grade == "D"):
        total_grade_points += 1*class_credit
        total_credit_hours += class_credit
    elif(letter_grade == "F"):
        total_grade_points += 0*class_credit
        total_credit_hours += class_credit
    elif(letter_grade == "U"):
        total_grade_points += 0*class_credit
        total_credit_hours += class_credit

    # Grades such as S are ignored from calculations as defined in the formula.

# Total gpa is grade points/ total credits.
gpa = total_grade_points/total_credit_hours

print(("Your final gpa is : %.2f") % (gpa))
    



The output-

The code has been commented so you can understand the code better.

I would love to resolve any queries in the comments. Please consider dropping an upvote to help out a struggling college kid :)

Happy Coding !!


Related Solutions

Write a program that asks the user for a number of seconds and tells them how...
Write a program that asks the user for a number of seconds and tells them how many hours, minutes and seconds it is. Make sure your program works correctly for values smaller than the whole hour or whole minute. Here’s what the sample output from several runs of your program would look like: Please enter the number of seconds: 2 2 seconds >>> Please enter the number of seconds: 500 8 minutes 20 seconds >>> Please enter the number of...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
Write a c++ program that asks the user to choose his preferred shape, and asks then...
Write a c++ program that asks the user to choose his preferred shape, and asks then for two numbers (positive but not necessary integers) in order to calculate the shape's area. The possible shapes are: Triangle, Ring and Rectangle. If the user chose a different shape, you will warn him and wait for a valid shape. The area of a circle is πr12-r22 (suppose π= 3.4 ). The area of a triangle is base*height/2. The area of a rectangle is...
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT