Im trying to complete these 2 objectives using C#. I missed the class explaining how to populate an array with an object so i dont really have a starting point how to do the second objective.
"1. Create a Student class with two fields, StudentName (string) and StudentNumber (int), the appropriate properties (i.e. get and set) and constructors (default and non-default). The student name will default to an empty string while the student number will default to -1.
- Use the Student class to solve the following problem. Create a program that will allow a user to input up to 24 students into an array ensuring that the student number is exactly 5 digits long. Once all the students have been entered, allow the user to do sequential searches for students by either name or number. Display the full student name and number if found, or an error message if not. Allow the user to keep searching until they decide to quit."
The first part i got working and here is my Student Class:
class Student
{
// fields
private string _studentName;
private int _studentNumber;
// properties
public string studentName
{
get
{
return _studentName;
}
set
{
studentName = value;
}
}
public int studentNumber
{
get
{
return _studentNumber;
}
set
{
studentNumber = value;
}
}
// constructors
// default - no parameters
public Student()
{
_studentName = "";
_studentNumber = -1;
}
// non default - takes perameters
public Student(string studentName, int studentNumber)
{
_studentName = studentName;
_studentNumber = studentNumber;
}
}
And here is my main program:
class Program
{
static void Main(string[] args)
{
////////////// Question 1 ////////////////
// create new student
Student defaultStudent = new Student();
// display student
InputOutput.DisplayStudentInformation(defaultStudent);
// keep console open
Console.ReadLine();
}
}
Now im running into the problem with the second part of the objective. I don't know how to use the Object(student) class to help me create a user entered array as i missed that particular lecture.
Im not asking for someone to do the whole assignment for me, i just don't know how to populate the array with a studentName and studentNumber with user input.
I am at my wits end trying to get a starting point here. Anyone?