0% found this document useful (0 votes)
24 views

Lab Assignment 1

This document defines structures and enums for student registration numbers, programs, campuses, sessions, and gender. It includes a Registerationnumber structure that stores registration number details and methods to add, display, and generate emails from registration numbers. A Student structure stores student details including name, registration number, gender, and email. Methods are included to add students and update their details.

Uploaded by

Hassan Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lab Assignment 1

This document defines structures and enums for student registration numbers, programs, campuses, sessions, and gender. It includes a Registerationnumber structure that stores registration number details and methods to add, display, and generate emails from registration numbers. A Student structure stores student details including name, registration number, gender, and email. Methods are included to add students and update their details.

Uploaded by

Hassan Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

// ZAIN UL ABDIN

// LAB ASSIGNEMENT 1
// FA18 BSE 109 (BSSE 6 (A))
// VISUAL PROGRAMMING

// We cannot take Enums in integer/Numeric Type thats why I have not created an
enum of Year.

// We cannot create the default constructors in structures so if no no information


is provided CUI/SP21-BCS-001/ISB will not be displayed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LAB_ASSIGNMENT_1
{
enum Campus
{ ISL, LHR, SHW, WAH, VEH }
enum Session
{ FA, SP }
enum Program
{ BCS, BSE, BAF, BBA, BEE }
enum Gender
{ Male, Female }

struct Registerationnumber
{
private String Rollnumber;
private Session session;
private Program program;
private Campus campus;
private int year;

public Registerationnumber(Campus campus, Session session, Program program,


int year, string rollnumber)
{
this.campus = campus;
this.session = session;
this.program = program;
this.year = year;
this.Rollnumber = rollnumber;
}
public Registerationnumber AddRegNo()
{
Console.WriteLine("Enter Roll number");
String rol = Console.ReadLine();
while (true)
{
Console.WriteLine("Select Campus");
Console.WriteLine("1: ISLAMABAD");
Console.WriteLine("2: LAHORE");
Console.WriteLine("3: SAHIWAL");
Console.WriteLine("4: WAH CANTT");
Console.WriteLine("5: VEHARI");
int x = Convert.ToInt32(Console.ReadLine());
if (x == 1)
{
campus = Campus.ISL;
break;
}
else if (x == 2)
{
campus = Campus.LHR;
break;
}
else if (x == 3)
{
campus = Campus.SHW;
break;
}
else if (x == 4)
{
campus = Campus.WAH;
break;
}
else if (x == 5)
{
campus = Campus.VEH;
break;
}
else
{
Console.WriteLine("invalid selection");
Console.WriteLine("select Again");
}

}
while (true)
{
Console.WriteLine("Enter Session");
Console.WriteLine("1: FALL");
Console.WriteLine("2: SPRING");
int y = Convert.ToInt32(Console.ReadLine());
if (y == 1)
{
session = Session.FA;
break;
}
else if (y == 2)
{
session = Session.SP;
break;
}
else
{
Console.WriteLine("Invalid Selection");
Console.WriteLine("select Again");
}

Console.WriteLine("Enter Year");
int year = Convert.ToInt32(Console.ReadLine());

while (true)
{
Console.WriteLine("Enter Program");
Console.WriteLine("1: Bachelors in computer science");
Console.WriteLine("2: Bachelors in software enginearing");
Console.WriteLine("3: Bachelors in accounting and finance");
Console.WriteLine("4: Bachelors in Business and accounts");
Console.WriteLine("5: Bachelors in Electrical Enginearing");

int p = Convert.ToInt32(Console.ReadLine());
if (p == 1)
{
program = Program.BCS;
break;
}
else if (p == 2)
{
program = Program.BSE;
break;
}
else if (p == 3)
{
program = Program.BAF;
break;
}
else if (p == 4)
{
program = Program.BBA;
break;
}
else if (p == 5)
{
program = Program.BEE;
break;
}
else
{
Console.WriteLine("Invalid! We are not offering this");
Console.WriteLine("Select Again");
}
}

Registerationnumber r = new Registerationnumber(campus, session,


program, year, rol);
return r;
}
public override string ToString()
{
return "CUI/" + this.session + (this.year)%100 + "-" + this.program +
"-" + (this.Rollnumber) + "/" + this.campus;
}
public string Email()
{
return session + "" + year + "-" + program + "-" + Rollnumber + "@" +
(campus) + "student.comsats.edu.pk";
}
struct Student
{
private String Name;
private Registerationnumber reg;
private String email;
private Gender gender;

public Student(String n, Registerationnumber r, Gender g)


{
this.Name = n;
this.email = r.Email();
this.gender = g;
this.reg = r;
}

public Registerationnumber Reg


{
get { return this.reg; }
set { this.reg = value; }
}
public Gender Gen
{
get { return this.gender; }
set { this.gender = value; }
}
public String nam
{
get { return this.Name; }
set { this.Name = value; }
}

public override string ToString()


{
return "Name: " + this.Name + "\nRegisteration number: " + this.reg
+ "\nGender: " + this.gender + "\nEmail: " + this.email;
}

public Student Addstudent()


{
Console.WriteLine("Enter Student Details");
Registerationnumber x = new Registerationnumber();
Registerationnumber reg = x.AddRegNo();

Console.WriteLine("Enter Student's Name");


String Name = Console.ReadLine();
while (true)
{
Console.WriteLine("Select Gender");
Console.WriteLine("1: Male");
Console.WriteLine("2: Female");
int g = Convert.ToInt32(Console.ReadLine());
if (g == 1)
{
gender = Gender.Male;
break;
}
else if (g == 2)
{
gender = Gender.Female;
break;
}
else
{
Console.WriteLine("Invalid Selection!");
Console.WriteLine("Select Again");
}
}
Student student = new Student(Name,reg,gender);
return student;
}

public void Updatestudent( Student[] students, int j)


{
while (true)
{
Console.WriteLine("Registeration number found");
Console.WriteLine("What do you want to update");
Console.WriteLine("Regesteration no? Press 1");
Console.WriteLine("Gender? Press 2");
Console.WriteLine("Name? Press 3");
int x = Convert.ToInt32(Console.ReadLine());

if (x == 1)
{

Registerationnumber newreg = new Registerationnumber();


Registerationnumber sav = newreg.AddRegNo();
students[j].Reg = sav;
break;
}
else if (x == 2)
{
while (true)
{
Console.WriteLine("Select Gender");
Console.WriteLine("1: Male");
Console.WriteLine("2: Female");
int g = Convert.ToInt32(Console.ReadLine());
if (g == 1)
{
students[j].Gen = Gender.Male;
break;
}
else if (g == 2)
{
students[j].Gen = Gender.Female;
break;
}
else
{
Console.WriteLine("Invalid Selection!");
Console.WriteLine("Select Again");
}
}
break;
}
else if (x == 3)
{
Console.WriteLine("Enter Updated Name");
students[j].nam = Console.ReadLine();
break;
}
else
{
Console.WriteLine("Invalid Selection");
Console.WriteLine("Select again");
}
}
}
public void DUpdatestudent(List<Student> s, int j)
{
while (true)
{
Console.WriteLine("Registeration number found");
Console.WriteLine("What do you want to update");
Console.WriteLine("Regesteration no? Press 1");
Console.WriteLine("Gender? Press 2");
Console.WriteLine("Name? Press 3");
int x = Convert.ToInt32(Console.ReadLine());

if (x == 1)
{

Registerationnumber newreg = new Registerationnumber();


Registerationnumber sav = newreg.AddRegNo();
Student stud = s[j];
stud.Reg = sav;
s[j] = stud;
break;

}
else if (x == 2)
{
Console.WriteLine("Select Gender");
Console.WriteLine("1: Male");
Console.WriteLine("2: Female");
int g = Convert.ToInt32(Console.ReadLine());
Gender gend = new Gender();

if (g == 1)
{

gend = Gender.Male;
}
else if (g == 2)
{
gend = Gender.Female;
}
Student stud = s[j];
stud.Gen = gend;
s[j] = stud;

break;
}
else if (x == 3)
{
String nam = Console.ReadLine();
Student stud = s[j];
stud.Name = nam;
s[j] = stud;
break;
}
else
{
Console.WriteLine("Invalid Selection");
Console.WriteLine("Select Again");
}
}

}
public void Deletestudent(Student s, Student[] students,int tem)
{
try
{
for (int i = 0; i < tem; i++)
{
if (s.reg.Equals(students[i].reg))
{
students[i] = students[i + 1];
}
}
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("index out of bound exception");
}

}
public void DDeletestudent(Student s, List<Student> st, int tem)
{
for (int i = 0; i < tem; i++)
{
if (s.reg.Equals(st[i].reg))
{
st[i] = st[i + 1];
}
}
}
}

class LAB1
{
static void Main(string[] args)
{
Console.WriteLine("How do you want to perform actions");
Console.WriteLine("Statically? Press 1");
Console.WriteLine("Dynamically? Press 2");
int a = Convert.ToInt32(Console.ReadLine());
if (a == 1)
{
Console.WriteLine("Enter number of students in class: ");
int x = Convert.ToInt32(Console.ReadLine());
if (x < 0)
{
throw new Exception("Negative number is not allowed");
}
Student[] Students = new Student[x];
bool z = true;
int temp = 0;
while (z == true)
{
Console.WriteLine("1: Add Student");
Console.WriteLine("2: Update Student");
Console.WriteLine("3: Delete Student");
Console.WriteLine("4: Display Student");
Console.WriteLine("5: Exit");
int y = Convert.ToInt32(Console.ReadLine());
{
if (y == 1)
{
Student S = new Student();
Students[temp] = S.Addstudent();
temp++;
}
else if (y == 2)
{
Registerationnumber std = new
Registerationnumber();
Registerationnumber stdnew = std.AddRegNo();

for (int j = 0; j < temp; j++)


{
if (stdnew.Equals(Students[j].Reg))
{
Student S = new Student();
S.Updatestudent(Students, j);
}
}

}
else if (y == 3)
{
Student ext = new Student();
ext = ext.Addstudent();
ext.Deletestudent(ext, Students,temp);
temp--;
}
else if (y == 4)
{
for (int k = 0; k < temp; k++)
Console.WriteLine(Students[k].ToString());
}
else if (y == 5)
{
z = false;
}
else
{
Console.WriteLine("Entered invalid number");
Console.WriteLine("Enter Again");
}
}
}
}
else if (a == 2)
{

List<Student> student = new List<Student>();


bool z = true;
int temp = 0;
while (z == true)
{
Console.WriteLine("1: Add Student");
Console.WriteLine("2: Update Student");
Console.WriteLine("3: Delete Student");
Console.WriteLine("4: Display Student");
Console.WriteLine("5: Exit");
int y = Convert.ToInt32(Console.ReadLine());
{
if (y == 1)
{
Student S = new Student();
student.Add(S.Addstudent());
temp++;
}
else if (y == 2)
{
Registerationnumber std = new
Registerationnumber();
Registerationnumber stdnew = std.AddRegNo();

for (int j = 0; j < temp; j++)


{
if (stdnew.Equals(student[j].Reg))
{
Student S = new Student();
S.DUpdatestudent(student, j);
}
}

}
else if (y == 3)
{
Student ext = new Student();
ext = ext.Addstudent();
ext.DDeletestudent(ext, student,temp);
temp--;
}
else if (y == 4)
{
for (int k = 0; k < temp; k++)
Console.WriteLine(student[k].ToString());
}
else if (y == 5)
{
z = false;
}
else
{
Console.WriteLine("Entered invalid number");
}
}
}
}
}
}
}
}

You might also like