A command-line interface project for a Programming with C# course taught by Microsoft through their edX.org program.
Tools Utilized: C#, OOP in C#, .NET Framework
View this project on GitHub
The purpose of this project was to create a database of courses, teachers, students, and their grades. There is more to this than what's below, I just wanted to show two examples of classes: Creating an individual record and adding that record to a larger database.
Learn more about the course here.
-
Student class, which inherits from the Person class:
The Person class, which also shares member variables with the Teacher class:
class Student : Person { public static int numOfStudents = 0; public static Stack<int> Grades = new Stack<int>(); private static Random r = new Random(); public static void StudentGrades(Stack<int> Grades) { for (int i = 0; i < 5; i++) { Grades.Push(r.Next(50, 100)); } } public Student(string _firstName, string _lastName, string _city, string _state) { numOfStudents++; this.firstName = _firstName; this.lastName = _lastName; this.city = _city; this.state = _state; } }
The Teacher class:class Person { public string firstName { get; set; } public string lastName { get; set; } public string city { get; set; } public string state { get; set; } }
class Teacher : Person { // member variables public int empNumber { get; set; } public string department { get; set; } // Teacher profile public Teacher(string _firstName, string _lastName, string _city, string _state, string _department, int _empNumber) { this.firstName = _firstName; this.lastName = _lastName; this.city = _city; this.state = _state; this.department = _department; this.empNumber = _empNumber; } }
-
This is the class that builds the output:
class Course : UProgram { public static void CreateStudentList(List<Student> students) { // The student objects Student student0 = new Student("Michael", "Winston", "Manhattan", "NY"); Student student1 = new Student("Jalal", "Abramsson", "Queens", "NY"); Student student2 = new Student("Arnleik", "Gjersvik", "Brooklyn", "NY"); // Add them to the list<> students.Add(student0); students.Add(student1); students.Add(student2); } public static void CreateTeacherList(List<Teacher> teachers) { // The teacher Teacher teacher1 = new Teacher("Gerry", "O'Brien", "Redmond", "WA", "Information Technology", 1); // Add them to the list<> teachers.Add(teacher1); } // method for printing students and grades public static void ListStudents(List<Student> students) { foreach (Student student in students) { // Print the students Console.WriteLine("{0} {1}", student.firstName, student.lastName); // Print their grades Console.Write("Grades: "); // I'm using the StudentGrades method from the Student class var Grades = new Stack<int>(); Student.StudentGrades(Grades); foreach (int _grades in Grades) { Console.Write("{0} ", _grades); } Console.WriteLine("\n-----------------\n"); } } }