Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <string.h>
- #include <fstream>
- #include <cstring>
- #include <string>
- #include <conio.h>
- #include <stdlib.h>
- #include <iomanip>
- using namespace std;
- class item
- {
- private:
- int code;
- char name[15];
- int Qty;
- public:
- void get_item(void);
- void put_item(void);
- int get_code(void)
- {
- return code;
- }
- void update_Qty(int num)
- {
- Qty=Qty-num;
- }
- };
- void item :: get_item(void)
- {
- cout<<"Vyvedi nomera na kniga:"; cin>>code;
- fflush(stdin);
- cout<<"Vyvedi zaglavie na kniga:"; cin>>name;
- cout<<"Vyvedi kolichestvo:"; cin>>Qty;
- }
- void item:: put_item(void)
- {
- cout<<setw(6)<<code
- <<setw(15)<<name
- <<setw(6)<<Qty<<endl;
- }
- void add_record(void);
- void show_record(void);
- void show_All(void);
- void delete_record(void);
- void modify_record(void);
- item it;
- fstream file;
- int main()
- {
- int option;
- while(1)
- { system("cls");
- cout<<"***Menu**"<<endl;
- cout<<"1.Dobavi nov zapis"<<endl;
- cout<<"2.Pokaji vsichki zapisi"<<endl;
- cout<<"3.Pokaji izbran zapis"<<endl;
- cout<<"4.Iztrii zapis"<<endl;
- cout<<"5.Redaktirai zapis"<<endl;
- cout<<"6.Izhod"<<endl;
- cout<<"Izberi opciq No.: "; cin>>option;
- switch(option)
- {
- case 1:{ add_record();
- cout<<"Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- case 2:{
- cout<<"--------------------------------------------\n";
- cout<<setw(6)<<"Code"<<setw(15)<<"Name"<<setw(6)<<"Qty"<<endl;
- cout<<"--------------------------------------------\n";
- show_All();
- cout<<"--------------------------------------------\n";
- cout<<"Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- case 3:{
- show_record();
- cout<<"Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- case 4:{
- delete_record();
- cout<<"Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- case 5:{ modify_record();
- cout<<"Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- case 6:{
- exit(0);
- }
- default:{
- cout<<"Nevalidna komanda, Natisni buton za vryshtane v glavnoto menu...";
- getch();
- break;
- }
- }
- }
- return 0;
- }
- void add_record()
- {
- char ch= 'y';
- file.open("stock.dat", ios::app | ios::binary);
- while(ch=='y'|| ch=='Y')
- {
- it.get_item();
- file.write((char*)&it, sizeof(it));
- cout<<"Dobavi oshte zapisi....(y/n)?";
- cin>>ch;
- }
- file.close();
- }
- void show_All(void)
- {
- file.open("stock.dat", ios::in | ios::binary);
- if(! file)
- {
- cout<<"Faila ne e nameren";
- exit(0);
- }
- else
- {
- file.read((char*)&it, sizeof(it));
- while(! file.eof())
- {
- it.put_item();
- file.read((char*)&it, sizeof(it));
- }
- }
- file.close();
- }
- void show_record(void)
- {
- int no, flag = 0;
- file.open("stock.dat", ios::in| ios::binary);
- if(!file)
- {
- cout<<"Faila ne e nameren";
- exit(0);
- }
- else
- {
- cout<<"Vyvedete nomera na kniga: ";
- cin>>no;
- file.read((char*)&it, sizeof(it));
- while(!file.eof())
- {
- if(no==it.get_code())
- {
- flag=1;
- cout<<"--------------------------------------------\n";
- cout<<setw(6)<<"Code"<<setw(15)<<"Name"<<setw(6)<<"Qty"<<endl;
- cout<<"--------------------------------------------\n";
- it.put_item();
- cout<<"--------------------------------------------\n";
- break;
- }
- file.read((char*)&it, sizeof(it));
- }
- if(flag==0)
- {
- cout<<"Produkta ne e nameren...\n";
- }
- }
- file.close();
- }
- void delete_record()
- {
- int no;
- cout<<"Vyvedete nomer na kniga za iztrivane: ";
- cin >> no;
- ofstream file2;
- file2.open("new.dat", ios::out|ios::binary);
- file.open("stock.dat", ios:: in|ios::binary);
- if(! file)
- {
- cout<<"Faila ne e nameren";
- exit(0);
- }
- else
- {
- file.read((char*)&it, sizeof(it));
- while(!file.eof())
- {
- if(no!= it.get_code())
- {
- file2.write((char*)&it, sizeof(it));
- }
- file.read((char*)&it, sizeof(it));
- }
- }
- file2.close();
- file.close();
- remove("stock.dat");
- rename("new.dat", "stock.dat");
- }
- void modify_record(void)
- {
- int no, num;
- cout<<"Vyvedete nomer na kniga za redakciq:"; cin >> no;
- cout<<"Vyvedete kolichestvo: "; cin >> num;
- file.open("stock.dat", ios:: in| ios::out | ios::binary);
- if(! file)
- {
- cout<<"Faila ne e nameren";
- exit(0);
- }
- while (file.read((char*)&it, sizeof(it)))
- {
- if(it.get_code()== no)
- {
- it.update_Qty(num);
- int pos = sizeof(it);
- file.seekp(-pos, ios::cur);
- file.write((char*)&it, sizeof(it));
- }
- }
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement