stefan1919

EdExC# Assignment Complex Data Structures

Oct 31st, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ModuleThreeAssignment
  8. {
  9.     class Program
  10.     {
  11.         //The structure for student
  12.         public struct Student
  13.         {
  14.             public Student(string name, string currentDegree, string age, double gpa)
  15.             {
  16.                 this.Name = name;
  17.                 this.CurrentDegree = currentDegree;
  18.                 this.Age = age;
  19.                 this.Gpa = gpa;
  20.             }
  21.             public string Name;
  22.             public string CurrentDegree;
  23.             public string Age;
  24.             public double Gpa;
  25.         }
  26.         //The structure for Teacher
  27.         public struct Teacher
  28.         {
  29.             public Teacher(string name, string qualification, int age, string department)
  30.             {
  31.                 this.Name = name;
  32.                 this.Qualiffication = qualification;
  33.                 this.Age = age;
  34.                 this.Department = department;
  35.             }
  36.             public string Name;
  37.             public string Qualiffication;
  38.             public int Age;
  39.             public string Department;
  40.         }
  41.         //The structure for program
  42.         public struct ProgramInf
  43.         {
  44.         public ProgramInf(string name, DateTime startDate, DateTime endDate, int freePlaces)
  45.         {
  46.             this.Name = name;
  47.             this.StartDate = startDate;
  48.             this.EndDate = endDate;
  49.             this.FreePlaces = freePlaces;
  50.         }
  51.         public string Name;
  52.         public DateTime StartDate;
  53.         public DateTime EndDate;
  54.         public int FreePlaces;
  55.         }
  56.  
  57.         //The structure for Course
  58.         public struct Course
  59.         {
  60.          public Course(string name, string professor, string department, int credits, string semester)
  61.         {
  62.             this.Name = name;
  63.             this.Professor = professor;
  64.             this.Department = department;
  65.             this.Credits = credits;
  66.             this.Semester = semester;
  67.         }
  68.          public string Name;
  69.          public string Professor;
  70.          public string Department;
  71.          public int Credits;
  72.          public string Semester;
  73.         }
  74.  
  75.  
  76.         //The Main
  77.         static void Main(string[] args)
  78.         {
  79.             Console.WriteLine("Please select the type of information you want to receive: student, teacher,  program, course");
  80.             string input = Console.ReadLine();
  81.             if (input == "student")
  82.             {
  83.                 StudentInformation();
  84.             }
  85.             else if (input == "teacher")
  86.             {
  87.                 TeacherInformation();
  88.             }
  89.             else if (input == "program")
  90.             {
  91.                 GetProgramInformation();
  92.             }
  93.             else if(input == "course")
  94.             {
  95.                 GetCourseInformation();
  96.             }
  97.         }
  98.  
  99.         //Group of methods for student
  100.         static void StudentInformation()
  101.         {
  102.             Console.Write("Enter the name: ");
  103.             string name = Console.ReadLine();
  104.             Console.Write("Enter the degree: ");
  105.             string degreeStudent = Console.ReadLine();
  106.             Console.Write("Enter the age: ");
  107.             string age = Console.ReadLine();
  108.             Console.Write("Enter the GPA: ");
  109.             double gpa = double.Parse(Console.ReadLine());
  110.             Student student1 = new Student(name, degreeStudent, age, gpa);
  111.             Console.WriteLine("If you want to check how my array works type: check array. Else just type something other like \"no\"");
  112.             string input1 = Console.ReadLine();
  113.             if (input1 == "check array")
  114.             {
  115.                 Student[] studentArray = new Student[1];
  116.                 studentArray[0] = student1;
  117.                 foreach (var student in studentArray)
  118.                 {
  119.                 Console.WriteLine("{0} is persuading a degree in {1} and is {2} years-old. Current GPA: {3}", student.Name, student.CurrentDegree, student.Age, student.Gpa);
  120.                 }
  121.             }
  122.             else
  123.             {
  124.                 PrintStudentInformation(student1.Name, student1.CurrentDegree, student1.Age, student1.Gpa);
  125.             }
  126.         }
  127.         static void PrintStudentInformation(string name, string degree, string age, double gpa)
  128.         {
  129.             Console.WriteLine("{0} is persuading a degree in {1} and is {2} years-old. Current GPA: {3}", name, degree, age, gpa);
  130.         }
  131.  
  132.         //Group of methods for teacher
  133.         static void TeacherInformation()
  134.         {
  135.             Console.Write("Enter the name: ");
  136.             string name = Console.ReadLine();
  137.             Console.Write("Enter the qualification: ");
  138.             string qualification = Console.ReadLine();
  139.             Console.Write("Enter the age: ");
  140.             int age = int.Parse(Console.ReadLine());
  141.             Console.Write("Enter the Department: ");
  142.             string department = Console.ReadLine();
  143.             Teacher teacher1 = new Teacher(name, qualification, age, department);
  144.             PrintTeacherInformation(teacher1.Name, teacher1.Qualiffication, teacher1.Age, teacher1.Department);
  145.         }
  146.         static void PrintTeacherInformation(string name, string qualification, int age, string department)
  147.         {
  148.             Console.WriteLine("Name: {0}, Qualification: {1}, Age: {2}, Department: {3}", name, qualification, age, department);
  149.         }
  150.  
  151.         //Group of Methods for Program
  152.         static void GetProgramInformation()
  153.         {
  154.             try
  155.             {
  156.             Console.Write("Enter the name: ");
  157.             string name = Console.ReadLine();
  158.             Console.Write("Enter the Start Date (DD/MM/YYYY): ");
  159.             DateTime start = Convert.ToDateTime(Console.ReadLine());
  160.             Console.Write("Enter the End Date (DD/MM/YYYY): ");
  161.             DateTime end = Convert.ToDateTime(Console.ReadLine());
  162.             Console.Write("Enter the number of Free Places: ");
  163.             int freePlaces = int.Parse(Console.ReadLine());
  164.             ProgramInf programInf1 = new ProgramInf(name, start, end, freePlaces);
  165.             PrintProgramInformation(programInf1.Name, programInf1.StartDate, programInf1.EndDate, programInf1.FreePlaces);
  166.             }
  167.             catch (System.FormatException e)
  168.             {
  169.                 Console.WriteLine("Please input the Start and End dates in the valid format!!!");
  170.             }
  171.         }
  172.         static void PrintProgramInformation(string name, DateTime start, DateTime end, int free)
  173.         {
  174.             Console.WriteLine("Name: {0}, Start: {1}, End: {2}, Free Places: {3}", name, start.ToString(), end.ToString(), free.ToString());
  175.         }
  176.  
  177.         //The Group of Methods for Course
  178.         static void GetCourseInformation()
  179.         {
  180.             Console.Write("Enter the name: ");
  181.             string name = Console.ReadLine();
  182.             Console.Write("Enter the professor: ");
  183.             string professor = Console.ReadLine();
  184.             Console.Write("Enter the department: ");
  185.             string department = Console.ReadLine();
  186.             Console.Write("Enter the number of credits: ");
  187.             int credits = int.Parse(Console.ReadLine());
  188.             Console.Write("Enter the semester, the program is offered: ");
  189.             string semester = Console.ReadLine();
  190.             Course course1 = new Course(name, professor, department, credits, semester);
  191.             PrintCourseInformation(course1.Name, course1.Professor, course1.Department, course1.Credits, course1.Semester);
  192.         }
  193.         static void PrintCourseInformation(string name, string professor, string department, int credits, string semester)
  194.         {
  195.             Console.WriteLine("Name: {0}, Professor: {1}, Department: {2}, Number of Credits it is evaluated: {3}, Semester it is offered: {4}", name, professor, department, credits.ToString(), semester);
  196.         }
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment