Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 1. Список товаров, имеющихся на складе, включает в себя наименование
- товара, количество единиц товара, цену единицы и дату поступления товара на
- склад. Вывести список товаров, хранящихся больше месяца и стоимость которых превышает 1 000 000 р.
- */
- #include<iostream>
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<windows.h>
- using namespace std;
- FILE*fl;
- struct Spis
- {
- char name[30];
- char kol[7];
- int cost;
- int day;
- int month;
- int year;
- } ;
- Spis spis[30];
- char fname[20];
- int nspis=0;
- int menu();
- void nnf();
- void newf();
- void spisok();
- void opf();
- void resc();
- void resf(int i);
- int main()
- {
- using namespace std;
- while(true)
- {
- switch (menu())
- {
- case 1: nnf(); break;
- case 2: newf(); break;
- case 3: spisok(); break;
- case 4: opf(); break;
- case 5: resc(); break;
- case 6: return 0;
- default: cout << "Error! Write NUMBER 1 - 7!" << endl;
- }
- puts("nazmite clavishy for continues");
- _getch();
- system("cls");
- }
- }
- int menu()
- {
- cout << "ВЫБЕРИТЕ:" << endl;
- cout << "1. Name of file" << endl;
- cout << "2. New file" << endl;
- cout << "3. Write spisok" << endl;
- cout << "4. Open file" << endl;
- cout << "5. Show result and write them in file" << endl;
- cout << "6. EXIT" << endl;
- int i;
- cin >> i;
- return i;
- }
- void nnf()
- {
- cout << "Write name of file: " << endl;
- cin >> fname;
- }
- void newf()
- {
- if ((fl = fopen(fname,"wb")) == NULL)
- {
- cout << "Error with creating" << endl;
- exit(1);
- }
- cout << "File created" << endl;
- fclose(fl);
- }
- void spisok()
- {
- using namespace std;
- if ((fl=fopen(fname,"rb+"))==NULL)
- {
- cout << "Error with creating" << endl;
- exit(1);
- }
- cout << "Write number of product: " << endl;
- cin >> nspis;
- for(int i=0; i<nspis; i++)
- {
- cout << "Name of product: ";
- cin >> spis[i].name;
- cout << "Kol_vo edinits of product: ";
- cin >> spis[i].kol;
- cout << "Cost of product: ";
- cin >> spis[i].cost;
- cout << "Year, when u get product: ";
- cin >> spis[i].year;
- cout << "Month, when u get product: ";
- cin >> spis[i].month;
- cout << "Day, when u get product: ";
- cin >> spis[i].day;
- fwrite(&spis[i],sizeof(Spis),1,fl);
- }
- fclose(fl);
- }
- void opf()
- {
- if ((fl=fopen(fname,"rb"))==NULL)
- {
- cout << "Error with creating " << endl;
- exit(1);
- }
- nspis=0; Spis std;
- while(true)
- {
- int nwrt=fread(&std, sizeof(Spis),1,fl);
- if(nwrt!=1) break;
- spis[nspis]=std;
- cout << spis[nspis].name << " " << spis[nspis].kol << " " << spis[nspis].cost << " " << spis[nspis].day << spis[nspis].month << spis[nspis].year << endl;
- nspis++;
- }
- fclose(fl);
- }
- void resc()
- {
- int nyear, nmonth, nday;
- cout << "What year, month, day now?\n";
- cin >> nyear, nmonth, nday;
- for(int i=0; i<nspis; i++)
- { if(spis[i].cost > 1000000) {
- if (nyear == spis[i].year)
- { if (((nmonth == spis[i].month) && (nday > spis[i].day)) || (nmonth > spis[i].month))
- {
- resf(i); // вызов функции для записи в файл
- cout << spis[i].name << endl;
- }
- }
- else { if (nyear < spis[i].year) {cout << "ERROR!"; exit(1);}
- else { if ((nyear - spis[i].year)>=2) { cout << spis[i].name; resf(i); }
- else {if (nmonth < 12) {cout << spis[i].name; resf(i); }
- else { if (nday> spis[i].day) {cout << spis[i].name; resf(i); }
- }
- }
- }
- }
- }
- }
- }
- void resf(int number)
- {
- char namet[30];
- FILE*ft;
- ft=fopen("Vivod.txt","a");
- char s[80];
- strcpy(s,spis[number].name);
- strcat(s,"\n");
- fputs(s,ft);
- fclose(ft);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement