mamad1994
یک شنبه 02 آذر 1393, 22:37 عصر
دوستان برنامه زیر رو نوشتم
تو فایل 뛠慳慤s쳌쳌쳌쳌쳌쳌쳌쳌쳌珌摡獡d 쳌쳌쳌쳌쳌懌摳獡d쳌쳌쳌쳌쳌쳌쳌 نوشته می شه موقع چاپ هم نا مفهوم چاپ می شه مشکل از چیه؟
کامپایلر visual studio
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std ;
void getstudent();
void printstudent(int x);
void searchstu(unsigned long int help ,int x);
class Student{
public :
unsigned long int id ;
char name[25];
char Borncity[20];
char livingCity[20];
};
int main(){
int switchId=-1;
int x=0;
unsigned long int id;
fstream we("count.txt");
we >>x;
do{
cout<<"1.reception student info\n"<<"2.Print student info\n"<<"3.search student info \n"<<"0.Exit\n";
cout<<"adad gozine ra vared konid: \n";
cin>>switchId;
switch(switchId)
{
case 1:
getstudent();
++x;
we.seekg (0,we.beg);
we <<x;
break;
case 2 :
printstudent(x);
break;
case 3 :
cout<<"enter id : "<<endl;
cin>>id;
searchstu(id,x);
}
}while(switchId!=0);
we.close();
}
void getstudent(){
Student s;
fstream ofs("infoS.txt");
ofs.seekg(0,ofs.end);
cout<<"Enter student id\n";
cin>>s.id;
cout<<"Enter student name :"<<endl;
cin>>s.name;
cout<<"enter Born City :"<<endl;
cin>>s.Borncity;
cout<<"enter study City :"<<endl;
cin>>s.livingCity;
ofs.write((char *)&s,sizeof(s));
ofs.close();
}
void printstudent(int x ){
Student s;
ifstream out("infoS.txt");
out.seekg(0,out.beg);
for(int i=0 ;i<x;i++){
out.read((char *)&s,sizeof(s));
cout<<s.id<<endl<<s.name<<endl<<s.Borncity<<endl<<s.livingCity<<endl<<endl;
if(strcmp(s.Borncity,s.livingCity)==0){
cout<<"local student \n\n\n";
}
}
}
void searchstu(unsigned long int help , int x){
Student s;
ifstream d("infoS.txt");
d.seekg(0,d.beg);
for(int i=0 ;i<x;i++){
d.read((char *)&s,sizeof(s));
if(s.id==help){
cout <<"ID: "<<s.id<<" name: "<<s.name<<" Born City :"<<s.Borncity<<" living City :"<<s.livingCity<<endl;
if(s.id==help && strcmp(s.Borncity,s.livingCity)==0){
cout<<"\nlocal student \n\n\n";
break;}
break;}
}
if(s.id!=help){
cout<<"not found !!!\n";
}
}
تو فایل 뛠慳慤s쳌쳌쳌쳌쳌쳌쳌쳌쳌珌摡獡d 쳌쳌쳌쳌쳌懌摳獡d쳌쳌쳌쳌쳌쳌쳌 نوشته می شه موقع چاپ هم نا مفهوم چاپ می شه مشکل از چیه؟
کامپایلر visual studio
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std ;
void getstudent();
void printstudent(int x);
void searchstu(unsigned long int help ,int x);
class Student{
public :
unsigned long int id ;
char name[25];
char Borncity[20];
char livingCity[20];
};
int main(){
int switchId=-1;
int x=0;
unsigned long int id;
fstream we("count.txt");
we >>x;
do{
cout<<"1.reception student info\n"<<"2.Print student info\n"<<"3.search student info \n"<<"0.Exit\n";
cout<<"adad gozine ra vared konid: \n";
cin>>switchId;
switch(switchId)
{
case 1:
getstudent();
++x;
we.seekg (0,we.beg);
we <<x;
break;
case 2 :
printstudent(x);
break;
case 3 :
cout<<"enter id : "<<endl;
cin>>id;
searchstu(id,x);
}
}while(switchId!=0);
we.close();
}
void getstudent(){
Student s;
fstream ofs("infoS.txt");
ofs.seekg(0,ofs.end);
cout<<"Enter student id\n";
cin>>s.id;
cout<<"Enter student name :"<<endl;
cin>>s.name;
cout<<"enter Born City :"<<endl;
cin>>s.Borncity;
cout<<"enter study City :"<<endl;
cin>>s.livingCity;
ofs.write((char *)&s,sizeof(s));
ofs.close();
}
void printstudent(int x ){
Student s;
ifstream out("infoS.txt");
out.seekg(0,out.beg);
for(int i=0 ;i<x;i++){
out.read((char *)&s,sizeof(s));
cout<<s.id<<endl<<s.name<<endl<<s.Borncity<<endl<<s.livingCity<<endl<<endl;
if(strcmp(s.Borncity,s.livingCity)==0){
cout<<"local student \n\n\n";
}
}
}
void searchstu(unsigned long int help , int x){
Student s;
ifstream d("infoS.txt");
d.seekg(0,d.beg);
for(int i=0 ;i<x;i++){
d.read((char *)&s,sizeof(s));
if(s.id==help){
cout <<"ID: "<<s.id<<" name: "<<s.name<<" Born City :"<<s.Borncity<<" living City :"<<s.livingCity<<endl;
if(s.id==help && strcmp(s.Borncity,s.livingCity)==0){
cout<<"\nlocal student \n\n\n";
break;}
break;}
}
if(s.id!=help){
cout<<"not found !!!\n";
}
}