OOP ASSIGNMENT NO 1
NAME:   Areeb Khan.
Reg no: 4994-FOC/BSCS/F23 (B)
Teacher: Sir Muzamil Shah.
Q: Simple student DB using struct.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define MaxStudent 50
struct stud {
    string name, fname;
    int id;
    float cgpa;
    char grades;
};
void   fillInfo(stud& student, int studentNumber);
void   input_student(stud[], int& count);
void   add_student(stud[], int& count);
void   display(stud student[], int& count);
void   showGrade(stud student[], int& count);
void fillInfo(stud& student, int studentNumber) {
    cout << "Enter details for Student " << studentNumber << ":" << endl;
       cout << "Enter student name: ";
       cin >> student.name;
       cout << "Enter father name: ";
       cin >> student.fname;
       cout << "Enter roll no: ";
       cin >> student.id;
    cout << "Enter CGPA: ";
    cin >> student.cgpa;
    cout << "Enter grades (A, B, C, D, F): ";
    cin >> student.grades;
}
void input_student(stud student[], int& count) {
    do {
         cout << "Enter number of students (MAX " << MaxStudent << "): ";
         cin >> count;
         if (count < 1 || count > MaxStudent) {
             cout << "INVALID!!!" << endl;
         }
    } while (count < 1 || count > MaxStudent);
    for (int i = 0; i < count; i++) {
        fillInfo(student[i], i + 1);
    }
}
void add_student(stud student[], int& count) {
    if (count < MaxStudent) {
        cout << "Enter details of the new student: ";
        fillInfo(student[count], count + 1);
        count++;
    } else {
        cout << "No more space to add new student" << endl;
    }
}
void display(stud student[], int& count) {
    if (count == 0) {
        cout << "No student to display." << endl;
    } else {
        for (int i = 0; i < count; i++) {
             cout << "\n------- STUDENT " << (i + 1) << " DETAILS -------" << endl;
             cout << "Name: " << student[i].name << endl;
             cout << "Father's Name: " << student[i].fname << endl;
             cout << "ID: " << student[i].id << endl;
             cout << "CGPA: " << student[i].cgpa << endl;
             cout << "Grade: " << student[i].grades << endl;
        }
    }
}
void showGrade(stud student[], int& count) {
    if (count == 0) {
        cout << "No student to display." << endl;
    } else {
        for (int i = 0; i < count; i++) {
             cout << "Student name is " << student[i].name << " and his CGPA is " <<
student[i].cgpa << endl;
        }
    }
}
int main() {
    stud student[MaxStudent];
    int count = 0;
    int choice;
    do {
        cout << setw(50) <<   "****************** MENU ******************"   <<   endl;
        cout << setw(50) <<   "* 1. Create student record               *"   <<   endl;
        cout << setw(50) <<   "* 2. Add a record                        *"   <<   endl;
        cout << setw(50) <<   "* 3. Show grades                         *"   <<   endl;
        cout << setw(50) <<   "* 4. Display Data                        *"   <<   endl;
        cout << setw(50) <<   "* 5. Exit                                *"   <<   endl;
        cout << setw(50) <<   "******************************************"   <<   endl;
        cout << "Enter your   choice: ";
        cin >> choice;
        switch (choice) {
            case 1:
                input_student(student, count);
                break;
            case 2:
                add_student(student, count);
                break;
            case 3:
                showGrade(student, count);
                break;
            case 4:
                display(student, count);
                break;
            case 5:
                cout << "Exiting..." << endl;
                break;
            default:
                cout << "INVALID INPUT!" << endl;
                break;
        }
    } while (choice != 5);
    return 0;
}