Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
- char item[10][10];
- int price[10];
- int stock[10];
- int cnt=0;
- void insert();
- void view();
- void edit();
- void search();
- void main(){
- int opt;
- clrscr();
- cout<<"1. insert\n2. view\n3. edit\n4. search\n5. exit"<<endl;
- cin>>opt;
- switch(opt){
- case 1: insert(); break;
- case 2: view(); break;
- case 3: edit(); break;
- case 4: search(); break;
- default: exit(0);
- }
- }
- void insert(){
- char nitem[10];
- int nprice, nstock;
- clrscr();
- cout<<"enter new item"<<endl;
- cin>>nitem;
- cout<<"enter price"<<endl;
- cin>>nprice;
- cout<<"enter stock"<<endl;
- cin>>nstock;
- strcpy(item[cnt],nitem);
- price[cnt] = nprice;
- stock[cnt] = nstock;
- cnt++;
- cout<<"Item added successful..."<<endl;
- system("pause");
- main();
- }
- void view(){
- clrscr();
- cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
- for(int i=0;i<10;i++){
- if(stock[i]!=0){
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
- }
- else{
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
- }
- }
- system("pause");
- main();
- }
- void edit(){
- char eitem[10];
- int opt,sel,eprice=0,estock=0;
- cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
- for(int i=0;i<10;i++){
- if(stock[i]!=0){
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
- }
- else{
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
- }
- }
- cout<<"Input ID: "<<endl;
- cin>>opt;
- clrscr();
- cout<<"Edit for:"<<endl;
- cout<<"1. Item\n2. Price\n3. Stock"<<endl;
- cin>>sel;
- switch(sel){
- case 1:
- cout<<"enter New Item"<<endl;
- cin>>eitem;
- strcpy(item[opt],eitem);
- cout<<"Edit successful..."<<endl;
- system("pause");
- main();
- case 2:
- cout<<"enter New price"<<endl;
- cin>>eprice;
- price[opt]=eprice;
- cout<<"Edit successful..."<<endl;
- system("pause");
- main();
- case 3:
- cout<<"enter New stock"<<endl;
- cin>>estock;
- stock[opt]=estock;
- cout<<"Edit successful..."<<endl;
- system("pause");
- main();
- default: main();
- }
- }
- void search(){
- char sitem[10];
- int opt,sprice,sid;
- clrscr();
- cout<<"search for: "<<endl;
- cout<<"1. ID\n2. item\n3. price"<<endl;
- cin>>opt;
- switch(opt){
- case 1:
- cout<<"enter ID: ";
- cin>>sid;
- clrscr();
- cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
- if(stock[sid]!=0){
- cout<<sid<<"\t"<<item[sid]<<"\t\t"<<price[sid]<<"\t\t"<<stock[sid]<<endl;
- }
- else{
- cout<<sid<<"\t"<<item[sid]<<"\t\t"<<price[sid]<<"\t\t"<<"out of stock"<<endl;
- }
- system("pause");
- main();
- break;
- case 2:
- cout<<"enter item: ";
- cin>>sitem;
- clrscr();
- cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
- for(int i=0;i<10;i++){
- if(strcmp(sitem,item[i])==0){
- if(stock[i]!=0){
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<endl;
- }
- else{
- cout<<i<<"\t"<<item[i]<<"\t\t"<<price[i]<<"\t\t"<<"out of stock"<<endl;
- }
- }
- }
- system("pause");
- main();
- break;
- case 3:
- cout<<"enter price: ";
- cin>>sprice;
- clrscr();
- cout<<"ID\tITEM\t\tPRICE\t\tSTOCK"<<endl;
- for(int d=0;d<10;d++){
- if(price[d]==sprice){
- if(stock[d]!=0){
- cout<<d<<"\t"<<item[d]<<"\t\t"<<price[d]<<"\t\t"<<stock[d]<<endl;
- }
- else{
- cout<<d<<"\t"<<item[d]<<"\t\t"<<price[d]<<"\t\t"<<"out of stock"<<endl;
- }
- }
- }
- system("pause");
- main();
- break;
- case 5: main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement