Assignment 1
Program to fetch subject to which student is enrolled to :
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static Student[] student_records = new Student[5];
public static Teacher[] teacher_records = new Teacher[2];
static void Main(string[] args)
{
for (int i = 0; i < student_records.Length; i++)
{
student_records[i] = new Student();
Console.WriteLine(" Enter the Student ID:");
student_records[i].Sid = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" Enter the Student Name:");
student_records[i].Sname = Console.ReadLine();
Console.WriteLine(" Enter the Teacher ID:");
student_records[i].Tid = Convert.ToInt32(Console.ReadLine());
}
for (int j = 0; j < teacher_records.Length; j++)
{
teacher_records[j] = new Teacher();
Console.WriteLine(" Enter the Teacher ID:");
teacher_records[j].Tid = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" Enter the Teacher Name:");
teacher_records[j].Tname = Console.ReadLine();
Console.WriteLine(" Enter the Subject:");
teacher_records[j].Sub = Console.ReadLine();
}
Console.WriteLine("Enter Student ID to get the subject enrolled: ");
String subject = getData(Convert.ToInt32(Console.ReadLine()));
Console.WriteLine("Subject Enrolled: " + subject);
Console.ReadLine();
}
public static String getData(int sid)
{
String subject = null;
for (int i = 0; i < student_records.Length; i++)
{
if (student_records[i].Sid == sid)
{
for (int j = 0; j < teacher_records.Length; j++)
{
if (teacher_records[j].Tid == student_records[i].Tid)
{
subject = teacher_records[j].Sub;
break;
}
}
break;
}
}
return subject;
}
}
class Student
{
private int sid, tid;
private String sname;
public int Sid
{
get
{
return sid;
}
set
{
sid = value;
}
}
public String Sname
{
get
{
return sname;
}
set
{
sname = value;
}
}
public int Tid
{
get
{
return tid;
}
set
{
tid = value;
}
}
}
class Teacher
{
private int tid;
private String tname, sub;
public int Tid
{
get
{
return tid;
}
set
{
tid = value;
}
}
public String Tname
{
get
{
return tname;
}
set
{
tname = value;
}
}
public String Sub
{
get
{
return sub;
}
set
{
sub = value;
}
}
}
}
Assignment 1
Reviewed by Share less to Learn More
on
7:40 PM
Rating:
No comments