Lab Assignment 1
Lab Assignment 1
// 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.
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;
}
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");
}
}
if (x == 1)
{
if (x == 1)
{
}
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();
}
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)
{
}
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");
}
}
}
}
}
}
}
}