Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this so far for an assignment that needs to create a gradStudent class that inherits from a student class. But i need to

I have this so far for an assignment that needs to create a gradStudent class that inherits from a student class. But i need to also have the Degree Name, their GPA and also their Masters Program name. But Im stuck on having to show the GPA. I only get the grade. I might have put the wrong equation. I just want to make sure its right.

class Stud { protected string fName, lName; protected float ex1, ex2, ex3; protected float avg;

public Stud() { fName = lName = ""; ex1 = ex2 = ex3 = avg = 0; } public Stud(string fName, string ln, float e1, float e2, float e3) { this.fName = fName; this.lName = ln; ex1 = e1; ex2 = e2; ex3 = e3; } public void calAvg() { float tmp = ex1 + ex2 + ex3; this.avg = tmp / 3.0f;

} public virtual void disp() { Console.WriteLine(fName + " " + lName + " " + avg); } } class GradStud : Stud { string bsName, prg; float bsAvg; public GradStud(string fName, string ln, float e1, float e2, float e3, string bn, string p, float ba) : base(fName, ln, e1, e2, e3) { bsName = bn; prg = p; bsAvg = ba;

} public override void disp() { base.disp(); Console.WriteLine(bsName + " " + prg); } } static void Main(string[] args) { Stud s1 = new Stud("Jane", "Doe", 100f, 95f, 75f); s1.calAvg(); s1.disp();

GradStud ds2 = new GradStud("Joe", "Smith", 45, 85, 95, "Computer Engineering,", "Computer Science", 3.50f); ds2.calAvg(); ds2.disp();

Stud[] list = { new Stud("George", "Hall", 100f, 95f, 75f), new GradStud("Julia", "Hernadez", 45, 85, 95, "Psychology,", "Biology", 3.50f) };

Console.WriteLine(" "); foreach (var s in list) { s.calAvg(); s.disp(); } Console.ReadKey(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions