Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using MyDLL;
- namespace StudentData
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- Student stud = new Student();
- int choice, studnumber;
- string coursecode;
- Console.WriteLine("====================");
- Console.WriteLine("======= MENU =======");
- Console.WriteLine("====================");
- Console.WriteLine("[1] Add Student\n[2] Display All\n[3] Display Student\n[4] Display Course");
- Console.WriteLine("====================");
- Console.Write("Enter your choice: ");
- choice = Convert.ToInt32(Console.ReadLine());
- switch (choice)
- {
- case 1: EnrollStudent(stud);
- break;
- case 2: DisplayStudentProfile();
- break;
- case 3: Console.WriteLine("Enter student number: ");
- studnumber = Convert.ToInt32(Console.ReadLine());
- break;
- case 4: Console.WriteLine("Enter course code: ");
- coursecode = Convert.ToString(Console.ReadLine());
- break;
- default: Console.WriteLine("Invalid input. Please enter from numbers 1-4 only.");
- break;
- }
- }
- catch (FormatException e)
- {
- Console.WriteLine(e.Message);
- }
- Console.Read();
- }
- static void EnrollStudent(Student s)
- {
- Console.Clear();
- try
- {
- string path = @"D:\MCL\StudentsData\";
- path = string.Concat(path, ".txt");
- using (StreamWriter sw = new StreamWriter(path))
- {
- Console.Write("Enter student number: ");
- s.StudNum = Convert.ToInt32(Console.ReadLine());
- sw.WriteLine(s.StudNum);
- Console.Write("Enter full name of student: ");
- s.FullName = Console.ReadLine();
- sw.WriteLine(s.FullName);
- Console.Write("Enter student program: ");
- s.StudProgram = Console.ReadLine();
- sw.WriteLine(s.StudProgram);
- Console.Write("Enter father's name: ");
- s.FatherName = Console.ReadLine();
- sw.WriteLine(s.FatherName);
- Console.Write("Enter mother's name: ");
- s.MotherName = Console.ReadLine();
- sw.WriteLine(s.MotherName);
- Console.Write("Enter birthdate [yyyymmdd]: ");
- s.BirthDate = Convert.ToInt32(Console.ReadLine());
- sw.WriteLine(s.BirthDate);
- for (int i = 0; i < s.StudCourse.Length; i++)
- {
- Console.Write("Enter Course {0}: ", i + 1);
- s.StudCourse[i] = Console.ReadLine();
- sw.WriteLine(s.StudCourse[i]);
- }
- sw.Close();
- }
- }
- catch (IOException e)
- {
- Console.WriteLine(e.Message);
- }
- }
- public static void DisplayStudentProfile()
- {
- try
- {
- string path = @"D:\MCL\StudentsData\";
- path = string.Concat(path, ".txt");
- string[] stud = File.ReadAllLines(path);
- Student s = new Student();
- s.FullName = (string)stud.GetValue(0);
- for (int i = 0; i < stud.Length - 6; i++)
- {
- s.StudCourse[i] = (string)stud.GetValue(i + 6);
- }
- foreach (string data in stud)
- {
- Console.WriteLine(data);
- }
- }
- catch (IOException e)
- {
- Console.WriteLine(e.Message);
- }
- catch (IndexOutOfRangeException e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement