Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PF Lab Project

Enrollment System

#include <iostream>

#include <string>

using namespace std;

const int MAX_STUDENTS = 100;

struct Student {

string name;

int age;

string course;

};

void inputStudent(Student students[], int& studentCount) {

if (studentCount < MAX_STUDENTS) {

cout << "Enter student name: ";

cin >> students[studentCount].name;


cout << "Enter student age: ";

cin >> students[studentCount].age;

cout << "Enter enrolled course: ";

cin >> students[studentCount].course;

studentCount++;

} else {

cout << "Maximum student limit reached!" << endl;

void displayStudents(Student students[], int studentCount) {

cout << "\nDisplaying student details:" << endl;

for (int i = 0; i < studentCount; i++) {

cout << "\nStudent " << i + 1 << " details:" << endl;

cout << "Student name: " << students[i].name << endl;

cout << "Student age: " << students[i].age << endl;

cout << "Enrolled course: " << students[i].course << endl;

int main() {
Student students[MAX_STUDENTS];

int studentCount = 0;

char choice;

do {

cout << "\nStudent Enrollment System" << endl;

cout << "1. Add Student\n2. Display Students\n3. Exit" << endl;

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case '1':

inputStudent(students, studentCount);

break;

case '2':

displayStudents(students, studentCount);

break;

case '3':

cout << "\nExi ng the program." << endl;

break;
default:

cout << "\nInvalid choice. Please enter a valid op on." << endl;

break;

} while (choice != '3');

return 0;

Library Inclusion: The code starts by including necessary header files. iostream is
used for input and output, and string is used for working with strings.

Constants: const int MAX_STUDENTS = 100; defines the maximum number of


students that can be enrolled.

Student Structure: The struct Student defines the structure for student data. It
includes three fields: name, age, and course.

Input Func on: inputStudent func on takes an array of Student and the current
student count by reference. If the student count is less than the maximum limit, it
prompts the user to enter student details using cin.
Display Func on: displayStudents func on takes an array of Student and the
student count. It displays the details of each student using a loop.

Main Func on: The main func on is where the program execu on starts. It
declares an array of Student named students and an integer studentCount to keep
track of the number of enrolled students.

Menu and User Interac on: Inside the do-while loop, the program displays a
menu of op ons: adding a student, displaying student details, and exi ng the
program. The user's choice is read using cin.

Switch Statement: Based on the user's choice, the program enters different cases:

Case 1: Calls the inputStudent func on to input a new student's details.

Case 2: Calls the displayStudents func on to display all enrolled students' details.

Case 3: Exits the program.

Loop Termina on: The loop con nues un l the user chooses to exit (choice 3).

Return Statement: The main func on ends by returning 0, indica ng successful


execu on.

Remember, this code is kept simple for beginner understanding and might not
handle all possible edge cases or inputs. During your viva, be prepared to explain
the purpose of the different sec ons, the use of func ons, the flow of the
program, and how user input and display of data are handled.

You might also like