Условие:
Написать программу учета продажи мебели .
Каждая запись содержит:
• Покупатель.
• Адрес покупателя
• Наименование мебели
• Модель мебели
• Дата оформления договора
• Дата исполнения договора
Программа должна обеспечивать выбор с помощью меню и выполнение следующих функций:
─ Ввод информации
─ Удаление информации об исполненных договорах за все даты, предшествующие заданной.
─ Просмотр информации в базе.
─ Вывод информации о неисполненных договорах. Информация упорядочена по дате оформления договора.
─ Вывод информации о неисполненных договорах на определенную дату, по запросу. Информация отсортирована по наименованию мебели и по покупателю.
То, что сделала:
#include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#define MAX 100
#include <stdlib.h>
struct Furniture
{
int Num_Buyer;
char Addres_Buyer[30];
char Furniture_Name[30];
int Furniture_Model;
int Date_Registration;
int Date_Execution;
};
int enterChoice();
void newFile (fstream&);
void addFile (fstream&);
void viewFile (ostream&);
void deleteFile (fstream&);
void runFile (fstream&);
void outputFile (fstream&);
void outputLine(ostream&, Furniture);
void main()
{
fstream My_base ("f:\\base.dat",ios::in | ios::out);
if (!My_base)
{
cerr<<"The file can't be opened!"<<endl;
exit(1);
}
int choice;
while ((choice=enterChoice())!=6)
{
switch (choice)
{
case 1:
newFile (My_base);
break;
case 2:
addFile (My_base);
break;
case 3:
viewFile (My_base);
break;
case 4:
deleteFile (My_base);
break;
case 5:
runFile (My_base);
break;
case 6:
outputFile (My_base);
break;
default:
cerr<<"Incorrect choice"<<endl;
break;
}
My_base.clear();
}
}
int enterChoice()
{
cout<<endl<<"Your choise:"<<endl
<<"1-newFile"<<endl
<<"2-addFile"<<endl
<<"3-viewFile"<<endl
<<"4-deleteFile"<<endl
<<"5-runFile"<<endl
<<"6-outputFile"<<endl
<<"7-the end of the work"<<endl<<"?";
int menuChoice;
cin>>menuChoice;
return menuChoice;
}
void newFile (ofstream &writeFromFile)
{
ofstream My_base("f:\\base.dat", ios::out);
if (!My_base)
{
cerr<<"The file can't be opened!"<<endl;
My_base.close();
}
Furniture blankFurniture={0," "," ",0,0,0};
for( int i=1; i<=100; i++)
My_base.write((char*)&blankFurniture, sizeof(blankFurniture));
}
void addFile (ofstream &writeFromFile)
{
ofstream My_base("f:\\base.dat", ios::ate);
if (!My_base)
{
cerr<<"The file can't be opened!"<<endl;
My_base.close();
}
cout<<"Input the number of the buyer"
<<"(from 1 to 100, 0 - the end of input)"<<endl<<"?";
Furniture furniture;
cin>>furniture.Num_Buyer;
while(furniture.Num_Buyer>0 && furniture.Num_Buyer<=100)
{
cout<<"Input Addres_Buyer, Furniture_Name, Furniture_Model, Date_Registration, Date_Execution"
<<endl<<"?";
cin>>furniture.Addres_Buyer>>furniture.Furniture_Name
>>furniture.Furniture_Model>>furniture.Date_Registration
>>furniture.Date_Execution;
My_base.seekp((furniture.Num_Buyer-1)*sizeof(furniture));
My_base.write((char*)&furniture, sizeof(furniture));
cout<<"Input the number of the buyer"
<<"(from 1 to 100, 0 - the end of input)"<<endl<<"?";
cin>>furniture.Num_Buyer;
}
}
void viewFile(int, char, char,int,int,int);
{
ifstream inFurnitureFile("f:\\base.dat", ios::in);
if (!inFurnitureFile)
{
cerr<<"The file cannot be opened"<<endl;
getch();
exit (1);
}
int Num_Buyer;
char Addres_Buyer[30];
char Furniture_Name[30];
int Furniture_Model;
int Date_Registration;
int Date_Execution;
cout<<setiosflags(ios::left)<<setw(6)<<"Num_Buyer"
<<setw(16)<< "Addres_Buyer"<<setw(11)<<"Furniture_Name"
<<setiosflags(ios::right)<<setw(10)<<"Furniture_Model"
<<setw(10)<<"Date_Registration"<<setw(11)<<"Date_Execution"
<<endl;
while (inFurnitureFile>>Num_Buyer>>Addres_Buyer>>Furniture_Name
>>Furniture_Model>>Date_Registration
>>Date_Execution)
outputLine (Num_Buyer,Addres_Buyer,Furniture_Name,Furniture_Model,Date_Registration,Date_Execution);
return 0;
}
void outputLine(int Num_B, char *Addres_B, char *F_Name, int F_Model, int Date_Registr, int Date_Exec)
{
cout<<setiosflags(ios::left)<<setw(6)<<Num_B
<<setw(16)<<Addres_B<<setw(11)<<F_Name
<<setw(10)<<setprecision(5)
<<setiosflags(ios::showpoint | ios::right)
<<F_Model<<setw(10)<<Date_Registr
<<setw(10)<<Date_Exec<<endl;
}
void deleteFile(fstream &deleteFromFile)
{
int d=0;
int i;
int k=0;
int r=0;
cout<<"Input the date:";
cin>>d;
Furniture furniture;
if (furniture.Num_Buyer!=0)
{
Furniture blankFurniture={0," "," ",0,0,0};
deleteFromFile.seekp((d-1)*sizeof(furniture));
deleteFromFile.write((char*)&blankFurniture, sizeof(furniture));
}
for (i=0;i<k;i++)
{
if (furniture.Date_Execution<d)
{
r=r+1;
}
}
if (r==0)
cout<<" Information was delete"<<endl;
}