farman-h
01-07-2010, 17:36
سلام خدمت دوستان بايد پروژه انبار بنويسم با فايلها اينجاش فعلا گير کردم
کسي از دوستان ککمکم کنه.پروژه هم اينجوريه ميخوام 6تا ماشين وارد کنم البته بجاي ماشين از عدد استفاده کردم بعدش ميخوام به هر ماشين قطعه هاشو اضافه کنم مثلا اگه ماشين شماره 1 رو زدم بتونم بهش قطعه اضافه کنم
هر قطعه هم شامل نام و جنس و وزن و قيمت ميباشد ولي هر کاري کردم قطعه ها رو اضافه نکرد.کمک کنيد لطفا پروژمه
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
//////////////////////
class product{
public:
char shomara[1];
char p_num[4];
char mat[1];
float wight;
float cost;
public:
void insertCar(product p,char fname[30]);
void insertPiece(product p,char shomara2[1],char fname[30]);
};
//////////////////////////////////////////////////////////////////////
void product::insertCar(product p,char fname[30])
{
fstream f;
f.open(fname,ios::app);
if(!f)
{
cout<<"file not found";
}
else
{
f<<shomara<<"*"<<"\n";
}
f.close();
}
////////////////////////////////////////////////////////////////////////
void product::insertPiece(product p,char shomara2[1],char fname[30])
{
fstream f;
char temp[30];
char ch;
f.open(fname,ios::app);
if(!f)
cout<<"file not found";
else if (shomara2=="1")
{
while(!f.fail()){
f>>ch;
int i=0;
while(ch!='*'){
temp[i]=ch;
i++;
f>>ch;
}
//if(strcmp(shomara2,temp)==0){
f.seekp(i,ios::cur);
f<<p_num<<"*"<<mat<<"*"<<wight<<"*"<<cost;
// }
// else
// f.seekg(i,ios::cur);
}
}
f.close();
}
//////////////////////////////////////////////////////////////////////////
int main()
{
char shomara2[1];
product p;
int choice;
cout<<"1-insertCar"<<endl;
cout<<"2-insertPiece"<<endl;
cout<<"3_show"<<endl;
cin>>choice;
if(choice==1){
cout<<"enter product's name"<<endl;
cin>>p.shomara;
p.insertCar(p,"c:\\products.txt");
}
else if(choice==2)
{
cout<<"please enter number 1 to 6:\n1=paikan\n2=pride\n3=pjo206\n4=pjo405\n5=l90\n 6=zantia\n"<<endl;
cout<<"enter your number machine:";
cin>>shomara2;
cout<<"\nenter your name piece"<<endl;
cin>>p.p_num;
cout<<"\nenter your mat piece"<<endl;
cin>>p.mat;
cout<<"\nenter your wight piece"<<endl;
cin>>p.wight;
cout<<"\nenter your cost piece"<<endl;;
cin>>p.cost;
p.insertPiece(p,shomara2,"c:\\products.txt");
}
else if(choice==3)
{
}
getch();
return 0;
}
کسي از دوستان ککمکم کنه.پروژه هم اينجوريه ميخوام 6تا ماشين وارد کنم البته بجاي ماشين از عدد استفاده کردم بعدش ميخوام به هر ماشين قطعه هاشو اضافه کنم مثلا اگه ماشين شماره 1 رو زدم بتونم بهش قطعه اضافه کنم
هر قطعه هم شامل نام و جنس و وزن و قيمت ميباشد ولي هر کاري کردم قطعه ها رو اضافه نکرد.کمک کنيد لطفا پروژمه
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
//////////////////////
class product{
public:
char shomara[1];
char p_num[4];
char mat[1];
float wight;
float cost;
public:
void insertCar(product p,char fname[30]);
void insertPiece(product p,char shomara2[1],char fname[30]);
};
//////////////////////////////////////////////////////////////////////
void product::insertCar(product p,char fname[30])
{
fstream f;
f.open(fname,ios::app);
if(!f)
{
cout<<"file not found";
}
else
{
f<<shomara<<"*"<<"\n";
}
f.close();
}
////////////////////////////////////////////////////////////////////////
void product::insertPiece(product p,char shomara2[1],char fname[30])
{
fstream f;
char temp[30];
char ch;
f.open(fname,ios::app);
if(!f)
cout<<"file not found";
else if (shomara2=="1")
{
while(!f.fail()){
f>>ch;
int i=0;
while(ch!='*'){
temp[i]=ch;
i++;
f>>ch;
}
//if(strcmp(shomara2,temp)==0){
f.seekp(i,ios::cur);
f<<p_num<<"*"<<mat<<"*"<<wight<<"*"<<cost;
// }
// else
// f.seekg(i,ios::cur);
}
}
f.close();
}
//////////////////////////////////////////////////////////////////////////
int main()
{
char shomara2[1];
product p;
int choice;
cout<<"1-insertCar"<<endl;
cout<<"2-insertPiece"<<endl;
cout<<"3_show"<<endl;
cin>>choice;
if(choice==1){
cout<<"enter product's name"<<endl;
cin>>p.shomara;
p.insertCar(p,"c:\\products.txt");
}
else if(choice==2)
{
cout<<"please enter number 1 to 6:\n1=paikan\n2=pride\n3=pjo206\n4=pjo405\n5=l90\n 6=zantia\n"<<endl;
cout<<"enter your number machine:";
cin>>shomara2;
cout<<"\nenter your name piece"<<endl;
cin>>p.p_num;
cout<<"\nenter your mat piece"<<endl;
cin>>p.mat;
cout<<"\nenter your wight piece"<<endl;
cin>>p.wight;
cout<<"\nenter your cost piece"<<endl;;
cin>>p.cost;
p.insertPiece(p,shomara2,"c:\\products.txt");
}
else if(choice==3)
{
}
getch();
return 0;
}