2. The same way we implemented automatic reference counting for the Person class
ID: 3782522 • Letter: 2
Question
2. The same way we implemented automatic reference counting for the Person class, provide an automatic Student ID generator for the class student. The ID generator works exactly the same way that the reference counter does for
the class Person. Of course the result from the ID generator is placed within a member variable of type int;
3. This question explicitly asks for implementation of a Student Roster class. he class should be named "StudentRoster". Ideally, the StudentRoster class should posess the properties of a dictionary. Look up the definition of a Dictionary in C#, and how to use a dictionary using the example of the method "static voidExampleUsingDictionary()" in Program.cs. Also, by looking up the definition (from the source file Dictionary), you will realize that the method Add (which we will use to add students to our Roster), is not virtual, which means that:
Having StudentRoster should not inherit from Dictionary, because the Add method for StudentRoster will add Students, but the the same Add method from Dictionary is NOT virtual.
Look up aggregation in OOP, and add the functionalities of a Dictionary to the class Student_Roster accordingly.
4. If you understood and answered Question 3 correctly, you should realize that although you added the functionalities of a Dictionary to the class Student_Roster, you still need to initialize it. So do it in this question.
5. Develop a IContactable interface which forces the implementation of
Properties
PhoneNumber
6. Implement the properties forced "upon you" by IContactable
7. Add a property for the student ID (both read and write)
8. Create a property for the age member variable
9. Create a property for the member variable m_FirstName (read and write)
10. Create a property for the member variable m_hairColor (read and write)
11. Create an interface "IPrinter" with a skeleton method "void Print(String theMessage )"
12. Create two classes, "ConsolePrinter" and "GuiPrinter", and have them implement IPrinter. For ConsolePrinter, the message printing is done using
Contactable Debug Student Class Person Fields m Email m id mid count m Phone Number m printer Properties Email Phone Number Methods G. prepare debug info Debug Student Student Roster Class Fields m Student Dictionary Methods Add Student Roster Person Class Fields m-age m First Name m haircolor m .LastName m NumberReferences roperties Age FirstName Haircolor LastName Methods GetFirstName NumberReferences Person 2 overloads PrintOutConten Set First Name Printer Contactable Methods Properties Print Email PhoneNumber Methods Debug Printe Console Printer A Methods Print Printer GUI Printer Methods PrintExplanation / Answer
ConsolePrinter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public class ConsolePrinter : IPrinter
{
public void Print(string TheMessage)
{
Console.WriteLine(TheMessage);
}
}
}
GuiPrinter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter_11_code
{
public class GuiPrinter : IPrinter
{
public void Print(string TheMessage)
{
MessageBox.Show(TheMessage);
}
}
}
IContactable.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public interface IContactable
{
string PhoneNumber
{
get;
set;
}
string Email
{
get;
set;
}
}
}
IDebug.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public interface IDebug
{
void Debug();
}
}
IPrinter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public interface IPrinter
{
void Print(string TheMessage);
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter_11_code
{
class Program
{
static void Main(string[] args)
{
//this is how we declare a new object of the class person
student pA = new student ("Julien", "Esposito", 35, "Dark", 3.5f);
student pB = new student ("Christopher", "McCall", 29, "Dark", 2.0f);
student pC = new student ("Greg", "McKee", 30, "Dark", 1.5f);
student pD = new student("Timmy", "turner", 18, "brown", 3.0f);
//Instructor i = new Instructor();
pA.PrintOutContent();
pA.PrintGPA(pA.m_gpa);
Console.WriteLine("Number of items created " + person.NumReferences());
A.Dictionary_totorial();
Student_Roster roster = new Student_Roster();
roster.Add(pA.ID, pA);
roster.Add(pB.ID, pB);
roster.Add(pC.ID, pC);
student Chris =roster[2];
pA.m_IPrinter = new ConsolePrinter();
pB.m_IPrinter = new GuiPrinter();
pA.Debug();
pB.Debug();
Console.ReadLine();
}
}
}
Student_Roster.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public class Student_Roster : Dictionary <int, student>
{
public void Add(int student_id, student Student)
{
base.Add(student_id, Student);
}
}
}
person.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
// we make person public, meaning its accessible from other modules can access and use class
public class person
{
private static int NumberReferences = 0;
public static int NumReferences()
{
return NumberReferences;
}
protected string m_FirstName;
protected string m_LastName;
protected int m_age;
protected string m_Haircolor;
//this kind of method when you set a member variables is called a setter.
public void SetFirstName(string firstname)
{
m_FirstName = firstname;
}
//this type of method (reading back the value of a memeber variable is called a getter)
public string FirstName
{
get
{
return m_FirstName;
}
set
{
m_FirstName = value;
}
}
public int age
{
get
{
return m_age;
}
set
{
m_age = value;
}
}
public string LastName
{
get
{
return m_LastName;
}
set
{
m_LastName = value;
}
}
// this is a constructor. because default no imput required also no return value
protected person()
{
m_FirstName = "Jane";
m_LastName = "Doe";
m_age = 0;
m_Haircolor = "Ginger";
}
public String HairColor
{
set
{
m_Haircolor = value;
}
get
{
return m_Haircolor;
}
}
// this is an parameterized contructor, meaning it takes its one parameters
public person(string fn, string ln, int age, string haircolor)
{
NumberReferences = NumberReferences + 1;
m_FirstName = fn;
m_LastName = ln;
m_age = age;
m_Haircolor = haircolor;
}
public person( ref person p)
{
}
public void PrintOutContent()
{
Console.WriteLine("First name = " + m_FirstName);
Console.WriteLine("Last name = " + m_LastName);
Console.WriteLine("Age = " + m_age);
Console.WriteLine("Hair color = " + m_Haircolor);
}
}
}
student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter_11_code
{
public class student : person, IContactable, IDebug
{
private static int id = 0;
public float m_gpa;
private int m_id;
public string m_email;
public string m_PhoneNumber;
public IPrinter m_IPrinter;
public void Debug()
{
string everything = "First name = " + m_FirstName + " Last name = " + m_LastName + " age =" + m_age + " Hair Color = " + m_Haircolor + " gpa = " + m_gpa ;
m_IPrinter.Print(everything);
}
public string Email
{
get
{
return m_email;
}
set
{
m_email = value;
}
}
public string PhoneNumber
{
get
{
return m_PhoneNumber;
}
set
{
m_PhoneNumber = value;
}
}
public float GPA
{
get
{
return m_gpa;
}
set
{
m_gpa = value;
}
}
public static int Id()
{
return id;
}
public int ID
{
get
{
return m_id;
}
set
{
m_id = value;
}
}
public student( string fn, string ln, int age, string haircolor, float gpa)
: base(fn, ln, age, haircolor)
{
m_gpa = gpa;
id = id + 1;
m_id = id;
}
public void PrintGPA(float m_gpa)
{
Console.WriteLine("gpa = " + m_gpa);
Console.WriteLine("id = " + id);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.