Student Management System Project in C++

Dear Students, Today in C++ Programming Tutorial we will learn How to make a Student Management System Project in C++. Previously we shared Simple School Management C++ Project. It is a simple c++ project for beginners. To keep the project simple only basic functionalities has been added it is recommended for students first understand the project flow then add more functions like edit record (hint code also has given below) etc. Students are recommended to first add validation in this project which will not allow user to enter wrong option and then add more functions.
Students Management System Project in C++
Students Management System Project in C++

Concepts used in C++ Project

This Project includes the concept of following topics:
  • struct 
  • Filing 
  • Loops
  • Arrays
  • If else
  • Switch statement
  • String class functions
Project has for major functions in menu
  • Insert record
  • Show all record
  • Search record
  • Exit program

How it works

Each functionality has a function call in switch statement on the user choice control transfers to a function. Every function opens a file name "database" and insert, show and search data from it. File will be created where c++ file is placed in secondary storage.

Watch Student Management System Project Tutorial



School Management System Project Source Code

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>

struct student
{
 char name[20];
 char reg[15];
 char course[10];
 float cgpa;
};

fstream file;
student obj;

void add()
{
 cout<<"Enter Name: ";
 cin>>obj.name;
 cout<<"Enter Registration Number: ";
 cin>>obj.reg;
 cout<<"Enter Course: ";
 cin>>obj.course;
 cout<<"Enter CGPA: ";
 cin>>obj.cgpa;

 file.open("database.txt",ios::app) ;
 file.write((char*)&obj,sizeof(obj));
 file.close();
}

void show_all()
{     //  clrscr();
 file.open("database.txt",ios::in);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  cout<<"Name: "<<obj.name<<endl;
  cout<<"Registration Number: "<<obj.reg<<endl;
  cout<<"Course: "<<obj.course<<endl;
  cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}

void search()
{      // clrscr();
 float user;
 cout<<"Enter CGPA: ";
 cin>>user;
 file.open("database.txt",ios::in);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (obj.cgpa==user)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}

void edit()
{     //  clrscr();

 char user[15];
 cout<<"Enter registration Number: ";
 cin>>user;

 file.open("database.txt",ios::in|ios::out);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (strcmp(obj.reg,user)==0)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

   cout<<"\nEnter New course: ";
   cin>>obj.course;

   file.seekp(file.tellg()-sizeof(obj));
   file.write((char*)&obj,sizeof(obj));
   cout<<"\n\nFile Updated";
   break;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}


void main()
{
// clrscr();

 //file.open("c:\database.txt",ios::out);
 //file.close();
 int option;

 while(1)
 {
 // clrscr();
  cout<<"Enter 1 to Enter Record\n";
  cout<<"Enter 2 to Show All Record\n";
  cout<<"Enter 3 to Search Record\n";
  cout<<"Enter 4 to Exit\n";
  cout<<"\n\nEnter Option: ";
  cin>>option;

  switch (option)
  {
   case 1:
    add();
    cout<<"\n\nRecord Entered\n";
    getch();
    break;
   case 2:
    show_all();
    break;
   case 3:
    search();
    break;
   case 4:
    exit(0);
  }
 }
 getch();
}

School Management System Project Output

School Management System Project Output
School Management System Project Output
Source code has been tested on Microsoft Visual C++ compiler. If you are running on a different compiler like codeBlocks. Some changes may required like add using namespace std; , remover .h from iostream etc.

Reference edit functionality c++ source code

void edit()
{     //  clrscr();

 char user[15];
 cout<<"Enter registration Number: ";
 cin>>user;

 file.open("database.txt",ios::in|ios::out);
 file.read((char*)&obj,sizeof(obj));

 while (file.eof()==0)
 {
  if (strcmp(obj.reg,user)==0)
  {
   cout<<"Name: "<<obj.name<<endl;
   cout<<"Registration Number: "<<obj.reg<<endl;
   cout<<"Course: "<<obj.course<<endl;
   cout<<"CGPA: "<<obj.cgpa<<endl<<endl;

   cout<<"\nEnter New course: ";
   cin>>obj.course;

   file.seekp(file.tellg()-sizeof(obj));
   file.write((char*)&obj,sizeof(obj));
   cout<<"\n\nFile Updated";
   break;
  }

  file.read((char*)&obj,sizeof(obj));
 }
 file.close();

 getch();
}

MORE C++ EXAMPLE PROGRAMS:



If this was Helpful Please share with your friends. Thanks


Post a Comment

  1. Im using microsoft blend for visual studio. The code worked fine until I reached void edit()... At the line... file.seekp(file.tellg(),-sizeof(obj));...I recieve an error saying..."unary minus operator applied to unasigned type. How do I fix that???

    ReplyDelete

 

Top