Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application in c# that enables a user to input the grade and number of

ID: 3918917 • Letter: W

Question

Write an application in c# that enables a user to input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a B receives 3 points, a C receives 2 points, and a D receives 1 point. Thus, a three–credit hour course receiving an A would have 12 quality points associated with the course. Allow the user to input any number of courses and associated grades. Display the number of hours earned and the calculated GPA.

CAN YOU DO IN METHOD in C#

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Globalization;

namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
Dictionary<string, int> grade = new Dictionary<string, int>();
Dictionary<string, double> dict = new Dictionary<string, double>();
dict.Add("A", 4);
dict.Add("A-", 3.75);
dict.Add("B+", 3.25);
dict.Add("B", 3.00);
dict.Add("B-", 2.75);
dict.Add("C+", 2.25);
dict.Add("C", 2);
dict.Add("C-", 1.75);
dict.Add("D+", 1.25);
dict.Add("D", 1);
dict.Add("D-", .75);
dict.Add("F", 0);
string choice = "y";   
do{
//Your code goes here
Console.WriteLine("Enter Grade:"); // Prompt
string line = Console.ReadLine(); // Get string from user
Console.WriteLine("You typed "+line); // Report output
bool isValid = false;
foreach (KeyValuePair<string, double> pair in dict)
{
if(pair.Key.ToString().Equals(line)){
break;
}
}
if(isValid){
return;
}
Console.WriteLine("Enter Attempeted Hours:"); // Prompt
String value = Console.ReadLine(); // Get string from user
int attemptedHours;
  
if (Int32.TryParse(value,NumberStyles.Any,
CultureInfo.InvariantCulture,out attemptedHours)){
Console.WriteLine(" You entered hours "+attemptedHours);
}else{
Console.WriteLine("{0} is outside the range of a Double.",
value);
return;
}
grade.Add(line,attemptedHours);
Console.WriteLine("Do you want to continue ? Press 'Y' otherwise for exit press 'N' ");
choice = Console.ReadLine();
}while(choice == "y" || choice == "Y");
double total = 0;
double points = 0;
int totalHours = 0;
foreach (KeyValuePair<string, int> pair in grade)
{
totalHours = totalHours + pair.Value;
double value = dict[pair.Key];
total = total + value * pair.Value;
  
}
Console.WriteLine(total);
double result = Convert.ToDouble(total/Convert.ToDouble(totalHours));
Console.WriteLine("Number of Hours Attempted " + totalHours);
Console.WriteLine("GPA : "+ result);
}
}
}

Output

-----------

Description :

-----------------

1. You can check in the above answer , we have predefined grade scale which limit ( 0 to 4 )

2. in sample output two course data entered

A, 3  

B+, 2

which means A grade is equal to 4 points mean s 4 * 3 = 12

and B+ = 3.25 means 3.25 * 2 = 6.50  

so total points = 18.5 and

spo GPA = 18.5 / 5 = 3.7  

= so grade would be A-  

Let me know if you need to understand anything else on above solution. i will be further explainging you. Tha nks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote