C++ dasturlash tilida Biror baza yaratish uchun biz struktura hamda massivdan foydalanamiz.
“Talaba” nomli baza yaratib kuramiz.
#include
#include
#include
using namespace std;
struct Talaba
{
string ism;
string familya;
int t_yil;
string yunalish;
};
int main()
{ int a,c;
cout<<"Nechta talaba haqida malumot kiritmoqchisiz ? \n";
cin>>a;
Talaba t[a];
for(int i=0; i
{
cout<
cout<<"Familyasini kiriting : >> ";
cin>>t[i].familya;
cout<<"Ismini kiriting : >> ";
cin>>t[i].ism;
cout<<"Tug'ilgan yilini kiriting kiriting : >> ";
cin>>t[i].t_yil;
cout<<"Talim yo'nalishini kiriting : >> ";
cin>>t[i].yunalish;
}
// Malumotlarni Faylga yozamiz
ofstream outfile;
outfile.open("D:/Talaba_bazasi.txt",ios::binary);
for(int i=0; i
{
outfile.write((char*)&t[i],sizeof(Talaba));
}
outfile.close();
// Fayldan o'qiymiz
cout<<"Kiritilgan ma'lumotlarni ko'rishni istaysizmi ?"<
cout<<"1. Ha 2. Yuq \n --> ";
cin>>c;
if(c==1)
{
Talaba T[a];
Talaba m;
int k=0;
ifstream fin("D:/Talaba_bazasi.txt",ios::binary);
if(!fin.is_open())
{
cout<<"Xatolik yuz berdi . Fayl topilmadi ?";
exit(1);
}
while(!fin.eof())
{
fin.read((char*)&m,sizeof(Talaba));
T[k]=m;
k++;
}
fin.close();
// Ekranga chop etish
for(int g=0; g
{
cout<
cout<<"Familyasi : "<
cout<<"Ismi : "<
cout<<"Tug'ilgan yili : "<
cout<<"Talim yo'nalishi : "<
}
}
else {
cout<<"Dastur ishlashi tugatildi !!!"<
exit(1);
}
return 0;
}
Do'stlaringiz bilan baham: |