stefan1919

EdExC# Assignment Complex Data Structures + Challenge

Oct 31st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.72 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[5];
  116.                 studentArray[0] = student1;
  117.                 for (int i = 1; i < studentArray.Length; i++)
  118.                 {
  119.                     Console.Write("Enter the name: ");
  120.                     string name1 = Console.ReadLine();
  121.                     Console.Write("Enter the degree: ");
  122.                     string degreeStudent1 = Console.ReadLine();
  123.                     Console.Write("Enter the age: ");
  124.                     string age1 = Console.ReadLine();
  125.                     Console.Write("Enter the GPA: ");
  126.                     double gpa1 = double.Parse(Console.ReadLine());
  127.                     Student studentX = new Student(name1, degreeStudent1, age1, gpa1);
  128.                     studentArray[i] = studentX;
  129.                 }
  130.                 foreach (var student in studentArray)
  131.                 {
  132.                 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);
  133.                 Console.WriteLine("-------------------------------------------------------------------------");
  134.                 }
  135.             }
  136.             else
  137.             {
  138.                 PrintStudentInformation(student1.Name, student1.CurrentDegree, student1.Age, student1.Gpa);
  139.             }
  140.         }
  141.         static void PrintStudentInformation(string name, string degree, string age, double gpa)
  142.         {
  143.             Console.WriteLine("{0} is persuading a degree in {1} and is {2} years-old. Current GPA: {3}", name, degree, age, gpa);
  144.         }
  145.  
  146.         //Group of methods for teacher
  147.         static void TeacherInformation()
  148.         {
  149.             Console.Write("Enter the name: ");
  150.             string name = Console.ReadLine();
  151.             Console.Write("Enter the qualification: ");
  152.             string qualification = Console.ReadLine();
  153.             Console.Write("Enter the age: ");
  154.             int age = int.Parse(Console.ReadLine());
  155.             Console.Write("Enter the Department: ");
  156.             string department = Console.ReadLine();
  157.             Teacher teacher1 = new Teacher(name, qualification, age, department);
  158.             PrintTeacherInformation(teacher1.Name, teacher1.Qualiffication, teacher1.Age, teacher1.Department);
  159.         }
  160.         static void PrintTeacherInformation(string name, string qualification, int age, string department)
  161.         {
  162.             Console.WriteLine("Name: {0}, Qualification: {1}, Age: {2}, Department: {3}", name, qualification, age, department);
  163.         }
  164.  
  165.         //Group of Methods for Program
  166.         static void GetProgramInformation()
  167.         {
  168.             try
  169.             {
  170.             Console.Write("Enter the name: ");
  171.             string name = Console.ReadLine();
  172.             Console.Write("Enter the Start Date (DD/MM/YYYY): ");
  173.             DateTime start = Convert.ToDateTime(Console.ReadLine());
  174.             Console.Write("Enter the End Date (DD/MM/YYYY): ");
  175.             DateTime end = Convert.ToDateTime(Console.ReadLine());
  176.             Console.Write("Enter the number of Free Places: ");
  177.             int freePlaces = int.Parse(Console.ReadLine());
  178.             ProgramInf programInf1 = new ProgramInf(name, start, end, freePlaces);
  179.             PrintProgramInformation(programInf1.Name, programInf1.StartDate, programInf1.EndDate, programInf1.FreePlaces);
  180.             }
  181.             catch (System.FormatException e)
  182.             {
  183.                 Console.WriteLine("Please input the Start and End dates in the valid format!!!");
  184.             }
  185.         }
  186.         static void PrintProgramInformation(string name, DateTime start, DateTime end, int free)
  187.         {
  188.             Console.WriteLine("Name: {0}, Start: {1}, End: {2}, Free Places: {3}", name, start.ToString(), end.ToString(), free.ToString());
  189.         }
  190.  
  191.         //The Group of Methods for Course
  192.         static void GetCourseInformation()
  193.         {
  194.             Console.Write("Enter the name: ");
  195.             string name = Console.ReadLine();
  196.             Console.Write("Enter the professor: ");
  197.             string professor = Console.ReadLine();
  198.             Console.Write("Enter the department: ");
  199.             string department = Console.ReadLine();
  200.             Console.Write("Enter the number of credits: ");
  201.             int credits = int.Parse(Console.ReadLine());
  202.             Console.Write("Enter the semester, the program is offered: ");
  203.             string semester = Console.ReadLine();
  204.             Course course1 = new Course(name, professor, department, credits, semester);
  205.             PrintCourseInformation(course1.Name, course1.Professor, course1.Department, course1.Credits, course1.Semester);
  206.         }
  207.         static void PrintCourseInformation(string name, string professor, string department, int credits, string semester)
  208.         {
  209.             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);
  210.         }
  211.     }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment