help me with this error (expected unqualified- id before '{' token ) the bold codings

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>


using namespace std;



class product


{
int pID;
char name [50];
float price, qty;
public:
void create_product ()
{
cout<<"\nPlease Enter The Product ID of the product ";
cin>>pID;
cout<<"\nPlease enter the Name of the Product";
gets(name);
cout<<"\nPlease enter the price of the Product";
cin>>price ;

}
void show_product()
{
cout<<"\nThe Product ID of the Product :"<<pID;
cout<<"\nThe Name of the product :";
puts(name);

}

int retpID()
{return pID; }

float retprice()
{return price;}

char* retname()
{return name;}

};

//declaration for the stream object

fstream fp;
product pr;

//function to write in file

void write_product();
{

fp.open("Shop.dat",ios::|ios::app);
pr.create_product();
fp.write((char*)&pr,sizeof(product));
fp.close();
cout<<"\n\nTHE PRODUCT HAS BEEN CREATED";
system("pause");

}

//functions to read records form file

void display_all()
{
system("cls");
cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
pr.show_product();
cout<<"\n\n==========================\n";
system("pause");
}
fp.close();
system("pause");
}

//function to read specific record from file

void display_sp(int n)
{
int flag=0;
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
if (pr.retpID()==n)
{
system("cls");
pr.show_product();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
system("pause");
}

//function to modify record of file

void modify_product();
{

int no, found=0;
system("cls");
cout<<"\n\nTo Modify";
cout<<"\n\n\tPlease Enter the Product ID of the product";
cin>>ID;
fp.open("Shop.dat",ios::in|ios::out);
while(fp.read((char*)&pr,sizeof(product))&& found==0)
{
if(pr.retpID()==ID)
{
pr.show_product();
cout<<"\nPlease Enter The New Details Of Product"<<endl;
pr.create_product();
int pos=-1*sizeof(pr);
fp.seekp(pos,ios::cur);
fp.write((char*)&pr,sizeof(product));
cout<<"\n\n\tRECORD UPDATED";
found=1;

}
fp.close();
if(found==0)
cout<<"\n\nRECORD NOT FOUND";
system("pause");
}
}
//function to delete record of file

void delete_product()
{
int no;
system ("cls");
cout<<"\n\n\nDelete Record";
cout<<"\n\nPlease Enter the Product ID of the product You want to delete";
cin>>ID;
fp.open("Shop.dat",ios::in|ios::out);
fstream.fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpID()!=ID)
{
fp2.write((char*)&pr,sizeof(product));

}
}
fp2.close();
fp.close();
remove("Shop.dat");
rename("Temp.dat","Shop.dat");
cout<<"\n\n\t..RECORD DELETED...";
system("pause");

}


//function to display all product price list

void menu()
{
system("cls");
fp.open("Shop.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\nGO TO ADMIN MENU TO CREATE FILE";
cout<<"\n\n\n:::Program is Closing:::";
system("pause");
exit(0);

}
cout<<"\n\n\t\tPRODUCT MENU\n\n";
cout<<"**************************************\n";
cout<<"P.ID\tNAME\tPRICE\n";
cout<<"**************************************\n";
while(fp.read((char*)&pr,sizeof(product)))
{
cout<<pr.retpID()<<"\t\t"<<pr.retname()<<"\t\t"<<pr.retprice()<<endl;

}
fp.close();
}


//function to place order and generate bill for products

void place_order()
{
int order_arr[50],quan[50],c=0;
float amt,total=0;
char ch='Y';
menu();
cout<<"\n=======================";
cout<<"\n STATE YOUR ORDER ";
cout<<"\n=======================";
do
{
cout<<"\n\nEnter The Product ID of the product :";
cin>>order_arr[c];
cout<<"\nQuantity in number :";
cin>>quan[c];
c++;
cout<<"\nDo You Want Another Product ? (y/n)";
cin>>ch;
}while (ch=='y'||ch=='Y');
cout<<"\n\nThank You For Placing The Order";
system("cls");
system("pause");
cout<<"\n\n******INVOICE*********\n";
cout<<"\nPr ID \tPr Name\tQuantity\tAmount\tAmount after %\n";
for(int x=0;x<=c;x++)
{
fp.open("Shop.dat",ios::in);
fp.read((char*)&pr,sizeof(product));
while(!fp.eof())
{
if(pr.retpID()==order_arr[x])
{
amt=pr.retprice()*quan[x];

cout<<"\n"<<order_arr[x]<<"\t"<<pr.retname()<<"\t"<<quan[x]<<"\t\t"<<pr.retprice()<<"\t"<<amt;
total+=damt;
}
fp.read((char*)&pr,sizeof(product));
}
fp.close();
}
cout<<"\n\n\t\t\t\tTOTAL = "<<total;
system("pause")();

}

//admin menu function

void admin_menu()
{
system("cls");
char ch2;
cout<<"\n\n\n\tADMIN MENU";
cout<<"\n\n\t1.CREATE PRODUCT";
cout<<"\n\n\t2.DISPLAY ALL PRODUCTS";
cout<<"\n\n\t3.QUERY";
cout<<"\n\n\t4.MODIFY PRODUCT";
cout<<"\n\n\t5.DELETE PRODUCT";
cout<<"\n\n\t6.VIEW PRODUCT MENU";
cout<<"\n\n\t7.BACK TO MAIN MENU";
cout<<"\n\n\t8.Please Enter Your Choice (1-7)";
ch2=getche();
switch(ch2)
{
case '1' : system("pause");
write_product();
break;
case '2' : display_all();break;
case '3' : int num;
system ("cls");
cout<<"\n\n\tPlease Enter The Product ID";
cin>>num;
display_sp(num);
break;
case '4' : modify_product();break;
case '5' : delete_product();break;
case '6' : menu();
system("pause");
case '7' : break ;
default : cout<<"<<\a";admin_menu()
}
}

//main function of the program

void main ()
{
char chl
intro();
do
{
system("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01.CUSTOMER";
cout<<"\n\n\t02.ADMINISTRATOR";
cout<<"\n\n\t03.EXIT";
cout<<"\n\n\tPLEASE CHOOSE YOUR OPTION (1-3)";
ch=getche();
switch(ch)
{
case '1' : system("cls");
place_order();
system("pause");
break;
case '2' : admin_menu();
break;
case '3' : exit(0)
default :cout<<"\a";

}while(ch!='3');
}

}
return 0;

closed account (o3hC5Di1)
Hi there,

You need to remove the ';' at the end of the declarator:

1
2
void write_product(); // <-- remove the ;
{


Hope that helps.

All the best,
NwN
Topic archived. No new replies allowed.