21xrx.com
2024-11-06 05:03:33 Wednesday
登录
文章检索 我的文章 写文章
学籍管理系统C++源代码
2023-07-05 12:33:51 深夜i     --     --
学籍管理系统 C++源代码 学生信息管理 教师信息管理 数据库设计

学籍管理系统是一款可以方便管理学生信息的软件,包括学生的基本信息、学业信息、考试成绩等,能够实现对学生信息的查看、修改、添加、删除等操作。下面是学籍管理系统的C++源代码:


#include<iostream>

#include<fstream>

#include<cstring>

#include<iomanip>

#include<conio.h>

using namespace std;

class student

{

  int roll_no;

  char name[50];

  int maths,eng,science,total;

  float per;

  char grade;

  void calculate()

  {

    total=maths+eng+science;

    per=total/3.0;

    if(per>=60)

      grade='A';

    else if(per>=50&&per<60)

      grade='B';

    else if(per>=33&&per<50)

      grade='C';

    else

      grade='F';

  }

public:

  void getdata()

  {

    cout<<"\nEnter the Roll number of student: ";

    cin>>roll_no;

    cout<<"\nEnter the Name of student : ";

    cin.ignore();

    cin.getline(name,50);

    cout<<"\nEnter the marks in Maths out of 100 : ";

    cin>>maths;

    cout<<"\nEnter the marks in English out of 100 : ";

    cin>>eng;

    cout<<"\nEnter the marks in Science out of 100 : ";

    cin>>science;

    calculate();

  }

  void showdata()

  {

    cout<<"\nRoll number of student : "<<roll_no;

    cout<<"\nName of student : "<<name;

    cout<<"\nMarks in Maths : "<<maths;

    cout<<"\nMarks in English : "<<eng;

    cout<<"\nMarks in Science : "<<science;

    cout<<"\nTotal Marks : "<<total;

    cout<<"\nPercentage : "<<setprecision(2)<<per;

    cout<<"\nGrade : "<<grade;

  }

  int retrollno()

  

    return roll_no;

  

};

fstream fp;

student st;

void write_student()

{

  fp.open("student.dat",ios::binary|ios::app);

  st.getdata();

  fp.write((char*)&st,sizeof(student));

  fp.close();

  cout<<"\n\nStudent record Has Been Created ";

  getch();

}

void display_all()

{

  cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";

  fp.open("student.dat",ios::binary);

  while(fp.read((char*)&st,sizeof(student)))

  {

    st.showdata();

    cout<<"\n\n====================================\n";

  }

  fp.close();

  getch();

}

void display_sp(int n)

{

  int flag=0;

  fp.open("student.dat",ios::binary);

  while(fp.read((char*)&st,sizeof(student)))

  {

    if(st.retrollno()==n)

    {

      st.showdata();

      flag=1;

    }

  }

  fp.close();

  if(flag==0)

    cout<<"\n\nrecord not exist";

  getch();

}

void modify_student()

{

  int no,found=0;

  cout<<"\n\n\tTo Modify ";

  cout<<"\n\n\tPlease Enter The roll number of student";

  cin>>no;

  fp.open("student.dat",ios::binary|ios::in|ios::out);

  while(fp.read((char*)&st,sizeof(student))&&found==0)

  {

    if(st.retrollno()==no)

    {

      st.showdata();

      cout<<"\n\nPlease Enter The New Details of student"<<endl;

      st.getdata();

      int pos=(-1)*sizeof(st);

      fp.seekp(pos,ios::cur);

      fp.write((char*)&st,sizeof(student));

      cout<<"\n\n\t Record Updated";

      found=1;

    }

  }

  fp.close();

  if(found==0)

    cout<<"\n\n Record Not Found ";

  getch();

}

void delete_student()

{

  int no;

  cout<<"\n\n\n\tDelete Record";

  cout<<"\n\nPlease Enter The roll number of student You Want To Delete: ";

  cin>>no;

  fp.open("student.dat",ios::binary);

  fstream fp2;

  fp2.open("Temp.dat",ios::out|ios::binary);

  fp.seekg(0,ios::beg);

  while(fp.read((char*)&st,sizeof(student)))

  {

    if(st.retrollno()!=no)

      fp2.write((char*)&st,sizeof(student));

  }

  fp2.close();

  fp.close();

  remove("student.dat");

  rename("Temp.dat","student.dat");

  cout<<"\n\n\tRecord Deleted ..";

  getch();

}

void menu()

{

  int option;

  do

  {

    cout<<"\n\n\n\t\t\t\tSTUDENT REPORT CARD SYSTEM\n\n";

    cout<<"\t\t\t\t1. CREATE STUDENT RECORD";

    cout<<"\n\t\t\t\t2. DISPLAY ALL STUDENTS RECORDS";

    cout<<"\n\t\t\t\t3. SEARCH STUDENT RECORD ";

    cout<<"\n\t\t\t\t4. MODIFY STUDENT RECORD";

    cout<<"\n\t\t\t\t5. DELETE STUDENT RECORD";

    cout<<"\n\t\t\t\t6. EXIT";

    cout<<"\n\n\t\t\t\tEnter Your Option (1-6): ";

    cin>>option;

    switch(option)

    {

      case 1: write_student(); break;

      case 2: display_all(); break;

      case 3:

        int num;

        cout<<"\n\n\tPlease Enter The roll number: ";

        cin>>num;

        display_sp(num);

        break;

      case 4: modify_student(); break;

      case 5: delete_student(); break;

      case 6: exit(0); break;

      default: cout<<"\a";

    }

  }while(option!=6);

}

int main()

{

  menu();

  return 0;

}

以上是学籍管理系统的源代码,通过这段代码可以看到,该系统主要由一些类和函数组成,其中 `student` 类被用来表示学生的信息,包括姓名、学号、各科成绩、总分、百分比和等级。其他函数包括:添加学生数据、显示所有学生数据、查询学生数据、修改学生数据以及删除学生记录。通过这些函数,用户可以方便地管理学生信息。

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复