using System namespace Test Description of Student publi

using System;

namespace Test
{
     /// <summary>
     /// Description of Student.
     /// </summary>
     public class Student
     {
         string Name, Address, Phone, Email, Major;
         double GPA;
        
         public Student()
         {
             Name=\"\";
             Address=\"\";
             Phone=\"\";
             Email=\"\";
             Major=\"\";
             GPA=0;
         }
         public void setGPA(double gpa)
         {
             GPA=gpa;
         }
         public double getGPA()
         {
             return GPA;
         }
        
         public void setMajor(string major)
         {
             Major=major;
         }
         public string getMajor()
         {
             return Major;
         }
         public void setPhone(string phone)
         {
             Phone=phone;
         }
         public string getPhone()
         {
             return Phone;
         }
         public void setAddress(string address)
         {
             Address=address;
         }
         public string getAddress()
         {
             return Address;
         }
         public void setEmail(string email)
         {
             Email=email;
         }
         public string getEmail()
         {
             return Email;
         }
         public void setName(string name)
         {
             Name=name;
         }
         public string getName()
         {
             return Name;
         }
     }
}

Add Constructors to the Student class above

Add 2 constructors to the Student class. One that takes no arguments and initializes the data to all 0’s and “”(empty strings). And one constructor that takes 6 arguments, one argument for each property and then sets the properties to these arguments that are passed in. Lastly change your event code, to use these new Constructors. You will not need to call the set functions any more, but do not remove the set functions from your class.

Change Part #3 from Lab #10 to now use these constructors.

Student s1; //declare as global data

//Fill Button

s1 = new Student(567, “Susan Fry”, “Atl”, “770-221-5555”, “ACCT”, 3.2f);

//Display Button

s1.display();

Solution

You just need to add this constructor in your class:

         public Student(double GPA, string Name, string Address, string Phone, string Email, string Major){
              this.Name = Name;
              this.Address = Address;
              this.Phone = Phone;
              this.Email = Email;
              this.Major = Major;
              this.GPA = GPA;
         }


and then create the object in your driver class using this new constructor.

Hence, the final code:

using System;

namespace Test
{
     /// <summary>
     /// Description of Student.
     /// </summary>
     public class Student
     {
         string Name, Address, Phone, Email, Major;
         double GPA;

         public Student()
         {
             Name=\"\";
             Address=\"\";
             Phone=\"\";
             Email=\"\";
             Major=\"\";
             GPA=0;
         }

         public Student(double GPA, string Name, string Address, string Phone, string Email, string Major){
              this.Name = Name;
              this.Address = Address;
              this.Phone = Phone;
              this.Email = Email;
              this.Major = Major;
              this.GPA = GPA;
         }

         public void setGPA(double gpa)
         {
             GPA=gpa;
         }
         public double getGPA()
         {
             return GPA;
         }

         public void setMajor(string major)
         {
             Major=major;
         }
         public string getMajor()
         {
             return Major;
         }
         public void setPhone(string phone)
         {
             Phone=phone;
         }
         public string getPhone()
         {
             return Phone;
         }
         public void setAddress(string address)
         {
             Address=address;
         }
         public string getAddress()
         {
             return Address;
         }
         public void setEmail(string email)
         {
             Email=email;
         }
         public string getEmail()
         {
             return Email;
         }
         public void setName(string name)
         {
             Name=name;
         }
         public string getName()
         {
             return Name;
         }
     }
}

using System; namespace Test { /// <summary> /// Description of Student. /// </summary> public class Student { string Name, Address, Phone, Email, M
using System; namespace Test { /// <summary> /// Description of Student. /// </summary> public class Student { string Name, Address, Phone, Email, M
using System; namespace Test { /// <summary> /// Description of Student. /// </summary> public class Student { string Name, Address, Phone, Email, M
using System; namespace Test { /// <summary> /// Description of Student. /// </summary> public class Student { string Name, Address, Phone, Email, M

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site