Simple College Management System using C++ (With Source Code)
Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Simple College Management System using C++ (With Source Code).
What is a College Management System?
The Simple College Management System is a console based application which allows the user to manage a collection of student records in a college. This system accurately collects the college students information to add it to the records securely for further use by the administration of the college. It stores the following information of a student – Name, registration number, roll number, branch in college and etc. The system contains various functions to perform operations such as add new records, display records, remove/delete a student record, edit a record and search a student record.
In general, College Management System is a vital tool that assists colleges and universities in streamlining their operations, increasing efficiency, and improving student experiences. It provides a centralized platform for handling numerous administrative and academic responsibilities and handling student records in a convenient manner making it easier for institutions to provide student data to the administration and faculty to use it for further requirements.
Simple Clinic Management System using C++ (With Source Code)
The program for this project uses the concept of vectors to store the student records.
Overview of the UI:
- Enter <1> to Add new student
- Enter <2> to Display all student
- Enter <3> to Remove student
- Enter <4> to Edit student
- Enter <5> to Search student
- Enter <0> to Exit
The user will choose an option to proceed further to perform a function in the College Management System.
Simple College Management System Source code:
You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.
#include<iostream> #include<vector> #include<stdio.h> #include<cstring> #include<fstream> #include<algorithm> using namespace std; class student { public: long int reg; char name[80],branch[50]; void input() { cout<<"\n Enter name: "; gets(name); cout<<"\n Enter roll no: "; cin>>reg; fflush(stdin); cout<<"\n Enter Branch: "; gets(branch); } void display() { system("CLS"); cout<<"\t\tDisplay Records"; cout<<"\n"; cout<<"\n Name - "<<name; cout<<"\n Reg no. - "<<reg; cout<<"\n Branch - "<<branch; cout<<"\n"; system("PAUSE"); system("CLS"); } bool operator == (student a) { if(reg==a.reg) return true; else return false; } }; vector <student>v; int search_reg(long int reg,int &i); void get_file() { student x; int i=0; fstream f; f.open("College.txt",ios::in); if(f) { f.read((char *) &x,sizeof(class student)); while(!f.eof()) { v.push_back(x); f.read((char *) &x,sizeof(class student)); } } else ; f.close(); } void bubblesort() { int i,j; student x; for(i=0;i<v.size();i++) for(j=0;j<v.size()-i-1;j++) if(v[j].reg>v[j+1].reg) { x=v[j]; v[j]=v[j+1]; v[j+1]=x; } } void insert_new() { char ch='y'; int ta; while(ch=='y') { fflush(stdin); student x; x.input(); if(search_reg(x.reg,ta)==0) v.push_back(x); else cout<<"\nTHE REGISTRATION NO. ALREADY EXIST!!!\nCANNOT ADD"; cout<<"\n Press [Y] to enter more: "; cin>>ch; fflush(stdin); } } void write_file() { bubblesort(); fstream f; f.open("College.txt",ios::out); for(int i=0;i<v.size();i++) { student x=v[i]; f.write((char *) &x,sizeof(class student)); } f.close(); } int search_reg(long int reg,int &i) { int ta=0; for(i=0;i<v.size();i++) if(v[i].reg==reg) { ta=1; break; } return ta; } int search_name(char name[],vector<int> &vi) { int i,ta=0; for(i=0;i<v.size();i++) if(strcmp(v[i].name,name)==0) { ta=1; vi.push_back(i); } return ta; } int search_branch(char branch[],vector<int> &vj) { int i,ta=0; for(i=0;i<v.size();i++) if(strcmp(v[i].branch,branch)==0) { ta=1; vj.push_back(i); } return ta; } void search_and_show() { int ch,i,ta=0; char name[80],branch[50]; vector <int>vi; vector <int>vj; long int reg; poi: cout<<"\n1.Press to search reg no." <<"\n2.Press to search name" <<"\n3.Press to search branch"; cin>>ch; switch(ch) { case 1: cout<<"\nEnter reg no.: "; cin>>reg; if(search_reg(reg,i)==1) v[i].display(); else cout<<"\nRecord NOT FOUND!!!"; break; case 2: cout<<"\nEnter name: "; fflush(stdin); gets(name); if(search_name(name,vi)==1) { for(int j=0;j<vi.size();j++) v[vi[j]].display(); } else cout<<"\nRecord NOT FOUND!!!"; break; case 3: cout<<"\nEnter branch: "; fflush(stdin); gets(branch); if(search_branch(branch,vj)==1) { for(int j=0;j<vj.size();j++) v[vj[j]].display(); } else cout<<"\nRecord NOT FOUND!!!"; break; default: cout<<"\nWrong CHOICE!!!"; goto poi; } } void show() { int i; for(i=0;i<v.size();i++) v[i].display(); } void delete_data() { int i,j; long int reg; vector <student>::iterator p=v.begin(); cout<<"\nEnter Reg. no.: "; cin>>reg; if(search_reg(reg,i)==1) { student x=v[i]; cout<<"\nThe following data is being deleted"; x.display(); p+=i; v.erase(p,p+1); } } void edit_data() { int i,j; long int reg; vector <student>vi; cout<<"\nEnter Reg. no.: "; cin>>reg; if(search_reg(reg,i)==1) { cout<<"\nEnter new data:"; fflush(stdin); v[i].input(); } } int main() { int i=1; get_file(); while(i) { system("CLS"); cout<<"\t\t\t-----------------------------------------\n"; cout<<"\t\t\t Simple College Management System\n"; cout<<"\t\t\t-----------------------------------------\n"; cout<<"\n\t\t\tEnter <1> to Add new student" <<"\n\t\t\tEnter <2> to Display all student" <<"\n\t\t\tEnter <3> to Remove student" <<"\n\t\t\tEnter <4> to Edit student" <<"\n\t\t\tEnter <5> to Search student" <<"\n\t\t\tEnter <0> to Exit\n"; cout<<"\n\n\t\t\tEnter Your Choice:"; cin>>i; switch(i) { case 1 : insert_new(); break; case 2 : show(); break; case 3 : delete_data(); break; case 4 : edit_data(); break; case 5 : search_and_show(); break; case 0 : write_file(); break; default : cout<<"\nWRONG CHOICE!!!\nTRY AGAIN"; } } return 0; }
Now let us understand the code:-
- We will start by writing the header of the code with the required libraries – iostream, vector, stdio.h, cstring, fstream, and algorithm.
- Now we will define a class called student which will have three member variables -req (registration number), name (name of the student) and branch(branch of the student)and the member functions- input() and display() to input and display the student details respectively. The == operatoroverloading function is used to compare two student objects based on their registration numbers.
- We will create a vector v of student objects to store the student records.
- For the functionality of the program, we will declare the following functions:-
- The get_file() function uses an if-else statement with a while loop to read the student records from a file named “College.txt” and then store them in the vector v.
- The bubblesort() function uses a nested for loop and an if statement to sort the student records in ascending order of their registration numbers using the bubble sort algorithm.
- The insert_new() function uses a while loop with an if – else control statement to allow the user to add a new student record to the vector v.
- The write_file() function uses a for loop to save the student records in the vector v to the file named “College.txt”.
- The search_reg(long int reg,int &i) function uses a for loop and an if control statement to search the vector v for a student record based on the registration number and returns the index of the record if found.
- The search_name(char name[],vector<int> &vi) function uses a for loop and an if control statement to search the vector v for student records based on the name and returns a vector of indices of the matching records.
- The search_branch(char branch[],vector<int> &vj) function uses a for loop and an if control statement to search the vector v for student records by the branch and then return a vector of indices of the matching records.
- The search_and_show() function uses a switch case to select between the options to search for a record either by registration number, name or branch of a student. It then displays the matching records.
- The show() function displays uses a for loop to show all the student records in the vector v.
- The delete_data() function uses an if control statement and allow the user to delete a student record from the vector v.
- The edit_data() function uses an if control statement and will allow the user to edit a student record in the vector v.
- The main() function will display a list of options to the user to choose the operation they want to perform. It uses switch case statements to select between the options for the corresponding function calls.
- This sums up our project of College Management System using C++.
Bakery Management System using C++ (With Source Code)
Final Output:-
Here is an example to show how this project works
Video Output:
Conclusion
We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.
Chess Game Using C++ (With Source Code)
If you enjoyed the article and learned something new today, let us know in the comments.
Thank you.
Happy Reading! 🙂
Follow: CodewithRandom