#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int MAX_ENROLLMENTS=5;
struct Course{
string courseID;
int enrolDate;
int fine;
};
struct Student{
string stName;
string stID;
string stContact;
int enrollmentCount = 0;
Course enrollCourse[MAX_ENROLLMENTS];
};
//functions prototypes
void displayMenu();
void addStudent(Student Detail[], int&stCount);
void displayDetails(Student Detail[], int stCount);
void enrollInCourse(Student Detail[], int studentCount);
void displayenrollments(Student Detail[], int stCount);
void displayfines(Student Detail[], int stCount);
void displayoptionstoload(Student Detail[], int&stCount);
void displayoptionstosave(Student Detail[], int stCount);
void addStudentfromfile(Student Detail[], int&stCount);
void enrollInCoursefromfile(Student Detail[], int studentCount);
void displayDetailsinFile(Student Detail[], int stCount);
void displayenrollmentsinFile(Student Detail[], int stCount);
void displayfinesinFile(Student Detail[], int stCount);
void instructions();
int main(){
cout<< "\t\t============Welcome to The Admin Portal============"<<endl;
int MAX_STUDENTS;
int LastDate,LastMonth,LastYear;
int choice;
cout<< "\nMaximum Students = ";
cin>>MAX_STUDENTS;
Student stDetail[MAX_STUDENTS];
int studentCount = 0;
do{
displayMenu();
cout << "Enter your choice: ";
cin >> choice;
if(cin){
if(choice==1){
addStudent(stDetail, studentCount);
}else if(choice==2){
displayDetails(stDetail, studentCount);
}else if(choice==3){
enrollInCourse(stDetail, studentCount);
}else if(choice==4){
displayenrollments(stDetail, studentCount);
}else if(choice==5){
displayfines(stDetail, studentCount);
}else if(choice==6){
instructions();
}else if(choice==7){
displayoptionstoload(stDetail, studentCount);
}else if(choice==8){
displayoptionstosave(stDetail, studentCount);
}else if(choice==9){
cout<< "\n\t\t\t========THANKS FOR USING PORTAL========"<<endl;
}else{
cout<< "Invalid Choice"<<endl;
}
}else{
cin.clear();
cin.ignore();
cout<< "Invalid DataType"<<endl;
}
}while(choice!=9);
return 0;
}
//display function
void displayMenu(){
cout<< "\n\t=============== Student Registration System Menu ===============\n\n";
cout<<left<<setw(50)<< "1 => Add new student"<<left<<setw(50)<< "2 => Display all students"<<endl;
cout<<left<<setw(50)<< "3 => Enroll in a course" <<left<<setw(50)<< "4 => Display all enrollments"<<endl;
cout<<left<<setw(50)<< "5 => Display all fines" <<left<<setw(50)<<"6 => Instructions"<<endl;
cout<<left<<setw(50)<< "7 => Load data from file" <<left<<setw(50)<< "8 => Save data to file"<<endl;
cout<<left<<setw(50)<< "9 => Exit"<<endl;
}
void addStudent(Student Detail[], int&stCount){
string name,id,contact;
bool duplicate=false;
cout<< "\n\t\t=============== Register New Student ===============\n\n";
cout<<"Enter Student Name = ";
cin.ignore();
getline(cin,name);
cout<< "Enter Student ID = ";
getline(cin,id);
cout<< "Enter Student Contact INFO = ";
getline(cin,contact);
for (int i = 0; i < stCount; ++i) {
if (Detail[i].stID == id) {
cout<< "THIS STUDENT IS ALREADY PRESENT IN DTATABASE!!!"<<endl;
duplicate=true;
break;
}
}
if(duplicate==0){
Detail[stCount].stName= name;
Detail[stCount].stID= id;
Detail[stCount].stContact= contact;
stCount++;
cout<< "New Student is Enrolled SUCCESSFULY"<<endl;
}
}
void displayDetails(Student Detail[], int stCount){
cout<< "\n\t\t=============== Already Registered Students ===============\n\n";
if (stCount == 0) {
cout << "No students registered yet.\n";
}else{
cout<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Name"<<setw(20)<<"Student ID"<<setw(25)<<"Student Contact"<<endl;
for(int i=0 ; i<stCount;i++){
cout<<left<<setw(10)<<i+1<<setw(20)<<Detail[i].stName<<setw(20)<<Detail[i].stID<<setw(25)<<Detail[i].stContact<<endl;
}
}
}
void enrollInCourse(Student Detail[], int studentCount) {
string studentID;
string courseID;
cout << "Enter student ID: ";
cin >> studentID;
// Validate student ID
int studentIndex = -1;
for (int i = 0; i < studentCount; ++i) {
if (Detail[i].stID == studentID) {
studentIndex = i;
break;
}
}
if (studentIndex == -1) {
cout << "Student not found. Please register the student first.\n";
return;
}
if(Detail[studentIndex].enrollmentCount>=5){
cout << "Maximum no. of courses Enrolled of that Student"<<endl;
return;
}
cout << "Enter course ID: ";
cin >> courseID;
int j= Detail[studentIndex].enrollmentCount;
// Validate course ID
int d,m,y;
cout << "Enter Enrollment Date (DD MM YYYY): ";
cin >> d>>m>>y;
if((d>0&&d<=31)&&(m==01||m==1)&&(y==2024)){
// Get current date and time
Detail[studentIndex].enrollCourse[j].enrolDate=d;
// Enroll the student in the course
Detail[studentIndex].enrollCourse[j].courseID = courseID;
cout << "Enrollment successful.\n";
// Increment enrollment count
Detail[studentIndex].enrollmentCount++;
//fine calculate
if(d>0&&d<11){
Detail[studentIndex].enrollCourse[j].fine=0;
}else{
int daysfine=d-10;
Detail[studentIndex].enrollCourse[j].fine=500*daysfine;
}
}else{
cout<< "Invalid Date"<<endl;
}
}
void displayenrollments(Student Detail[], int stCount){
cout<< "\n\t\t=============== Already Registered Courses ===============\n\n";
if (stCount == 0) {
cout << "No students registered yet.\n";
}else{
cout<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Name"<<setw(20)<<"Student ID"<<setw(25)<<"Student Courses"<<setw(20)<<"Enrollment Date"<<endl;
for(int i=0 ; i<stCount;i++){
cout<<left<<setw(10)<<i+1<<setw(20)<<Detail[i].stName<<setw(20)<<Detail[i].stID;
if(Detail[i].enrollmentCount>=1){
for(int j=0; j<Detail[i].enrollmentCount; j++){
if(j==0){
cout<<setw(25)<< Detail[i].enrollCourse[j].courseID<< Detail[i].enrollCourse[j].enrolDate<<"/01/2024" <<endl;
}else{
cout<<setw(50)<<" "<<setw(25)<< Detail[i].enrollCourse[j].courseID << Detail[i].enrollCourse[j].enrolDate<<"/01/2024" <<endl;
}
}
cout<<endl;
}else{
cout<< setw(25)<<"No Course Registered"<<endl;
}
}
}
}
void displayfines(Student Detail[], int stCount){
cout<< "\n\t\t=============== Student Fine List ===============\n\n";
if (stCount == 0) {
cout << "No students registered yet.\n";
}else{
cout<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Names"<<setw(20)<<"Student IDs"<<setw(25)<<"No. of Courses"<<setw(20)<<"Fines"<<endl;
for(int i=0 ; i<stCount;i++){
int sum=0;
cout<<left<<setw(10)<<i+1<<setw(20)<<Detail[i].stName<<setw(20)<<Detail[i].stID;
if(Detail[i].enrollmentCount>=1){
for(int j=0; j<Detail[i].enrollmentCount; j++){
sum+=Detail[i].enrollCourse[j].fine;
}
cout<<setw(25)<< Detail[i].enrollmentCount<< sum<<endl;
}else{
cout<< setw(25)<<"No Course Registered"<<endl;
}
}
}
}
void displayoptionstosave(Student Detail[], int stCount){
cout<< "\n\t=============== Student Registration System Menu ===============\n\n";
cout<<left<<setw(50)<< "1 => Display all students"<<endl;
cout<<left<<setw(50)<< "2 => Display all enrollments"<<endl;
cout<<left<<setw(50)<< "3 => Display all fines"<<endl;
cout<<left<<setw(50)<< "4 => Exit"<<endl;
cout << "Enter your choice : ";
char choice;
cin>>choice;
switch(choice){
case '1':
displayDetailsinFile(Detail, stCount);
break;
case '2':
displayenrollmentsinFile(Detail, stCount);
break;
case '3':
displayfinesinFile(Detail, stCount);
break;
case '4':
break;
default:
cout<<"invalid choice";
}
}
void displayoptionstoload(Student Detail[], int&stCount){
cout<< "\n\t=============== Student Registration System Menu ===============\n\n";
cout<<left<<setw(50)<< "1 => Load students Data from f\File"<<endl;
cout<<left<<setw(50)<< "2 => Load enrollments Data from File"<<endl;
cout<<left<<setw(50)<< "3 => Exit"<<endl;
cout << "Enter your choice : ";
char choice;
cin>>choice;
switch(choice){
case '1':
addStudentfromfile(Detail, stCount);
break;
case '2':
enrollInCoursefromfile(Detail, stCount);
break;
case '3':
break;
default:
cout<<"invalid choice";
}
}
void addStudentfromfile(Student Detail[], int&stCount){
string name,id,contact;
ifstream inFile;
inFile.open("StudentData.txt");
if (!inFile) {
cout << "No previous data found.\n";
return;
}
while(inFile>>name>>id>>contact){
Detail[stCount].stName= name;
Detail[stCount].stID= id;
Detail[stCount].stContact= contact;
stCount++;
}
cout<< "New Students is Enrolled SUCCESSFULY"<<endl;
inFile.close();
}
void enrollInCoursefromfile(Student Detail[], int studentCount) {
string studentID;
string courseID;
ifstream inFile;
inFile.open("EnrollmentCourseData.txt");
while(inFile>>studentID){
// Validate student ID
int studentIndex = -1;
for (int i = 0; i < studentCount; ++i) {
if (Detail[i].stID == studentID) {
studentIndex = i;
break;
}
}
inFile >> courseID;
int j= Detail[studentIndex].enrollmentCount;
// Validate course ID
int d,m,y;
inFile >> d>>m>>y;
if((d>0&&d<=31)&&(m==01||m==1)&&(y==2024)){
// Get current date and time
Detail[studentIndex].enrollCourse[j].enrolDate=d;
// Enroll the student in the course
Detail[studentIndex].enrollCourse[j].courseID = courseID;
// Increment enrollment count
Detail[studentIndex].enrollmentCount++;
//fine calculate
if(d>0&&d<11){
Detail[studentIndex].enrollCourse[j].fine=0;
}else{
int daysfine=d-10;
Detail[studentIndex].enrollCourse[j].fine=500*daysfine;
}
}
}
cout << "Enrollment successful.\n";
inFile.close();
}
void displayenrollmentsinFile(Student Detail[], int stCount){
ofstream outFile;
outFile.open("DisplayEnrollments.txt");
outFile<< "\n\t\t=============== Already Registered Courses ===============\n\n";
if (stCount == 0) {
outFile << "No students registered yet.\n";
}else{
outFile<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Name"<<setw(20)<<"Student ID"<<setw(25)<<"Student Courses"<<setw(20)<<"Enrollment Date"<<endl;
for(int i=0 ; i<stCount;i++){
outFile<<left<<setw(10)<<i+1<<setw(20)<<Detail[i].stName<<setw(20)<<Detail[i].stID;
if(Detail[i].enrollmentCount>=1){
for(int j=0; j<Detail[i].enrollmentCount; j++){
if(j==0){
outFile<<setw(25)<< Detail[i].enrollCourse[j].courseID<< Detail[i].enrollCourse[j].enrolDate<<"/01/2024" <<endl;
}else{
outFile<<setw(50)<<" "<<setw(25)<< Detail[i].enrollCourse[j].courseID << Detail[i].enrollCourse[j].enrolDate<<"/01/2024" <<endl;
}
}
outFile<<endl;
}else{
outFile<< setw(25)<<"No Course Registered"<<endl;
}
}
}
outFile.close();
}
void displayfinesinFile(Student Detail[], int stCount){
ofstream outFile;
outFile.open("DisplayFInes.txt");
outFile<< "\n\t\t=============== Student Fine List ===============\n\n";
if (stCount == 0) {
outFile << "No students registered yet.\n";
}else{
outFile<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Names"<<setw(20)<<"Student IDs"<<setw(25)<<"No. of Courses"<<setw(20)<<"Fines"<<endl;
for(int i=0 ; i<stCount;i++){
int sum=0;
outFile<<left<<setw(10)<<i+1<<setw(20)<<Detail[i].stName<<setw(20)<<Detail[i].stID;
if(Detail[i].enrollmentCount>=1){
for(int j=0; j<Detail[i].enrollmentCount; j++){
sum+=Detail[i].enrollCourse[j].fine;
}
outFile<<setw(25)<< Detail[i].enrollmentCount<< sum<<endl;
}else{
outFile<< setw(25)<<"No Course Registered"<<endl;
}
}
}
outFile.close();
}
void displayDetailsinFile(Student Detail[], int stCount){
ofstream outFile;
outFile.open("DisplayStdentDetails.txt");
outFile<< "\n\t\t=============== Already Registered Students ===============\n\n";
if (stCount == 0) {
outFile << "No students registered yet.\n";
}else{
outFile<<left<<setw(10)<<"sr no."<<setw(20)<<"Student Name"<<setw(20)<<"Student ID"<<setw(25)<<"Student Contact"<<endl;
for(int i=0 ; i<stCount;i++){
outFile<<left<<setw(13)<<i+1<<setw(20)<<Detail[i].stName<<setw(25)<<Detail[i].stID<<setw(25)<<Detail[i].stContact<<endl;
}
}
outFile.close();
}
void instructions(){
cout<<"\t==============Student Registration System - Instructions and Policy==============\n\n";
cout<< "HOW TO USE???\n\n1. Adding a New Student:\n\t- Choose option 1 from the main menu.\n\t- Enter the student's name, ID, and contact information.\n\t- The system checks for duplicate IDs before enrolling a new student."<<endl<<endl;
cout<< "2. Displaying All Students:\n\t- Choose option 2 from the main menu.\n\t- View a list of all currently registered students with their names, IDs, and contact information."<<endl<<endl;
cout<< "3. Enrolling in a Course:\n\t- Choose option 3 from the main menu.\n\t- Enter the student ID.\n\t - Enter the course ID, enrollment date (DD MM YYYY), and validate the date.\n\t- The system checks for maximum course enrollments (up to 5) and calculates fines if applicable."<<endl<<endl;
cout<< "4. Displaying All Enrollments:\n\t- Choose option 4 from the main menu.\n\t- View a list of all enrolled courses for each student, along with enrollment dates."<<endl<<endl;
cout<< "5. Displaying All Fines:\n\t- Choose option 5 from the main menu.\n\t- View a list of fines for each student based on their course enrollments."<<endl<<endl;
cout<< "6. Loading and Saving Data:\n\t- Choose options 7 and 8 from the main menu to load from and save data to files, respectively.\n\t- For loading, you can load both student and enrollment data from separate text files."<<endl<<endl;
cout<< "7. Exiting the Program:\n\t- Choose option 9 to exit the program."<<endl<<endl;
cout<< "\nPOLICY\n\t- The program is designed for managing student registrations, enrollments, and fines.\n\t- Respect the maximum limit of 5 enrollments per student.\n\t- Follow the specified format for input data, especially for dates (DD MM YYYY).\n\t- Be cautious to avoid duplicate student IDs during registration.\n\t- Save and load data using the provided options to maintain records.\n\t- The program calculates fines for late enrollments based on a fixed rate."<<endl<<endl;
cout<< "\nThank you for using the Student Registration System! If you have any questions or encounter issues, refer to the instructions or contact the administrator for assistance."<<endl<<endl;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter