In: Computer Science
This is in C# on visual Basic
For example,
Student {
Property: StudentName
Property: Contact
Method: CalculateFinalGrade()
}
For example, (note: the following are pseudo codes, not C#)
UndergraduateStudent : Student {
Property: QuizScore
Method: CalculateFinalGrade {
theQuiz = QuizScore/250
if theQuiz >= 0.90 then
finalGrade = "A"
else if theQuiz >= 0.80 then
finalGrade = "B"
...
else if theQuiz <= 0.60 then
finalGrade = "F"
finalGrade
}
Note:
3. Use the classes in the above to implement the GradeCalculation program as follows. (2 points)
In this program, you don’t need to implement data validation (even though I did it in the demo program). Make sure to hide the Term Paper textbox when the undergraduate is selected.
Source Code:
using System;
class Student {
protected string name;
protected string no;
protected string s;
public void getdetails(){
Console.WriteLine("Enter Name:");
name = Console.ReadLine();
Console.WriteLine("Enter PhoneNumber:");
no = Console.ReadLine();
}
public void printdetails(){
Console.WriteLine("Name:"+name+"\n");
Console.WriteLine("PhoneNumber:"+no+"\n");
}
public string CalculateFinalGrade(double a){
if(a>=90){s="A";}
else if(a<90 && a>=80){s= "B";}
else if(a<80 && a>=70){s="C";}
else if(a<70 && a>=60){s="D";}
else if(a<60){s="F";}
Console.WriteLine(s);
return s;
}
static void Main() {
int ch;
Graduate g1 = new Graduate();
underGraduate u1 = new underGraduate();
Console.WriteLine("1.Under Graduate\n2.Graduate");
Console.WriteLine("Enter Your Choice:");
ch = Convert.ToInt32(Console.ReadLine());
if(ch == 1)
{
u1.getData();
u1.printData();
}
if(ch == 2)
{
g1.getData();
g1.printData();
}
}
}
class Graduate : Student // Derived Class
{
int quiz_score,term_score;
string s;
public void getData(){
getdetails();
Console.WriteLine("Enter quiz_score(out of 250):");
s = Console.ReadLine();
quiz_score = Convert.ToInt32(s);
Console.WriteLine("Enter term_score(out of 50):");
s = Console.ReadLine();
term_score = Convert.ToInt32(s);
double total_percentage = (quiz_score + term_score)/3;
s = CalculateFinalGrade(total_percentage);
}
public void printData(){
printdetails();
Console.WriteLine("Quiz Score:"+quiz_score);
Console.WriteLine("Term Score:"+term_score);
Console.WriteLine("Total Score:300");
Console.WriteLine("Grades:"+s);
}
}
class underGraduate : Student
{
int quiz_score;
public void getData(){
getdetails();
Console.WriteLine("Enter quiz_score(out of 250):");
s = Console.ReadLine();
quiz_score = Convert.ToInt32(s);
double total_percentage = (quiz_score)/2.5;
s = CalculateFinalGrade(total_percentage);
}
public void printData(){
printdetails();
Console.WriteLine("Quiz Score:"+quiz_score);
Console.WriteLine("Total Score:250");
Console.WriteLine("Grade:"+s);
}
}
OUTPUT:
Thankyou
Thumbs Up if you satisfy with answer