Comp Proj
Comp Proj
h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
void border()
{
for(int i=1;i<80;i++)
{
gotoxy(i,1);cout<<"*";
gotoxy(i,25);cout<<"*";
}
for(i=1;i<25;i++)
{
gotoxy(1,i);cout<<"*";
gotoxy(80,i);cout<<"*";
}
}
class customer
{
long double c_code, pincode; //c_code is for customer code
char firstname[30], lastname[30], contactno[15], address[60],
city[20], country[20], email[50];
public:
void getdata()
{
cout<<"* Customer Code: ";
cin>>c_code;
cout<<"* First Name: ";
gets(firstname);
cout<<"* Last Name: ";
gets(lastname);
cout<<"* Contact No: ";
cin>>contactno;
cout<<"* Email: ";
gets(email);
cout<<"* Address: ";
gets(address);
cout<<"* City: ";
gets(city);
cout<<"* Pincode: ";
cin>>pincode;
cout<<"* Country: ";
gets(country);
}
void putdata()
{
cout<<endl<<"* Customer Code: "<<c_code<<endl;
cout<<"* First Name: "<<firstname<<endl;
cout<<"* Last Name: "<<lastname<<endl;
cout<<"* Contact No: "<<contactno<<endl;
cout<<"* Email: "<<email<<endl;
cout<<"* Address: "<<address<<endl;
cout<<"* City: "<<city<<endl;
cout<<"* Pincode: "<<pincode<<endl;
cout<<"* Country: "<<country<<endl;
cout<<"*_________________________________________________________________
____________";
}
long double getc_code()
{
return c_code;
}
int comparename(char comp[30])
{
if(strcmpi(comp,firstname)==0)
{
return 1;
}
else
{
return 0;
}
}
};
void c_insert()
{
clrscr();
border();
gotoxy(1,1);
cout<<endl<<endl<<"* Enter Details of Customer"<<endl<<endl;
fstream f("customer.dat", ios::binary|ios::out|ios::app);
customer c;
c.getdata();
f.write((char*)&c,sizeof(c));
f.close();
cout<<endl<<"* Record has been inserted";
}
void c_displayall()
{
clrscr();
border();
fstream f("customer.dat",ios::binary|ios::in);
customer c;
while(f.read((char*)&c,sizeof(c)))
{
clrscr();
border();
gotoxy(1,5);
cout<<endl<<endl;
c.putdata();
cout<<endl<<endl<<"* Press any key to continue";
getch();
}
f.close();
border();
}
void c_search1()
{
fstream f("customer.dat",ios::binary|ios::in);
customer c;
long double value;
cout<<"* Enter Customer Code: ";
cin>>value;
int found=0;
while(f.read((char*)&c,sizeof(c)))
{
if(value==c.getc_code())
{
c.putdata();
found=1;
break;
}
}
if(found==0)
{
cout<<"* Customer does not exist";
}
f.close();
}
void c_search2()
{
fstream f("customer.dat",ios::binary|ios::in);
customer c;
long double value;
cout<<"* Enter First Name: ";
gets(value);
int found=0;
while(f.read((char*)&c,sizeof(c)))
{
if(c.comparename(value)==1)
{
c.putdata();
found=1;
break;
}
}
if(found==0)
{
cout<<"* Customer does not exist";
}
f.close();
}
void c_modify()
{
clrscr();
border();
gotoxy(1,1);
fstream f("customer.dat",ios::binary|ios::in|ios::out);
customer c;
long double value;
cout<<endl<<"* Enter Customer Code: ";
cin>>value;
gotoxy(1,2);
int found=0,pos;
while(f.read((char*)&c,sizeof(c)))
{
if(value==c.getc_code())
{
pos=f.tellg();
c.putdata();
found=1;
cout<<endl<<"* Enter new details"<<endl;
c.getdata();
f.seekp(pos-sizeof(c),ios::beg);
f.write((char*)&c,sizeof(c));
cout<<endl<<"* Record has been modified";
break;
}
}
if(found==0)
{
cout<<"* Customer does not exist";
}
f.close();
}
void c_delete()
{
clrscr();
border();
gotoxy(1,1);
fstream f1("customer.dat",ios::binary|ios::in);
fstream f2("temp.dat",ios::binary|ios::out);
customer c;
int found=0;
char confirm ='y';
long double value;
cout<<endl<<endl<<"* Enter Customer Code: ";
cin>>value;
while(f1.read((char*)&c, sizeof(c)))
{
if(value==c.getc_code())
{
c.putdata();
found=1;
cout<<endl<<"* Are you sure to delete: " ;
cin>>confirm;
if((confirm =='n')||(confirm=='N'))
{
f2.write((char*)&c,sizeof(c));
}
else
{
cout<<endl<<"* Record Deleted";
}
}
else
{
f2.write((char*)&c,sizeof(c));
}
}
f1.close();
f2.close();
remove("customer.dat");
rename("temp.dat","customer.dat");
if(found==0)
{
cout<<"* Customer does not exist";
}
}
class hardware
{
int pcode;
char name[20];
float price;
char manufacturer[20];
long date;
int units;
char madein[20];
char supplier[20];
public :
void h_input();
void h_display();
int h_getpcode();
int comparename(char pname[20])
{
if(strcmpi(pname,name)==0)
{
return 1;
}
else
{
return 0;
}
}
};
void hardware::h_input()
{
cout<<endl<<"* Product Code: "; cin>>pcode;
cout<<"* Product Name: "; gets(name);
cout<<"* Price: "; cin>>price;
cout<<"* Manufacturer: "; gets(manufacturer);
cout<<"* Date of Manufacture (DDMMYY): "; cin>>date;
cout<<"* No. of Units: "; cin>>units;
cout<<"* Made In: "; gets(madein);
cout<<"* Supplier: "; gets(supplier);
}
void hardware::h_display()
{
cout<<endl<<"* Product Code: "<<pcode;
cout<<endl<<"* Product Name: "<<name;
cout<<endl<<"* Price: "<<price;
cout<<endl<<"* Manufacturer: "<<manufacturer;
cout<<endl<<"* Date of Manufacture: "<<date;
cout<<endl<<"* No. of Units: "<<units;
cout<<endl<<"* Made In: "<<madein;
cout<<endl<<"* Supplier: "<<supplier<<endl;
cout<<"*_________________________________________________________________
____________";
}
int hardware::h_getpcode()
{
return pcode;
}
void insert()
{
clrscr();
border();
gotoxy(1,1);
cout<<endl<<endl<<"* Enter Details of New Product"<<endl;
ofstream f("hardware.dat",ios::binary|ios::app);
hardware h;
h.h_input();
f.write((char*)&h,sizeof(h));
f.close();
}
void display()
{
clrscr();
border();
fstream f("hardware.dat",ios::binary|ios::in);
hardware h;
while(f.read((char*)&h,sizeof(h)))
{
clrscr();
border();
gotoxy(1,5);
cout<<endl<<endl;
h.h_display();
cout<<endl<<"* Press any key to continue";
getch();
}
f.close();
border();
}
void search1()
{
int code,found=0;
cout<<"* Enter Product Code: ";cin>>code;
fstream f("hardware.dat",ios::binary|ios::in);
hardware h;
while(f.read((char*)&h,sizeof(h)))
{
if(code==h.h_getpcode())
{
found=1;
h.h_display();
break;
}
}
if(found==0)
{
cout<<"* No such Product Exists";
}
f.close();
}
void search2()
{
char pname[20];
int found=0;
cout<<"* Enter Product Name: ";gets(pname);
fstream f1("hardware.dat",ios::binary|ios::in);
hardware h;
while(f1.read((char*)&h,sizeof(h)))
{
if(h.comparename(pname)==1)
{
found=1;
h.h_display();
break;
}
}
if(found==0)
{
cout<<"* No such Product Exists";
}
f1.close();
}
void search()
{
clrscr();
int ch;
border();
gotoxy(25,3);cout<<"Search Options";
gotoxy(20,5);cout<<"1. By Product Code";
gotoxy(20,6);cout<<"2. By Product Name";
gotoxy(20,8);cout<<"Enter Your Choice: ";cin>>ch;
switch(ch)
{
}
}
void modify()
{
clrscr();
border();
int code;
gotoxy(1,1);
cout<<endl<<"* Enter Product Code: "; cin>>code;
fstream f("hardware.dat",ios::binary|ios::out|ios::in);
hardware h;
int found=0;long pos;
while(f.read((char*)&h,sizeof(h)))
{
pos=f.tellg();
if(code==h.h_getpcode())
{
found=1;
cout<<"* Record is: \n";
h.h_display();
f.write((char*)&h,sizeof(h));
cout<<endl<<"* Record Modified";
break;
}
} if(found==0)
cout<<"* No Such Record Exists ";
f.close();
}
void delete_()
{
clrscr();
border();
gotoxy(1,1);
fstream f1("hardware.dat",ios::binary|ios::in);
fstream f2("temp.dat",ios::binary|ios::out);
hardware h;
int found=0;
int code;
char ch='y';
cout<<endl<<endl<<"* Product Code: "; cin>>code;
while(f1.read((char*)&h,sizeof(h)))
{
if(code==h.h_getpcode())
{
h.h_display();
found=1;
cout<<endl<<"* Are You Sure To Delete ? ";cin>>ch;
if(ch=='n'||ch=='N')
f2.write((char*)&h,sizeof(h));
else
cout<<endl<<"* Record Deleted...";
}
else
f2.write((char*)&h,sizeof(h));
}
f1.close(); f2.close();
remove("hardware.dat");
rename("temp.dat","hardware.dat");
if(found==0)
cout<<"* No Such Record Exists ";
}
void main()
{
clrscr();
int select=0;
while(select!=3)
{
clrscr();
border();
gotoxy(20,3);cout<<"------Hardware Shop Operations-----";
gotoxy(25,6);cout<<"1. Hardware Products";
gotoxy(25,7);cout<<"2. Customer Information";
gotoxy(25,8);cout<<"3. Exit";
gotoxy(25,10);cout<<"Enter Your Selection: "; cin>>select;
switch(select)
{
case 1 :
clrscr();
int choice=0;
while(choice!=6)
{
clrscr();
border();
switch(choice)
{
case 1 : insert();
getch();
break;
case 2 : display();
getch();
break;
case 3 : search();
getch();
break;
case 4 : modify();
getch();
break;
case 5 : delete_();
getch();
break;
}
break;
case 2 :
clrscr();
int choice0=0,choice1=0;
while(choice!=6)
{
clrscr();
border();
gotoxy(20,3);cout<<"_____Customer Operations_____";
gotoxy(25,6);cout<<"1. New Customer";
gotoxy(25,7);cout<<"2. Display All Customers";
gotoxy(25,8);cout<<"3. Search Customer";
gotoxy(25,9);cout<<"4. Modify Customer";
gotoxy(25,10);cout<<"5. Delete Customer";
gotoxy(25,11);cout<<"6. Exit";
gotoxy(25,13);cout<<"Enter Your Choice: ";cin>>choice0;
switch(choice0)
{
case 1: c_insert();
getch();
break;
case 2: c_displayall();
getch();
break;
case 3: clrscr();
border();
gotoxy(25,3);cout<<"Search Options";
gotoxy(20,5);cout<<"1. By Customer Code";
gotoxy(20,6);cout<<"2. By Customer Name";
gotoxy(20,8);cout<<"Enter Your Choice:
";cin>>choice1;
if(choice1==1)
{
c_search1();
getch();
}
else if(choice1==2)
{
c_search2();
getch();
}
else
{
cout<<endl<<"* Enter valid choice";
getch();
}
break;
case 4: c_modify();
getch();
break;
case 5: c_delete();
getch();
break;
}}
}