Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StudentRecordSystem
- {
- private string[] studentNames;
- private int[] studentAges;
- private string[] deptNames;
- private int totalStudents;
- private const int MAX_STUDENTS = 100; // Maximum number of students
- public StudentRecordSystem()
- {
- studentNames = new string[MAX_STUDENTS];
- studentAges = new int[MAX_STUDENTS];
- deptNames = new string[MAX_STUDENTS];
- totalStudents = 0;
- }
- public void AddStudent(string name, int age, string gradeLevel)
- {
- if (totalStudents < MAX_STUDENTS)
- {
- studentNames[totalStudents] = name;
- studentAges[totalStudents] = age;
- deptNames[totalStudents] = gradeLevel;
- totalStudents++;
- Console.WriteLine("Student added successfully.");
- }
- else
- {
- Console.WriteLine("Maximum number of students reached.");
- }
- }
- public void UpdateStudent(string name, int age, string gradeLevel)
- {
- int index = FindStudentIndex(name);
- if (index != -1)
- {
- studentAges[index] = age;
- deptNames[index] = gradeLevel;
- Console.WriteLine("Student record updated successfully.");
- }
- else
- {
- Console.WriteLine("Student not found.");
- }
- }
- public void DeleteStudent(string name)
- {
- int index = FindStudentIndex(name);
- if (index != -1)
- {
- for (int i = index; i < totalStudents - 1; i++)
- {
- studentNames[i] = studentNames[i + 1];
- studentAges[i] = studentAges[i + 1];
- deptNames[i] = deptNames[i + 1];
- }
- totalStudents--;
- Console.WriteLine("Student record deleted successfully.");
- }
- else
- {
- Console.WriteLine("Student not found.");
- }
- }
- public void SearchStudent(string name)
- {
- int index = FindStudentIndex(name);
- if (index != -1)
- {
- Console.WriteLine("Name: {studentNames[index]}, Age: {studentAges[index]}, Grade Level: {studentGradeLevels[index]}");
- }
- else
- {
- Console.WriteLine("Student not found.");
- }
- }
- public string GetAllStudentsInfo()
- {
- if (totalStudents == 0)
- {
- return "No students found.";
- }
- string allStudentsInfo = "";
- for (int i = 0; i < totalStudents; i++)
- {
- allStudentsInfo += "Name:" + studentNames[i] + ", Age: " + studentAges[i] + ", department name: " + deptNames[i] + "\n";
- }
- return allStudentsInfo;
- }
- private int FindStudentIndex(string name)
- {
- for (int i = 0; i < totalStudents; i++)
- {
- if (studentNames[i] == name)
- {
- return i;
- }
- }
- return -1; // Student not found
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- StudentRecordSystem recordSystem = new StudentRecordSystem();
- char choice;
- do
- {
- Console.WriteLine("\nMenu:");
- Console.WriteLine("1. Add Student");
- Console.WriteLine("2. Update Student");
- Console.WriteLine("3. Delete Student");
- Console.WriteLine("4. Search Student");
- Console.WriteLine("5. Display All Students");
- Console.WriteLine("6. Exit");
- Console.Write("Enter your choice: ");
- choice = Console.ReadKey().KeyChar;
- Console.WriteLine();
- switch (choice)
- {
- case '1':
- Console.Write("Enter name: ");
- string name = Console.ReadLine();
- Console.Write("Enter age: ");
- int age = int.Parse(Console.ReadLine());
- Console.Write("Enter Department name: ");
- string gradeLevel = Console.ReadLine();
- recordSystem.AddStudent(name, age, gradeLevel);
- break;
- case '2':
- Console.Write("Enter name of student to update: ");
- string nameUpdate = Console.ReadLine();
- Console.Write("Enter age: ");
- int ageUpdate = int.Parse(Console.ReadLine());
- Console.Write("Enter Department name: ");
- string gradeLevelUpdate = Console.ReadLine();
- recordSystem.UpdateStudent(nameUpdate, ageUpdate, gradeLevelUpdate);
- break;
- case '3':
- Console.Write("Enter name of student to delete: ");
- string nameDelete = Console.ReadLine();
- recordSystem.DeleteStudent(nameDelete);
- break;
- case '4':
- Console.Write("Enter name of student to search: ");
- string searchName = Console.ReadLine();
- recordSystem.SearchStudent(searchName);
- break;
- case '5':
- Console.WriteLine("All Students:");
- Console.WriteLine(recordSystem.GetAllStudentsInfo());
- break;
- case '6':
- Console.WriteLine("Exiting...");
- break;
- default:
- Console.WriteLine("Invalid choice. Please enter a valid option.");
- break;
- }
- } while (choice != '6');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement