0% found this document useful (0 votes)
22 views4 pages

Dsal 012

The document outlines a practical programming assignment for maintaining employee information, including functionalities to add, delete, and display employee details using an index sequential file. It provides a C++ program that allows user input for employee data and modifications, along with the logic for grading based on marks. The program also handles cases where an employee record may not be found and displays appropriate messages.

Uploaded by

bgmijaan055
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Dsal 012

The document outlines a practical programming assignment for maintaining employee information, including functionalities to add, delete, and display employee details using an index sequential file. It provides a C++ program that allows user input for employee data and modifications, along with the logic for grading based on marks. The program also handles cases where an employee record may not be found and displays appropriate messages.

Uploaded by

bgmijaan055
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No: 12

Name:- Mundhe Shrinath Sanjay


Class:- S.E Computer
Batch:- A3
Roll No:- 78

Title:- Company maintains employee information as employee ID, name, designation and salary.
Allow user to add, delete information of employee. Display information of particular employee. If
employee does not exist an appropriate message is displayed. If it is, then the system displays the
employee details. Use index sequential file to maintain the data.

Program Code:-

#include<fstream>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include <iostream>
#include <queue>
using namespace std;
class student
{
int rollno;
char name[20];
char branch[3];
float marks;
char grade;
public:
void getdata()
{
cout<<"Rollno: ";
cin>>rollno;
cout<<"Name: ";
cin>>name;
cout<<"Branch: ";
cin>>branch;
cout<<"Marks: ";
cin>>marks;
if(marks>=75)
{
grade = 'A';
}
else if(marks>=60)
{
grade = 'B';
}
else if(marks>=50)
{
grade = 'C';
}
else if(marks>=40)
{
grade = 'D';
}
else
{
grade = 'F';
}
}
void putdata()
{
cout<<"Rollno: "<<rollno<<"\tName: "<<name<<"\n";
cout<<"Marks: "<<marks<<"\tGrade: "<<grade<<"\n";
}
int getrno()
{
return rollno;
}
void modify();
}stud1, stud;
void student::modify()
{
cout<<"Rollno: "<<rollno<<"\n";
cout<<"Name: "<<name<<"\tBranch: "<<branch<<"\tMarks: "<<marks<<"\n";
cout<<"Enter new details.\n";
char nam[20]=" ", br[3]=" ";
float mks;
cout<<"New name:(Enter '.' to retain old one): ";
cin>>nam;
cout<<"New branch:(Press '.' to retain old one): ";
cin>>br;
cout<<"New marks:(Press -1 to retain old one): ";
cin>>mks;
if(strcmp(nam, ".")!=0)
{
strcpy(name, nam);
}
if(strcmp(br, ".")!=0)
{
strcpy(branch, br);
}
if(mks != -1)
{
marks = mks;
if(marks>=75)
{
grade = 'A';
}
else if(marks>=60)
{
grade = 'B';
}
else if(marks>=50)
{
grade = 'C';
}
else if(marks>=40)
{
grade = 'D';
}
else
{
grade = 'F';
}
}
}
int main()
{
//clrscr();
fstream fio("marks.dat", ios::in | ios::out);
char ans='y';
while(ans=='y' || ans=='Y')
{
stud1.getdata();
fio.write((char *)&stud1, sizeof(stud1));
cout<<"Record added to the file\n";
cout<<"\nWant to enter more ? (y/n)..";
cin>>ans;
}
//clrscr();
int rno;
long pos;
char found='f';
cout<<"Enter rollno of student whose record is to be modified: ";
cin>>rno;
fio.seekg(0);
while(!fio.eof())
{
pos = fio.tellg();
fio.read((char *)&stud1, sizeof(stud1));
if(stud1.getrno() == rno)
{
stud1.modify();
fio.seekg(pos);
fio.write((char *)&stud1, sizeof(stud1));
found = 't';
break;
}
}
if(found=='f')
{
cout<<"\nRecord not found in the file..!!\n";
cout<<"Press any key to exit...\n";
getch();
exit(2);
}
fio.seekg(0);
cout<<"Now the file contains:\n";
while(!fio.eof())
{
fio.read((char *)&stud, sizeof(stud));
stud.putdata();
}
fio.close();
getch();
return 0;
}

OutPut:-

You might also like