You are on page 1of 3

#include<fstream.

h>
#include<conio.h>
#include<stdio.h>
struct employee
{
int Empno;
char Name[20];
float salary;
};
void writefile()
{
ofstream F;
F.open("RECORD.DAT",ios::out|ios::binary);
employee E;
char ch;
do{
cout<<"Enter Empno,Name & Salary";
cin>>E.Empno;
gets(E.Name);
cin>>E.salary;
F.write((char*)&E,sizeof (E));
cout<<"Enter(Y/N) for more objects";
cin>>ch;
}
while(ch=='y'//ch=='Y');
F.close();
}
void readfile()
{
ifstream F;
F.open("RECORD.DAT",ios::in|ios::binary);
employee E;
while(!F.eof())
{
F.read((char*)&E,sizeof (E));
cout<<"\n EMPNO="<<E.Empno;
cout<<"\n Name="<<E.Name;
cout<<"\n Salary="<<E.salary;
}
F.close();
}
void main()
{
clrscr();
writefile();
readfile();
getch();
}
#include<iostream.h>
#include<conio.h>
class Flight
{
private:
int FLNO;
char Destination[20];
float fuel;
int distance;
void CALFUEL()
{
if(distance<500)
fuel=800;
else
if(distance>=500 && distance<100)
fuel=1200;
else
fuel=2200;
}
public:
void INPUT()
{
cout<<"Enter FLNO";
cin>>FLNO;
cout<<"Enter Destination";
cin>>Destination

;
cout<<"Enter distance";
cin>>distance;
CALFUEL();
}
void DISPLAY()
{
cout<<"\n Flno="<<FLNO;
cout<<"\n Destination="<<Destination;
cout<<"\n distance="<<distance;
cout<<"\n fuel="<<fuel;
}
};
void main()
{
clrscr();
Flight ob;
ob.INPUT();
ob.DISPLAY();
}
include<iostream.h>
#include<conio.h>
class student
{
private:
int admno;
char sname[20];
float Eng,Math,Sci;
float total;
float ctotal()
{
return(Eng+Math+Sci);
}
public:
void TAKEDATA()
{
cout<<"Enter admno";
cin>>admno;
cout<<"Enter sname";
cin>>sname;
cout<<"Enter marks in Eng,Math,Sci";
cin>>Eng>>Math>>Sci;
total=ctotal();
}
void SHOWDATA()
{
cout<<"\n admno="<<admno;
cout<<"\n name="<<sname;
cout<<"\n marks in English="<<Eng;
cout<<"\n marks in Math="<<Math;
cout<<"\n marks in Science="<<Sci;
cout<<"\n total marks="<<total;
}
};
void main()
{
clrscr();
student S;
S.TAKEDATA();
S.SHOWDATA();
ge

You might also like