Bonjormi (سلام)
منم دچار یکن مشکلم و مشکلم اینه با C++زیاد اشنا نیستم.
استاد ما پروژه ساده ای می خواد. البنه فکنم ساده.
توضیح پروژه:
1-دریافت اطلاعات یک دانشجو وذخیره کردن آن در یک فایل (نام و شماره ی دانشجویی و تعداد واحد های پاس شده و معدل کل)
2-جستجوی یک دانشجو بر اساس شماره دانشجو.
3-این برنامه باید به شکل یک منو باشه تا همه فهم باشه.
4-ویرایشکردن فایل فوق وذخیره کردن آن
البته من این برنامه را با توجه به کتاب آقای جعفر نژاد خان قمی نوشتم ولی از من خطا گرفت.
این همون برنامه است که از کتاب آقای جعفر نژاد خان قمی نوشتم.
اگه امکان دارهکاملش کنین والبنه تصیح هم کنین واگه امکانش هست فایلCPPآن را برای دانلود تو سایت بگذارین یا انکه فایل رو به میل من بفرستین.
E-Mail:Ahmadi.m.r.89@gmail.com
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
struct student {
char name[21];
int stno;
float ave;
}st;
int main()
{
clrscr();
int no,row=3;
ofstream fp("student.dat",ios::out | ios::binary);
if(!fp) {
cout<<"Cannot Open File.";
exit(0);
}
cout<<"name "<<"stno "<<"Average";
cout<<"\n------------";
while(1) {
gotoxy(1,row);
cin.get(st.name,20);
if(!st.name[0])
break;
gotoxy(20,row);
cin>>st.stno;
gotoxy(30,row);
cin>>st.ave;
cin.get();//for end of line from keybord buffer
fp.write((char *) &st,sizeof(struct student));
row++;
}
fp.close();
cout<<"Preaa akey to Continue...";
getch();
clrscr();
ifstream in ("student.dat",ios::in | ios::binary);
ifstream out ("temp.dat",ios::out | ios::binary);
if(!in && !out) {
cout<<"Cannot Open File.";
getch();
exit(0);
}
cout<<"Enter stno to Search:";
cin>>no;
row=6;
while(in.read((char *) &st,sizeof(struct student))) {
if(st.stno==no){
cout<<"\nEnter new Information for this student:\n";
cout<<"name "<<"stno "<<"Average";
cout<<"\n------------";
row++;
gotoxy(1,row);
cin>>st.name;
gotoxy(20,row);
cin>>st.stno;
gotoxy(30,row);
cin>>st.ave;
}//end of if
out.write((char *) &st,sizeof(struct student));
}//end of while
in.close();
out.close();
remove("student.dat");
rename("temp.dat","student.dat");
cout<<"Press a key to see new content of file...";
getch();
clrscr();
row=3;
ifstream temp("student.dat",ios::out | ios::binary);
cout<<"name "<<"stno "<<"Average";
cout<<"\n------------";
while(temp.read((char *) &st,sizeof(struct student))) {
gotoxy(1,row);
cout<<st.name;
gotoxy(20,row);
cout<<st.stno;
gotoxy(30,row);
cout<<st.ave;
row++;
}
getch();
return 0;
}
خطا در این خط است
out.write((char *) &st,sizeof(struct student));