hamzabaloch
salam sir yasir,
sir main ap ke pehli assignment per kam kar raha ho per ic main kuch problem aa rahay  hain please help me main nay bohat search ke per mujha solutions nai mil raha 
meray problem void insertRecord(struct Product pro[]); method main aa raha ha main jab user sa data la lata ho ic ka bad array of structure ko file main store karata to program end ho jata ha please help me sir

#include<iostream>
#include<conio.h>
#include<fstream>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;

struct Product
{
int productID;
string productName;
int productQuantaty;
float price;
string inStock;

};

void insertRecord(struct Product pro[]) {
for(int i=0; i<2; i++) {
pro[i].productID = i+1;
cin.ignore();
cout<<"enter the porduct name ";
getline(cin, pro[i].productName);
cout<<"enter the Porduct quantaty";
cin>>pro[i].productQuantaty;
cout<<"enter the price";
cin>>pro[i].price;
cin.ignore();
cout<<"is available product";
getline(cin,pro[i].inStock);
//cout<<pro[i].productName<<pro[i].productID<<pro[i].productQuantaty<<pro[i].price<<pro[i].inStock<<endl;


}

int i = 0;
ofstream ofile;
ofile.open("productdata.txt", ios:[redface]ut,ios::app);
while( i < 2) {

ofile.write((char *) &pro[i], sizeof(Product));
//ofile<<endl;
i++;
}
ofile.close();


}

void editRecord() {

}
void viewRecord(struct Product pro[]) {
//system("CLS");
cout<<"************************available porducts in store******************************"<<endl;
int i=0;
while(i<2) {
cout<<"productId: "<<pro[i].productID<<" Product Name: "<<pro[i].productName<<" Remaining Quantaty: "<<pro[i].productQuantaty<<" Product Price: "<<pro[i].price<<" Instock: "<<pro[i].inStock<<endl;
i++;
}
}

 

bool checkInput(int i,int proId, int proQuantaty, struct Product pro[], struct Product purchaseItems[]) {
cout<<"in checkinput"<<i;
for(int j=i; j<=i; j++) {
for(int k=0; k<2; k++) {
if(proId == pro[k].productID) {
if(proQuantaty <= pro[k].productQuantaty) {
purchaseItems[i].productQuantaty = pro[k].productQuantaty;
purchaseItems[i].productID = pro[k].productID;
purchaseItems[i].productName = pro[k].productName;
pro[k].productQuantaty = pro[k].productQuantaty - proQuantaty;
purchaseItems[i].price = pro[k].price;
return true;
break;
}else {
cout<<j;
cout<<"you enter the quantity above then availeble stock again enter"<<endl;
return false;
break;
}
}
}
cout<<"you enter the worng porduct id "<<endl;
return false;
}
}

void displayOrder(int k, struct Product purchaseItems[]) {
cout<<"*********************your order right now*****************"<<endl;
for (int i = 0; i <= k; i++) {
cout<<"porduct id is :"<<purchaseItems[i].productID<<endl;
cout<<"porduct Names is :"<<purchaseItems[i].productName<<endl;
cout<<"porduct Quantaty is :"<<purchaseItems[i].productQuantaty<<endl;
cout<<"porduct price is :"<<purchaseItems[i].price<<endl;
}
}
void ordercheckOut(struct Product purchaseItems[], int j) {
float toatalPrice = 0;
string customerName;
string customerAddress;
int atmNumber;
cin.ignore();
cout<<"enter your name "<<endl;
getline(cin,customerName);
cin.ignore();
cout<<"enter your address"<<endl;
getline(cin,customerAddress);
cout<<"enter four digit the atm numbre"<<endl;
cin>>atmNumber;
cout<<"enter your six digit ATM Number "<<endl;
cout<<"*************************** your order items *****************************"<<endl;
for(int i=0; i<=j; i++) {
cout<<" Product #"<<i<<endl;
cout<<" porduct Name "<<purchaseItems[i].productName<<" porduct Quantaty "<<purchaseItems[i].productQuantaty<<"porduct Price for single itme "<<purchaseItems[i].price<<" porduct Product Price on "<<purchaseItems[i].productQuantaty<<" items"<<purchaseItems[i].price * purchaseItems[i].productQuantaty<<endl;
}

for(int i=0; i<=j; i++) {
float price = purchaseItems[i].price * purchaseItems[i].productQuantaty;
toatalPrice = toatalPrice + price;
}
cout<<"Total purchasing bill "<<toatalPrice<<endl;
cout<<"thanks for purchasing ";

////creating bill slip
ofstream ofile;
////ofile.open("product/bill/"+customerName+".txt");
ofile.open("bills/"+customerName+".txt", ios:[redface]ut);
string demiName;
int demiQuantaty;
float demiSinglePrice;
float demiNetPrice;
ofile<<"************ your order items *****************"<<endl;
ofile<<"your name :"<<customerName<<endl;
ofile<<"your address :"<<customerAddress<<endl;
ofile<<atmNumber<<endl;
for(int i=0; i<=j; i++) {
ofile<<" Product #"<<i<<endl;
string demiName = purchaseItems[i].productName;
int demiQuantaty = purchaseItems[i].productQuantaty;
float demiSinglePrice = purchaseItems[i].price;
float demiNetPrice = purchaseItems[i].price * purchaseItems[i].productQuantaty;
ofile<<" porduct Name :"<<demiName<<endl<<" porduct Quantaty "<<demiQuantaty<<endl<<"porduct Price for single itme "<<demiSinglePrice<<endl<<" porduct Product Price on "<<demiQuantaty<<" items ="<<demiNetPrice<<endl;
}

for(int i=0; i<=j; i++) {
float price = purchaseItems[i].price * purchaseItems[i].productQuantaty;
toatalPrice = toatalPrice + price;
}
ofile<<"Total purchasing bill :"<<toatalPrice<<endl;
ofile<<"thanks for purchasing ";

ofile.close();


}
void shoping(struct Product pro[],struct Product purchaseItems[]) {
char ch;
cout<<"Press Y or y for shoping "<<endl;
cin>>ch;
int i = 0;
int remaningProduct = 5;
if(ch == 'y' || ch == 'Y') {
char morePurchase;
char checkOutOrder;
int porId;
int proQuantaty;
bool repeat;
cout<<"********According to store policy you can buy 5 different items at one time*********"<<endl;

do {
cout<<"-----------------------------------------------------------------------"<<i<<endl;
if(i>0) {

cout<<"please enter the product id that you want to buy"<<endl;
cin>>porId;
cout<<"enter the quantaty you want to buy"<<endl;
cin>>proQuantaty;
cout<<"Remaning Product you can Purchase :"<<remaningProduct-i<<endl;
repeat = checkInput(i, porId, proQuantaty, pro, purchaseItems);
if(repeat != true) {
i--;
}
displayOrder( i, purchaseItems);
viewRecord( pro );
cout<<"If you want to Conform your order then press O button"<<endl;
cout<<"if want to buy some more thing then press y"<<endl;
cin>>morePurchase;
if(morePurchase == 'o' || morePurchase == 'O') {
ordercheckOut(purchaseItems,i);
}
} else {
cout<<"please enter the product id that you want to buy"<<endl;
cin>>porId;
cout<<"enter the quantaty you want to buy"<<endl;
cin>>proQuantaty;
cout<<"Remaning Product you can Purchase :"<<remaningProduct-i<<endl;
repeat = checkInput(i, porId, proQuantaty, pro, purchaseItems);
if(repeat != true) {
i--;
}
displayOrder( i, purchaseItems);
viewRecord( pro );
cout<<"If you want to Conform your order then press O button"<<endl;
cout<<"If you want to purchase more items then press y button"<<endl;
cin>>morePurchase;
if(morePurchase == 'o' || morePurchase == 'O') {
ordercheckOut(purchaseItems,i);
}
}
//cout<<"before"<<i;
i++;
cout<<"after"<<i;
} while(morePurchase == 'y' || morePurchase == 'Y');
}
/*
cout<<"************************available porducts in store******************************"<<endl;
int i=0;
while(i<2) {
cout<<"productId: "<<pro[i].productID<<" Product Name: "<<pro[i].productName<<" Remaining Quantaty: "<<pro[i].productQuantaty<<" Product Price: "<<pro[i].price<<" Instock: "<<pro[i].inStock<<endl;
i++;
}
*/
}

void main () {
Product pro[2];
Product purchaseItems[2];
char ch;
do {
char choice;
cout<<"*************************** SELECT ********************************"<<endl;
cout<<"******** EDIT ********** press E *"<<endl;
cout<<"******** View *********** press V *"<<endl;
cout<<"******** Insert ********** press i *"<<endl;
cout<<"******** Shoping ********** press s *"<<endl;

cout<<"enter your choice "<<endl;
cin>>choice;
//cin.ignore();
if(choice=='e' || choice=='E') {
editRecord();
} else if (choice=='I' || choice=='i') {
insertRecord(pro);
} else if (choice=='v' || choice=='V') {
viewRecord(pro);
} else if (choice=='s' || choice=='S') {
viewRecord(pro);
shoping(pro,purchaseItems);
}
cout<<"for continue Y ";
cin>>ch;
} while(ch == 'y' || ch == 'Y');

 


/*
int i=0;
while(i<2) {
cout<<pro[i].productName<<pro[i].productID<<pro[i].productQuantaty<<pro[i].price<<pro[i].inStock<<endl;
i++;
}
*/

}

 

Quote 0 0
geniusyasee
hi, sorry for late reply, i am not feeling good due to some sickness,,, ok what i think the problem is when you pass the array to function then u have to pass the number of indexes it is going to hold along side it, ofcourse array is already defined then u need to pass the size to it and it is the same with structure array. u can not access an array with unlimmited memoray locations, as it continuous memory location reserved so u need to tell how many,, and when u pass array it is pass by ref automatically, so u have to tell. thats what my first observation, secondly i really dont know what kind of error it is generating for u,,, just attach the code file then i will look into it

regards
yasir
Quote 0 0
geniusyasee
it could be like void insert(struct product pro[],int size) so when u call this function u tell how many products this array can store then u can access this array in ur function
Quote 0 0

Add a Website Forum to your website.

 
Urdu IT Accademy � 2013 | License Agreement