Faculty of Information Technology Department of Software Engineering Assignment3

advertisement
Faculty of Information Technology
Department of Software Engineering
Assignment3
Lecturer
: Dr. Ali Fouad
Module
: Object Oriented Programming
1) Create Student class with

Three-argument constructor that initializes name, age, and ID number fields.
 Property with modifier only that sets ID number.
 ToString method that returns out the class fields as a string.
Answer
2. Write the Course class to represent a course. A course can have maximum 20
students. Your Course class should contain the followings:




Declaration of the required fields.
The constructor which doesn’t take any argument and creates a student list
without putting any student into this list.
The instance method addStudent which adds the given Student object into the
student list.
The instance method printall which prints the name, age, and Id number of
each student in that course.
3. Write the Test class that create three objects of type Student and ob object of type
Course, add students to course and than print all students in the course
public class student
{
private
string name;
private
int age
private
string id;
public student(string en, int ea, string eid){
id = eid;
name=en;
age=ea;
}
public string Id{
set {id=value ; }
}
public override string ToString(){
return string.Format(“{Name is :{0} ID number is {1} ”, name, id);
}
}
class Course {
private string cname;
private Student[] empList;
private int numOfEmp=0;
public Course (string cn) {
cname=cn;
empList = new Student [20];
}
public void addStudent (Student e) {
empList[numOfEmp++]=e;
}
public void printall() {
for (int i=0; i<numOfEmp; i++)
Consile.WriteLine(empList[i]);
}
class Test
{
public static void Main()
{
Student s1 = new Student( "Ahmed", 18,"20141002900");
Student s 2= new Student( "Mohammed",19,"2014345676");
Student s 3= new Student("Layla", 18,"201423445");
Course c = new Course("Object Oriented Programming");
c.addstudent(s1);
c.addstudent(s2);
c.addstudent(s3);
c.printall();
}
}
}
Download