C++ Program – Using FileHandling..Progress Report

by Nideesh C on May 2, 2011 · 0 comments

in C++




//Downloaded From theonlinetutorials.com
//(C)2011.All rights reserved.
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<fstream.h>

struct stud
{
public:
int rno;
char name[50];
int cls;
float marks[5];
};

struct res
{
int rnos;
float total;
char grade;
float perc;
};

void main()
{
clrscr();
float tm;
int i,ma;
stud st;
res rt;

ofstream gpj("stud.dat",ios::binary|ios::trunc);
ofstream jpg("result.dat",ios::binary|ios::trunc);

if(!gpj||!jpg)
cout<<"File Cannot Be Created"<<endl;
int n;
if(gpj&&jpg)
{
cout<<"How mamy Students U Want to Enter ???? "<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Name"<<endl;
gets(st.name);
cout<<"Enter Roll No"<<endl;
cin>>st.rno;
cout<<"Enter Class"<<endl;
cin>>st.cls;
for(ma=0;ma<5;ma++)
{
cout<<"Enter Marks in subj"<<ma+1<<endl;
cin>>st.marks[ma];
}

gpj.write((char*)&st,sizeof(st));

tm=st.marks[0]+st.marks[2]+st.marks[1]+st.marks[3]+st.marks[4];

rt.perc=tm/5;

if(rt.perc>=75)
rt.grade='A';
if((rt.perc>=60)&&(rt.perc<75))
rt.grade='B';
if((rt.perc>=50)&&(rt.perc<60))
rt.grade='C';
if((rt.perc>=40)&&(rt.perc<50))
rt.grade='D';
if(rt.perc<40)
rt.grade='F';
rt.rnos=st.rno;

jpg.write((char*)&rt,sizeof(rt));

}}
gpj.close();
jpg.close();

int r,k=0;
ifstream god("result.dat",ios::binary);
if(!god)
{
cout<<"File Erroe"<<endl;
}
else
{
god.seekg(0);
cout<<endl<<"ENTER ROLL NO"<<endl;
cin>>r;
while(god.read((char*)&rt,sizeof(rt)))
{
if(r==rt.rnos)
{
k++;
cout<<"  Roll no  :"<<rt.rnos<<endl<<"  Percentage  :"<<rt.perc<<endl<<"  Grade  :"<<rt.grade;
}
}
if(k==0)
cout<<"Roll no not present"<<endl;
god.close();
}
getch();
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ class program – illestrate File operations
  2. C++ program – Using class to generate mark sheet using multiple inheritance
  3. C++ program – illestrate virtual functions
  4. C++ program – implement Pure Virtual Functions
  5. C++ program – Print student details using constructor and destructor

Leave a Comment

Previous post:

Next post: