Question
I am using C # Microsoft Visual Studio This is what I need help with and my code is below it: Inheritance This LAB is
I am using C# Microsoft Visual Studio
This is what I need help with and my code is below it:
Inheritance
This LAB is in 2 parts:
Part #1: Create the Person class first.
Part #2: Modify the Student class to use the Person class
Part #1 - Create the Person class. Go to the Menu and select project. Under project, select Add class. Then start typing in your code for a Person class. Properties: Name, Address, Phone, Email. Behaviors: set and get methods, Display(outputs all person data to the Output window using Console.WriteLine()).
Part #2 Modify the Student class that you created in the last lab to use the new Person class. Indicate that the Student class inherits from the Person class. Remove any properties that are already in the Person class. Modify the constructors and the display method, to use code from the Person class.
Your Form class code should not change at all. It should work exactly the same as in the previous lab. If you find yourself changing the code in your Form class, you are probably doing something wrong.
namespace Students { public class Student { private string Name; private string Address; private string Phone; private string Email; private string Major; double GPA;
public Student() { Name = ""; Address = ""; Phone = ""; Email = ""; Major = ""; GPA = 0; }
public Student(string Name, string Address, string Phone, string Email, string Major, double GPA) { this.Name = Name; this.Address = Address; this.Phone = Phone; this.Email = Email; this.Major = Major; this.GPA = GPA;
}
public string getName() { return Name; } public void setName(string name) { Name = name; }
public string getAddress() { return Address; } public void setAddress(string address) { Address = address; }
public string getPhone() { return Phone; } public void setPhone(string phone) { Phone = phone; }
public string getEmail() { return Email; } public void setemail(string email) { Email = email; }
public string getMajor() { return Major; } public void setMajor(string major) { Major = major; }
public double getGPA() { return GPA; } public void setGPA(double gpa) { GPA = gpa; }
public void Display() { Console.WriteLine("Name = " + getName()); Console.WriteLine("Address = " + getAddress()); Console.WriteLine("Phone = " + getPhone()); Console.WriteLine("Email = " + getEmail()); Console.WriteLine("Major = " + getMajor()); Console.WriteLine("GPA = " + getGPA());
} } }
namespace Students { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
Student s1;
void fillBtn_Click(object sender, EventArgs e) { s1 = new Student(); s1 = new Student("Susan Fry", "ATL", "770-221-5555", "Email", "ACCT", 3.2f); }
private void dislpayBtn_Click(object sender, EventArgs e) { s1.Display(); }
private void exitBtn_Click(object sender, EventArgs e) { DialogResult dialog = MessageBox.Show("Do you want to close the program?", "SomeTitle", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { Application.Exit(); } else if (dialog == DialogResult.No) { //do nothing } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started