m.khani_121
دوشنبه 24 بهمن 1390, 20:16 عصر
این برنامه میاد اطلاعات نام ، شماره دانشجویی و معدل رو میگیره و بعد شماره دانشجویی میدیم بهش اطلاعات دانشجو رو باید بیاره ! مشکلش میدونین چیه ؟!!!! وقتی میخوای بهش شماره دانشجویی بدی تا بگرده از برنامه خارج میشه .
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
struct student
{
char name[21];
int stno;
int ave;
}st;
int main()
{
int no;
fstream out ("student.dat",ios::out | ios::binary);
if(!out)
{
cout<<" cannot !!";
exit(0);
}
cout<<" name , stno , ave , num"<<endl;
while(1)
{
cout<<"name :";
cin.get(st.name,20);
if(!st.name[0])
break;
cout<<endl<<" stno :";
cin>>st.stno;
cout<<endl<<" ave :";
cin>>st.ave;
cin.get();
out.write((char *)&st,sizeof(struct student));
}
out.close();
cout<<" press eny ket to contiue . . .";
getch();
system("cls");
ifstream in("student.dat",ios::in |ios::binary);
cout<<" enter stno : ";
cin>>no;
while(in.read((char *) &st,sizeof(struct student)))
{
if(st.stno==no)
{
cout<<endl<<" name :"<<st.name<<" stno :"<<st.stno<<" ave : "<<st.ave;
break;
}
getch();
}
in.close();
return 0;
}
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
struct student
{
char name[21];
int stno;
int ave;
}st;
int main()
{
int no;
fstream out ("student.dat",ios::out | ios::binary);
if(!out)
{
cout<<" cannot !!";
exit(0);
}
cout<<" name , stno , ave , num"<<endl;
while(1)
{
cout<<"name :";
cin.get(st.name,20);
if(!st.name[0])
break;
cout<<endl<<" stno :";
cin>>st.stno;
cout<<endl<<" ave :";
cin>>st.ave;
cin.get();
out.write((char *)&st,sizeof(struct student));
}
out.close();
cout<<" press eny ket to contiue . . .";
getch();
system("cls");
ifstream in("student.dat",ios::in |ios::binary);
cout<<" enter stno : ";
cin>>no;
while(in.read((char *) &st,sizeof(struct student)))
{
if(st.stno==no)
{
cout<<endl<<" name :"<<st.name<<" stno :"<<st.stno<<" ave : "<<st.ave;
break;
}
getch();
}
in.close();
return 0;
}