pooria_googooli
یک شنبه 08 فروردین 1389, 18:02 عصر
سلام دوستان . میشه توضیح بدید برا چی ارور میده؟
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
using namespace std;
#define max 50
class student {
public :
char numst[11];
char name[15];
char famili[20];
double score[4];
double ave;
student(); //initializing
~student(); //destructing
set_null(){name[0]=numst[0]='\0';}
}st[max];
//************************************
student::student(){ //initializing
set_null();
}
//*************************************
student::~student(){ //destructing
set_null();
}
//*************************************
class Enter {
private :
void save();
public :
void add();
void edit();
void search();
void print();
void len_file();
void load();
}e;
//************************************************** ****************************
void Enter::add(){
int i;
double sum=0.00;
for(i=0;i<max && st[i].name[0]!='\0';i++);
system("cls");
cout<<"\n Enter a name : "<<flush;
cin>>st[i].name;
cout<<"\n Enter a famili : "<<flush;
cin>>st[i].famili;
cout<<"\n Enter a numst : "<<flush;
cin>>st[i].numst;
for(int j=0;j<4;j++){
cout<<"\n Enter a score "<<j+1<<" : "<<flush;
cin>>st[i].score[j];
sum+=st[i].score[j];
}
st[i].ave=sum/4;
e.save();
}
//************************************************** ****************************
void Enter::edit(){
char tmp[11];
int i,flag=0;;
double sum=0.00;
system("cls");
cout<<"\n Enter a numst for edit : "<<flush;
cin>>tmp;
for(i=0;i<max && st[i].name[0]!='\0';i++)
if(strcmp(st[i].numst,tmp)==0){
cout<<"\n Enter a new name : ";
cin>>st[i].name;
cout<<"\n Enter a new famili : ";
cin>>st[i].famili;
for(int j=0;j<4;j++){
cout<<"\n Enter a new score "<<j+1<<" : "<<flush;
cin>>st[i].score[j];
sum+=st[i].score[j];
}
st[i].ave=sum/4;
cout<<"\n for continue . press key..."<<flush;
getch();
flag=1;
e.save();
}
if(flag==0){
cout<<"\n Not found . press key..."<<flush;
getch();
return ;
}
}
//************************************************** ****************************
void Enter::search(){
char tmp[15];
int i,flag=0;
system("cls");
cout<<"\n Enter a name for search : "<<flush;
cin>>tmp;
for(i=0;i<max && st[i].name[0]!='\0';i++)
if(strcmp(st[i].name,tmp)==0){
cout<<"\n Name = "<<st[i].name<<flush;
cout<<"\n Famili = "<<st[i].famili<<flush;
for(int j=0;j<4;j++)
cout<<"\n Score "<<j+1<<" = "<<st[i].score[j]<<flush;
cout<<"\n average = "<<st[i].ave<<flush;
cout<<"\n for continue . press key..."<<flush;
getch();
flag=1;
}
if(flag==0){
cout<<"\n Not found . press key..."<<flush;
getch();
return ;
}
}
//************************************************** ****************************
void Enter::print(){
int i;
system("cls");
for(i=0;i<max && st[i].name[0]!='\0';i++){
cout<<"\n Name = "<<st[i].name<<flush;
cout<<"\n Famili = "<<st[i].famili<<flush;
for(int j=0;j<4;j++)
cout<<"\n Score "<<j+1<<" = "<<st[i].score[j]<<flush;
cout<<"\n average = "<<st[i].ave<<"\n\n"<<flush;
}
cout<<"\n for continue . press key..."<<flush;
getch();
}
//************************************************** ****************************
void Enter::save(void){
register int i;
FILE *fp;
fp=fopen("c:\\st.dat","w+b");
if(!fp){
cout<<"\n Cannot open file press key ..."<<flush;
getch();
return ;
}
for(i=0;i<max && st[i].name[0]!='\0';i++)
fwrite(&st[i],sizeof(class student),1,fp);
fclose(fp);
}
//************************************************** ****************************
void Enter::load(void){
register int i;
FILE *fp;
system("cls");
fp=fopen("c:\\st.dat","rb");
if(!fp){
cout<<"\n Cannot open file press key ..."<<flush;
getch();
return ;
}
for(i=0;i<max;i++){
fread(&st[i],sizeof(class student),1,fp);
if(feof(fp)){
system("cls");
cout<<" Data loaded press a key ..."<<flush;
getch();
return ;
}
}
fclose(fp);
}
//************************************************** ****************************
void Enter::len_file(){
int handle;
system("cls");
handle=open("c:\\st.dat",O_RDONLY);
cout<<"\n File lenght in byte = "<<filelength(handle)<<" byte "<<flush;
getch();
close(handle);
}
//************************************************** ****************
void main(){
int num;
e.load();
do{
system("cls");
cout<<"\t\t Welcome\n"<<flush;
cout<<"\n 1).Add"<<flush;
cout<<"\n 2).Edit"<<flush;
cout<<"\n 3).Search"<<flush;
cout<<"\n 4).List"<<flush;
cout<<"\n 5).Length file"<<flush;
cout<<"\n 6).Exit"<<flush;
cout<<"\n\n Enter a number (1-6) :"<<flush;
num=getche()-48;
getch();
switch (num){
case 1 : e.add();
break;
case 2 : e.edit();
break;
case 3 : e.search();
break;
case 4 : e.print();
break;
case 5 : e.len_file();
break;
case 6 : exit(1);
}
}while(1);
}// end program
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
using namespace std;
#define max 50
class student {
public :
char numst[11];
char name[15];
char famili[20];
double score[4];
double ave;
student(); //initializing
~student(); //destructing
set_null(){name[0]=numst[0]='\0';}
}st[max];
//************************************
student::student(){ //initializing
set_null();
}
//*************************************
student::~student(){ //destructing
set_null();
}
//*************************************
class Enter {
private :
void save();
public :
void add();
void edit();
void search();
void print();
void len_file();
void load();
}e;
//************************************************** ****************************
void Enter::add(){
int i;
double sum=0.00;
for(i=0;i<max && st[i].name[0]!='\0';i++);
system("cls");
cout<<"\n Enter a name : "<<flush;
cin>>st[i].name;
cout<<"\n Enter a famili : "<<flush;
cin>>st[i].famili;
cout<<"\n Enter a numst : "<<flush;
cin>>st[i].numst;
for(int j=0;j<4;j++){
cout<<"\n Enter a score "<<j+1<<" : "<<flush;
cin>>st[i].score[j];
sum+=st[i].score[j];
}
st[i].ave=sum/4;
e.save();
}
//************************************************** ****************************
void Enter::edit(){
char tmp[11];
int i,flag=0;;
double sum=0.00;
system("cls");
cout<<"\n Enter a numst for edit : "<<flush;
cin>>tmp;
for(i=0;i<max && st[i].name[0]!='\0';i++)
if(strcmp(st[i].numst,tmp)==0){
cout<<"\n Enter a new name : ";
cin>>st[i].name;
cout<<"\n Enter a new famili : ";
cin>>st[i].famili;
for(int j=0;j<4;j++){
cout<<"\n Enter a new score "<<j+1<<" : "<<flush;
cin>>st[i].score[j];
sum+=st[i].score[j];
}
st[i].ave=sum/4;
cout<<"\n for continue . press key..."<<flush;
getch();
flag=1;
e.save();
}
if(flag==0){
cout<<"\n Not found . press key..."<<flush;
getch();
return ;
}
}
//************************************************** ****************************
void Enter::search(){
char tmp[15];
int i,flag=0;
system("cls");
cout<<"\n Enter a name for search : "<<flush;
cin>>tmp;
for(i=0;i<max && st[i].name[0]!='\0';i++)
if(strcmp(st[i].name,tmp)==0){
cout<<"\n Name = "<<st[i].name<<flush;
cout<<"\n Famili = "<<st[i].famili<<flush;
for(int j=0;j<4;j++)
cout<<"\n Score "<<j+1<<" = "<<st[i].score[j]<<flush;
cout<<"\n average = "<<st[i].ave<<flush;
cout<<"\n for continue . press key..."<<flush;
getch();
flag=1;
}
if(flag==0){
cout<<"\n Not found . press key..."<<flush;
getch();
return ;
}
}
//************************************************** ****************************
void Enter::print(){
int i;
system("cls");
for(i=0;i<max && st[i].name[0]!='\0';i++){
cout<<"\n Name = "<<st[i].name<<flush;
cout<<"\n Famili = "<<st[i].famili<<flush;
for(int j=0;j<4;j++)
cout<<"\n Score "<<j+1<<" = "<<st[i].score[j]<<flush;
cout<<"\n average = "<<st[i].ave<<"\n\n"<<flush;
}
cout<<"\n for continue . press key..."<<flush;
getch();
}
//************************************************** ****************************
void Enter::save(void){
register int i;
FILE *fp;
fp=fopen("c:\\st.dat","w+b");
if(!fp){
cout<<"\n Cannot open file press key ..."<<flush;
getch();
return ;
}
for(i=0;i<max && st[i].name[0]!='\0';i++)
fwrite(&st[i],sizeof(class student),1,fp);
fclose(fp);
}
//************************************************** ****************************
void Enter::load(void){
register int i;
FILE *fp;
system("cls");
fp=fopen("c:\\st.dat","rb");
if(!fp){
cout<<"\n Cannot open file press key ..."<<flush;
getch();
return ;
}
for(i=0;i<max;i++){
fread(&st[i],sizeof(class student),1,fp);
if(feof(fp)){
system("cls");
cout<<" Data loaded press a key ..."<<flush;
getch();
return ;
}
}
fclose(fp);
}
//************************************************** ****************************
void Enter::len_file(){
int handle;
system("cls");
handle=open("c:\\st.dat",O_RDONLY);
cout<<"\n File lenght in byte = "<<filelength(handle)<<" byte "<<flush;
getch();
close(handle);
}
//************************************************** ****************
void main(){
int num;
e.load();
do{
system("cls");
cout<<"\t\t Welcome\n"<<flush;
cout<<"\n 1).Add"<<flush;
cout<<"\n 2).Edit"<<flush;
cout<<"\n 3).Search"<<flush;
cout<<"\n 4).List"<<flush;
cout<<"\n 5).Length file"<<flush;
cout<<"\n 6).Exit"<<flush;
cout<<"\n\n Enter a number (1-6) :"<<flush;
num=getche()-48;
getch();
switch (num){
case 1 : e.add();
break;
case 2 : e.edit();
break;
case 3 : e.search();
break;
case 4 : e.print();
break;
case 5 : e.len_file();
break;
case 6 : exit(1);
}
}while(1);
}// end program