Book: Microsoft Visual C# 2012 - an introduction to object-oriented programming
ID: 674978 • Letter: B
Question
Book: Microsoft Visual C# 2012 - an introduction to object-oriented programming
Chapter 7, question 7
In chapter 4, you wrote a program named Admission for a college admissions office in which the user enters a numeric high school grade point average and an admission test score. The program displays "Accept" or "Reject" based on those values. Now, create a modified Program named AdmissionModularized in which the grade point average and test score are passed to a method that returns a string containing "Accept" or "Reject." IN C# LANGUAGE.
(Program from chapter 4 instructions: write a console-based program named Admission for a college admissions office. The user enters a numeric high school grade point average and an admission test score. Display the message "Accept" if a grade point average is 3.0 or higher and an admission score of at least 60 or a grade point average is less than 3.0 and an admission score of at least 80. If they don't meet either of these criteria, display "Reject.")
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AdmissionModularized
{
public class a
{
public String check(double g, double t)
{
if ((g >= 3.0 && t >= 60) || (g < 3.0 && t >= 80))
return "Accept";
else
return "Reject";
}
}
class Program
{
static void Main(string[] args)
{
double gpa, tscor;
a o = new a();
Console.WriteLine("Enter GPA ");
gpa=Convert.ToDouble ( Console.ReadLine());
Console.WriteLine("Enter Test Score ");
tscor = Convert.ToDouble(Console.ReadLine());
String s = o.check(gpa, tscor);
Console.WriteLine("Your Admission is " + s);
Console.ReadKey();
}
}
}