Printing a Student Marksheet in C++

Here in this page we made a program of printing a student marksheet in C++ . its is a demonstration of a printout related task i.e, printing receipt, printing Bill record etc.

In this program, only 5 subject names and subject marks (with their practicals subject) will be stored for which an array is used in the program. But, if there is no practical subject with any subject, in such a case, enter 0 value when program ask for practical subject name.

In this way, this program can be print the marksheet of almost all the students who have 5 subjects whether practical subject available or not.

Before starting program of  Printing a Student Marksheet in C++, the header files and their functions used in the program are described below.

#include<iostream.h>
#include<fstream.h>
#include <stdio.h> //rename(),remove()
#include <stdlib.h> //itoa(),atoi()
#include<conio.h>
#include<dos.h> //getdate()
#include<iomanip.h> // setwidth(),setiosflags()
#include<string.h> //strupr(),strcpy(),strcmp() strcat()
 class student
 {
   int marks[5],marks2[5],total_marks,pr;
   char r_no[10],stu_name[20],dob[20],f_name[20],m_name[20];
   typedef char subj[100];
   subj name[20]; // store subject name into name[] array
  public:
   void get_record(void); // take personal and subject detail from user
   void printing(); // print marksheet
   void grade(int,int); // store subject grade
//convert digit into character form//
    void get_total(int); //
    void one(char[],int); //
    void two(int); //
    void three(char[],int,int); //
    void process(char[],int,int); //
////////////////////////
};

Following Part of this Program will store subject detail (Theoretical  marks and  Practical marks). marks[j] for Theoretical marks and marks2[j] for Practical marks

cout<<"Student subject Detailn (If prectical subject not then enter 0n";
 
for(int i=0;i<5;i++)
 {
   cout<<"Enter "<<i+1<<" subject name: ";
   gets(name[i]); // store subject
 }
 cout<<endl;
 for(int j=0;j<5;j++)
 {
    cout<<"nEnter "<<j+1<<" Subject marks : ";
    cin>>marks[j];  // store theory subject marks
    cout<<"And Practical marks : ";
    cin>>marks2[j];     // store practical subject marks
    total_marks=total_marks+marks[j]+marks2[j]; // calculate total marks of subject
 }
 pr = total_marks/5; // variable pr store percantage

To Print student marksheet we write a file with each information entered by user, using << operator  . Here while- loop will be execute 5 times(Because of 5 subject).

int subject=0;
while(subject<5) // loop execute 5 time because of 5 subject
{
  fout<<"nt| ";
  fout.width(25);
  fout<<setiosflags(ios::left);
  fout<<strupr(name[subject]);// convert subject name into uppper case than write into file
  fout.width(6);
  fout<<setiosflags(ios::right);
  fout<<"|";
  fout.width(6);
  fout<<setiosflags(ios::right);
  fout<<marks[subject]; //print subject marks
  fout.width(5);
  fout<<setiosflags(ios::right);
  fout<<"|";
  fout.width(7);
  fout<<setiosflags(ios::right);
  if(marks2[subject]==0) // check subject is prectical or not
     fout<<"_";
  else
     fout<<marks2[subject];
  fout.width(5);
  fout<<setiosflags(ios::right);
  fout<<"|";
  fout.width(6);
  fout<<setiosflags(ios::right);
  fout<<marks[subject]+marks2[subject]; // print total of theory and prectical
  fout.width(4);
  fout<<setiosflags(ios::right);
  fout<<"|";
  fout<<" ";
  fout.width(13);
  fout<<setiosflags(ios::left);
  get_total(marks[subject]+marks2[subject]); // convert total into character form
  char ch[50];
  ifstream f0("char");
  while(!f0.eof()) {
     f0.getline(ch,50);
  } f0.close();
  strupr(ch); // convert string into upper case
  fout<<ch; // write total as character form into file
  remove("char"); // now remove char file after use
  fout<<" ";
  fout.width(3);
  fout<<setiosflags(ios::left);
  fout<<"|";
  grade(marks[subject],marks2[subject]);
  char g1[10];
  ifstream o1("grade");//open grade file to calculate grade for subject
  while(!o1.eof()) {
     o1.getline(g1,10);
    }o1.close();
  fout<<g1; // write grade into subject
  fout.width(4);
  fout<<setiosflags(ios::right);
  fout<<"|";
  if(subject==0)// represent row 
   {
     fout.width(8);
     fout<<setiosflags(ios::right);
     fout<<total_marks<<" |"; // print total subject marks accessing from get_record() function
   }
  if(subject==1)
  {
     fout.width(8);
     fout<<setiosflags(ios::right);
     if(marks[subject]<33||marks2[subject]) // check sudent passed or not
       fout<<"FAIL";
     else
       fout<<"PASSED";
     fout.width(4);
     fout<<setiosflags(ios::right);
     fout<<"|";
   }
  if(subject==2)
  {
     fout.width(7);
     fout<<setiosflags(ios::right);
     fout<<pr<<"%";
     fout.width(4);
     fout<<setiosflags(ios::right);
     fout<<"|";
  }
  if(subject==3)
  {
// write division into file
     fout.width(8);
     fout<<setiosflags(ios::right);
     if(pr>=60)
        fout<<"FIRST";
     else if(pr>=45&&pr<60)
        fout<<"SECOND";
     else if(pr<33)
        fout<<"THIRD";
     fout.width(4);
     fout<<setiosflags(ios::right);
     fout<<"|";
  }
  if(subject==4)
  {
     fout<<" DIV. |";
  }

The data entered by the user is in any form (lowercase or uppercase), the data in the file will be write in uppercase itself (because of strupr () function) as shown in the output.

The marksheet of two different classes (12th and IT courses) has been printed by the program.

OUTPUT:-

1st execution:-

 Student personal detail
Enter Class or Level   : 12th
 Enter Student roll no  : 1002
 Enter Student Name   : anand bisht	
 Enter Date of Birth     : 30/06/1996
 Enter Father Name     : kishan singh
 Enter Mother Name    : kamla devi
Student subject Detail
If prectical subject not then enter 0
Enter 1 subject name: hindi
Enter 2 subject name: english
Enter 3 subject name: biology
Enter 4 subject name: physics
Enter 5 subject name: chemistry
Enter 1 subject marks: 70
And Practical Marks  : 0
Enter 2 subject marks: 28
And Practical Marks  : 0
Enter 3 subject marks: 50
And Practical Marks  : 28
Enter 4 subject marks: 39
And Practical Marks  : 20
Enter 5 subject marks: 46
And Practical Marks  : 26

printing-a-student-marksheet-in-cpp

2nd execution:-Different Student Detail(information technology) entering in same way as above while Printed Marksheet is quite Different,

printing-student-marksheet-in-cpp

Thus, This Program can Print all Student Marksheet who has Only Five Subject.

 

Download complete Program and execute yourself,


Related Project in C++ are: