Student Management System using Function Overloading using OOP in C++

Create a class for student containing data members: – Roll_no, name, marks1, marks2, and marks3. Use Function overloading concept (where possible) and write necessary member functions: (i) To accept details of all students. (ii) To display details of one student. (iii) To display details of all students.

‪#‎include‬<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
class
{
public:
int roll_no;
char firstname[20];
char lastname[20];
int mark;
}student;
int main()
{
int flag,choice,shift,rollnumber,found,continu,length;
char studentname[20];
FILE *fp;
cout<<"-------------------------------------------------------------"<<endl;
cout<<"\n\t STUDENT DATABASE SYSTEM";
Label1:
cout<<endl<<"1 -> Store a new record in database"<<endl;
cout<<"2 -> Search a student record by rollNo"<<endl;
cout<<"3 -> Quit Student Database"<<endl;
cout<<endl<<endl;
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
//------------------------------------------------------------------------
case 1:
//------------------------------------------------------------------------
Label2:
cout<<endl<<"Enter Student Details:"<<endl<<endl<<"Roll number (Integer): ";
cin>>student.roll_no;
cout<<endl<<"First Name:";
cin>>student.firstname;
cout<<endl<<"Last Name:";
cin>>student.lastname;
cout<<endl<<"Mark(0 - 100 integer) : ";
cin>>student.mark;
fp=fopen("officefile.txt","a+");
fprintf(fp,"\n%d\t%s\t%s\t%d\t",student.roll_no,student.firstname,student.lastname,student.mark);
fclose(fp);
cout<<"A student record has been added successfully..."<<endl;
cout<<endl<<endl<<"1 -> Wish to add another record to database";
cout<<endl<<"2 -> Wish to move to Main Menu";
cout<<endl<<"3 -> Exit from Program"<<endl;
cin>>shift;
if(shift==1)
goto Label2;
if(shift==2)
goto Label1;
if(shift==3)
break;
if(shift!=1&&2&&3){
cout<<"Exiting.........";
break;
}
//------------------------------------------------------------------------
case 2:
//------------------------------------------------------------------------
Label6:
cout<<endl<<"Enter the rollnumber: ";
cin>>rollnumber;
cout<<"Searching record with rollnumber = "<<rollnumber<<endl;
found=0;
if((fp=fopen("officefile.txt","r"))==NULL)
{
cout<<" ! The File is Empty..."<<endl<<endl;
}
else
{
while(!feof(fp)&& found==0)
{
fscanf(fp,"\n%d\t%s\t%s\t%d\t",&student.roll_no,student.firstname,student.lastname,&student.mark);
if(student.roll_no==rollnumber)
found=1;
}
}
if(found)
{
cout<<endl<<"The record is found.";
printf("\nRoll no: %d\nName: %s\nSurname: %s\nMark: %d \n",student.roll_no,student.firstname,student.lastname,student.mark);
}
else
{
cout<<"Not found..."<<endl;
getchar();
}
Label7:
cout<<endl<<endl<<"1 -> Wish to search more..";
cout<<endl<<"2 -> Wish to move to Main Menu";
cout<<endl<<"3 -> Exit from Program"<<endl;
cin>>shift;
if(shift==1)
goto Label6;
if(shift==2)
goto Label1;
if(shift==3)
break;
if(shift!=1&&2&&3){
cout<<endl<<"Enter a valid choice";
goto Label7;
}
//------------------------------------------------------------------------
case 3: break;
//------------------------------------------------------------------------
}
getchar();
return 0;
}

No comments:

Post a Comment

Comment Here