حـ قطرة بر
26-02-2004, 02:55 PM
أن شاء الله راح أبدأ أنزل لكم المعامل Data Structure
هذاLab 1
EX1:
Assume you have sequential file contains 10 student record ( Student name and grade ) each student data on a separate line,
Write ac++ program to
*Read that data from the file
*Reorder student records depending on their grades
*Rewrite the ordered records in anther sequential file
الحل هو
#include<fstream.h>
#include<stdlib.h>
#include<conio.h>
struct student
{
char name[10];
double grade;
};
void main()
{ int i;
student x[10];
ifstream f1("input.dat");
if(!f1)
{
cerr<<"error.....";
exit(1);
}
for(i=0;i<3;i++)
{
f1>>x[i].name>>x[i].grade;
cout <<x[i].name<<" " <<x[i].grade << endl;
getch();
}
student tmp;
for( i=0;i<2;i++)
for(int j=0;j<2;j++)
if(x[j].grade>x[j+1].grade)
{
tmp=x[j];
x[j]=x[j+1];
x[j+1]=tmp;
}
ofstream f2("output.dat",ios: : o ut);
for (i=0;i<3;i++)
f2<<x[i].name<<" "<<x[i].grade<<endl;
}
EX2
Suupose you have the following structure:
struct employee { char name [10];
double salary;
{;
Write AC++ program to read information of 10 employee from the user and save those information in a reandom access file
الحل
#include<fstream.h>
#include<stdlib.h>
struct employee
{
char name[10];
int salary;
};
void main()
{
employee x;
ofstream f1("randomf.dat",ios::binary);
if (!f1)
{
cerr<<"Errorrrrrrrrrrrr";
exit(1);
}
for(int i=1;i<=3;i++)
{
cout<<"Enter the employee name:";
cin>>x.name;
cout<<"Enter the salary:";
cin>>x.salary;
f1.seekp((i-1)*sizeof(employee));
f1.write(reinterpret_cast<const char* >(&x),sizeof(employee));
}
}
أتمنى لكم التوفيق ادعوا لي
راحيه الجامعة ألحين
وأن شاء الله لما أرجع
أنزل لكم المعمل الثاني
هذاLab 1
EX1:
Assume you have sequential file contains 10 student record ( Student name and grade ) each student data on a separate line,
Write ac++ program to
*Read that data from the file
*Reorder student records depending on their grades
*Rewrite the ordered records in anther sequential file
الحل هو
#include<fstream.h>
#include<stdlib.h>
#include<conio.h>
struct student
{
char name[10];
double grade;
};
void main()
{ int i;
student x[10];
ifstream f1("input.dat");
if(!f1)
{
cerr<<"error.....";
exit(1);
}
for(i=0;i<3;i++)
{
f1>>x[i].name>>x[i].grade;
cout <<x[i].name<<" " <<x[i].grade << endl;
getch();
}
student tmp;
for( i=0;i<2;i++)
for(int j=0;j<2;j++)
if(x[j].grade>x[j+1].grade)
{
tmp=x[j];
x[j]=x[j+1];
x[j+1]=tmp;
}
ofstream f2("output.dat",ios: : o ut);
for (i=0;i<3;i++)
f2<<x[i].name<<" "<<x[i].grade<<endl;
}
EX2
Suupose you have the following structure:
struct employee { char name [10];
double salary;
{;
Write AC++ program to read information of 10 employee from the user and save those information in a reandom access file
الحل
#include<fstream.h>
#include<stdlib.h>
struct employee
{
char name[10];
int salary;
};
void main()
{
employee x;
ofstream f1("randomf.dat",ios::binary);
if (!f1)
{
cerr<<"Errorrrrrrrrrrrr";
exit(1);
}
for(int i=1;i<=3;i++)
{
cout<<"Enter the employee name:";
cin>>x.name;
cout<<"Enter the salary:";
cin>>x.salary;
f1.seekp((i-1)*sizeof(employee));
f1.write(reinterpret_cast<const char* >(&x),sizeof(employee));
}
}
أتمنى لكم التوفيق ادعوا لي
راحيه الجامعة ألحين
وأن شاء الله لما أرجع
أنزل لكم المعمل الثاني