Вот то, что у меня получилось пока:
Я не понимаю как сделать 2 пункта:
─ Вывод информации о неисполненных договорах. Информация упорядочена по дате оформления договора.
─ Вывод информации о неисполненных договорах на определенную дату, по запросу. Информация отсортирована по наименованию мебели и по покупателю.
#include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#define MAX 100
struct Furniture
{char Buyer [30];
char Addres_Buyer[30];
char Furniture_Name[30];
int Furniture_Model;
int Date_Registration;
int Date_Execution;
} furniture;
int enterChoice();
void newFile (fstream&);
void viewFile (fstream&);
void deleteFile (fstream&);
void runFile (fstream&);
void outputFile (fstream&);
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())!=5)
{ switch (choice)
{ case 1: newFile (My_base);
break;
case 2: viewFile (My_base);
break;
case 3: deleteFile (My_base);
break;
case 4: runFile (My_base);
break;
case 5: outputFile (My_base);
break;
default:
cerr<<"Incorrect choice"<<endl;
break;
}
My_base.clear();
}}
int enterChoice()
{ cout<<endl<<"Your choise:"<<endl
<<"1-newFile"<<endl
<<"2-viewFile"<<endl
<<"3-deleteFile"<<endl
<<"4-runFile"<<endl
<<"5-outputFile"<<endl
<<"6-the end of the work"<<endl<<"?";
int menuChoice;
cin>>menuChoice;
return menuChoice;
}
void newFile (ofstream &writeFromFile)
{ Furniture Furnitures[MAX];
int i;
ofstream NewFile("f:\\base.dat", ios::out);
if (!NewFile) { cerr<<"The file can't be opened!"<<endl;
exit(1);
}
cout<<"Buyer, Addres_Buyer,Furniture_Name,Furniture_Model,Date_Registration,Date_execution"<<endl
<<"Input FFF for the end"<<endl<<"?";
while (cin>>"Buyer">>Furnitures.Buyer>>"Addres_Buyer">>Furnitures.Addres_Buyer>>"Furniture_Name">>Furnitures.Furniture_Name>>"Furniture_Model">>Furnitures.Furniture_Model>>"Date_Registration">>Furnitures.Date_Registration>>"Date_Execution">>Furnitures.Date_Execution)
{NewFile<<"Buyer"<<Furnitures.Buyer<<' '<<"Addres_Buyer"<<Furnitures.Addres_Buyer<<' '<<"Furniture_Name"<<Furnitures.Furniture_Name<<' '<<"Furniture_Model"<<Furnitures.Furniture_Model<<' '<<"Date_Registration"<<Furnitures.Date_Registration<<' '<<"Date_Execution"<<Furnitures.Date_Execution<<endl;
cout<<"?";
}
void viewFile (ifstream &readFromFile)
{ ifstream ViewFile ("f:\\furniture.txt", ios::out);
if (!ViewFile)
{ cerr<<"The file cannot be opened"<<endl;
exit(1);
}
ViewFile<<setiosflags(ios::left)<<setw(6)<<"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;
readFromFile.seekg(0);
Furniture furnitur;
readFromFile.read((char*)&furniture, sizeof(furniture));
while (!readFromFile.eof())
{if (Furniture.Buyer!=0)
outputLine(ViewFile, furniture);
readFromFile.read((char*)&furniture, sizeof(furniture));
}
}
getch();
}