oduction to LuNa and the List Collection st of strings a) Add a new Project (vis
ID: 3798548 • Letter: O
Question
oduction to LuNa and the List Collection st of strings a) Add a new Project (visual ca/Windows Console Application called MyGrade02 to the Solution by right clicking the solution name and, in the pop-up windows, select Add/New Project b) See figure in Part 1 and your Solution Explorer should list two project now. Use a function (i.e. method) called "score2grade" that accepts the integral score as the only parameter and return the letter grade according to the table as specified in Parti. Make "My Grade 02" as the startup project by right clicking "MyGradeo2" and in the pop-up windows select "Set as Startup Project". Below is the sample run: a CAWindowsisystem32Mcmd. lease ente score: 80 Grade C lease enter score: 75 rade C Please enter score: 92 Grade: A the listExplanation / Answer
// C# code
using System.IO;
using System;
class MyGrade2
{
static void Main(String[] args)
{
while(true)
{
Console.WriteLine("Please enter score: ");
string str = Console.ReadLine();
double score = double.Parse(str);
if(score < 0)
break;
else
{
char grade = score2grade(score);
Console.WriteLine("Grade: {0}", grade);
}
}
}
private static char score2grade(double score)
{
if (score > 90) return 'A';
else if (score > 80) return 'B';
else if (score > 70) return 'C';
else if (score > 60) return 'D';
else return 'F';
}
}
/*
output:
Please enter score:
80
Grade: C
Please enter score:
75
Grade: C
Please enter score:
92
Grade: A
Please enter score:
-1
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.