Файлы исходного кода
If (fin.fail ()){delete p; throw errorf («Файл пуст или данные не соответствуют формату», «firma: inputfile ()», file);}. Cout<<" Введите данные согласно образцу: Гравий тонна 600 Автодор 7 059 403 65 14 11 2014 «; Cout<<» |No| Вид работы — Цена — Ед. изм. — Название фирмы — Номер счёта — Дата — Обьём — «; If (cin.fail () || a<=0 || a>n){cout<<» Ошибка ввода, введите еще раз «; cin. clear… Читать ещё >
Файлы исходного кода (реферат, курсовая, диплом, контрольная)
Firma.cpp:
# include «Firma.h» .
#include «Error.h» .
firma *firma:beg1(NULL), *firma:end1(NULL); int firma: n (0);
void firma: inputfile (){ //ввод из текстового файла.
firma *p;
ifstream fin;
char file[30];
cout<<" Имя входного файла: «;
cin>>file;
fin.open (file);
if (fin.fail ()){ throw errorf («Не удалось открыть файл», «firma: inputfile ()», file);}.
p=new firma;
fin>>p;
if (fin.fail ()){delete p; throw errorf («Файл пуст или данные не соответствуют формату», «firma: inputfile ()», file);}.
p->next=NULL;
if (beg1==NULL){beg1=p; end1=p; n++;}.
else { end1->next=p; end1=p; n++;};
p=new firma;
fin>>p;
p->next=NULL;
while (fin.good ()){.
end1->next=p;
end1=p;
n++;
try{p=new firma;}.
catch (bad_alloc){firma:clear (firma:beg1,firma:end1); throw errorm («Недостаточно памяти», «firma: inputfile ()»);};
fin>>p;
p->next=NULL;}.
delete p;
}.
void firma: output (firma* &beg1){ //вывод на экран.
if (beg1==NULL){throw errorm («Не на что смотреть» ," firma: output ()");}.
firma *p;
int i;
p=beg1;
i=0;
cout<<<<'~';
cout<<" |No| Вид работы | Цена | Ед. изм. | Название фирмы | Номер счёта | Дата | Обьём | «;
cout<<<<" ~ «;
while (p≠NULL){.
cout<<" |" <<<<<" |" <
p=p->next; i++;}
cout<<<<" ~ «;
}
void firma: outputfile (firma* &beg1){
if (beg1==NULL){throw errorm («Нечего выводить» ," firma: outputfile");}
ofstream fon;
firma *p;
char file[20];
int i=0;
p=beg1;
cout<<" Имя выходного файла: «;
cin>>file;
fon.open (file);
if (fon.fail ()){throw errorf («Не удалось создать файл», «firma: outputfile», file);}
fon<<<<" «;
fon<<" |No| Вид работы | Цена | Ед. изм. | Название фирмы | Номер счёта | Дата | Обьём | «;
fon<<<<" «;
while (p≠NULL){
fon<<" |" <<<<<" |" <
p=p->next; i++;}
fon<')<<<" «;
cout << «Вывод произведён. «;
fon.close ();
}
void firma: clear (firma* &beg1, firma* &end1){
firma *p;
while (beg1≠NULL){p=beg1; beg1=beg1->next; delete p;}
end1=NULL; n=0;}
void firma: sortnazv (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortnazv");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->nazv>p3->nazv){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->nazv>p3->nazv){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortkol (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortkol ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortnum (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortnum ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->numch>p3->numch){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->numch>p3->numch){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortdat (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortdat ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->datedate){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->datedate){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortvidrab (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortvidrab ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortedizm (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortedizm ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->edizm>p3->edizm){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->edizm>p3->edizm){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: sortprise (firma* &beg1, firma* &end1){
if (beg1==NULL){throw errorm («Не чего сортировать» ," firma: sortprise ()");}
int fl;
firma *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->prise>p3->prise){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->prise>p3->prise){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void firma: delet (){
if (beg1==NULL){throw errorm («Нечего удалять» ," firma: delet ()");}
int a, z;
firma *p,*r;
cout<<" Введите колличество удаляемых записей: «;
metka:
cin>>z;
if (cin.fail () || zn){cout<<" Ошибка ввода, введите еще раз «; cin. clear (); cin. sync (); goto metka; };
while (z≠0){
firma:output (firma:beg1);
z—;
p=beg1;
cout<<" Введите номер удаляемой записи: «;
metka1:
cin>>a;
if (cin.fail () || a<=0 || a>n){cout<<" Ошибка ввода, введите еще раз «; cin. clear (); cin. sync (); goto metka1; };
if (a==1){
beg1=beg1->next;
n—;
if (p==end1){end1=NULL;}
delete p;}
else{
a=a-2;
while (a>0) {a—; p=p->next;};
r=p->next;
p->next=r->next;
n—;
if (p==end1){end1=NULL;}
delete r;}}}
void firma: vvodklav (){ //добавление записи (ввод с клавиатуры)
firma*p;
int m;
cout<<" Введите количество записей: «;
metka:
cin>>m;
if (cin.fail () || m<=0){cout<<" Ошибка ввода, введите еще раз «; cin. clear (); cin. sync (); goto metka; };
cout<<" Введите данные согласно образцу: Гравий тонна 600 Автодор 7 059 403 65 14 11 2014 «;
m++;
p=new firma;
metka1:
cin>>p;
if (cin.fail ()){cout<<" Ошибка ввода, введите еще раз «; cin. clear (); cin. sync (); goto metka1; };
p->next=NULL;
if (beg1==NULL){beg1=p;}
else{end1->next=p;}
end1=p;
n++;
for (int i=1; i
try{p=new firma;}
catch (bad_alloc){firma:clear (firma:beg1,firma:end1); throw errorm («Недостаточно памяти», «firma: vvodklav ()»);};
metka2:
cin>>p;
if (cin.fail ()){cout<<" Ошибка ввода, введите еще раз «; cin. clear (); cin. sync (); goto metka2; };
p->next=NULL;
end1->next=p;
end1=p;
n++;}}
void firma: searchnumch (firma* &beg1){
if (beg1==NULL){throw errorm («Не где искать» ," firma: searchnumch ()");}
int f;
int fl=0;
firma *p;
p=beg1;
cout<<" Введите номер счета: «;
cin>>f;
cout<')<<<" - «;
while (p≠NULL){
if (f==p->numch){
cout<<" |" <
if (fl==0){cout<<" | Ненайдено | «;}
cout<')<<<" - «;}
Search.cpp:
#include «Search.h»
#include «Error.h»
firma *search:beg1(NULL), *search:end1(NULL); int search: n (0);
void search: serch_nazv (){
if (firma:beg1==NULL){throw errorm («Не где искать» ," stud: searchodn");}
string f;
int fl=0;
firma *p,*pn;
p=firma:beg1;
cout<<" Введите название фирмы: «;
cin>>f;
while (p≠NULL){
if (f==p->nazv){
try{pn=new firma;}
catch (bad_alloc) {search:clear (); throw errorm («Недостаточно памяти», «search: serch_nazv ()»);}
*pn=*p;
pn->next=NULL;
if (beg1==NULL){beg1=pn; end1=pn; n++;}
else {end1->next=pn; end1=pn; n++;};
fl=1;}
p=p->next;}
if (fl==0){cout<<" Ненайдено! «;}}
void search: output (){
if (beg1==NULL){throw errorm («Не чего выводить» ," search: output ()");}
firma:output (beg1);}
void search: sortprise (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortprise");}
firma:sortprise (beg1,end1);}
void search: sortvidrab (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortnum ()");}
firma:sortvidrab (beg1,end1);}
void search: sortkol (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortkol ()");}
firma:sortdat (beg1,end1);}
void search: sortdat (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortdat ()");}
firma:sortkol (beg1,end1);}
void search: sortedizm (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortedizm ()");}
firma:sortedizm (beg1,end1);}
void search: sortnum (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," search: sortnum ()");}
firma:sortnum (beg1,end1);}
void search: clear (){
firma:clear (beg1,end1);}
void search: outputfile (){
if (beg1==NULL){throw errorm («Не чего выводить» ," search: outputfile ()");}
firma:outputfile (beg1);}
void search: seurchnumch (){
if (beg1==NULL){throw errorm («Не где искать» ," search: seurchnumch ()");}
firma:searchnumch (beg1);}
Perech.cpp:
#include «Perech.h»
#include «Error.h»
pervidrab *pervidrab:beg1(NULL), *pervidrab:end1(NULL); int pervidrab: n (0);
void pervidrab: per_vidrab (){
if (firma:beg1==NULL){throw errorm («Не из чего формировать» ," pervidrab: per_vidrab ()");}
int l;
firma *p1;
pervidrab *p2;
p2=new pervidrab;
p1=firma:beg1;
p2->vidrab = p1->vidrab;
p2->koll=1;
p2->next=NULL;
beg1=p2;
end1=p2;
n++;
p1=p1->next;
while (p1≠NULL){
p2=beg1;
l=0;
while (p2≠NULL){
if (p1->vidrab == p2->vidrab){p2->koll++; l=1; break;}
p2=p2->next;}
if (l==0) {try{p2=new pervidrab;}
catch (bad_alloc) {pervidrab: clear (); throw errorm («Недостаточно памяти», «pervidrab:per_vidrab ()»);}
p2->next=NULL; p2->vidrab = p1->vidrab; p2->koll=1; end1->next=p2; end1=p2; n++;}
p1=p1->next;}
}
void pervidrab: output (){
if (beg1==NULL){throw errorm («Не на что смотреть» ," pervidrab: output ()");}
pervidrab *p;
int i;
p=beg1;
i=0;
cout<<<<" *" ;
cout<<" | Вид работы | Количество | «;
cout<')<<<" - «;
while (p≠NULL){
cout<<" |" <<<" |" <<<" | «;
p=p->next; i++;}
cout<<<<" * «;
}
void pervidrab: clear (){
pervidrab *p;
while (beg1≠NULL){p=beg1; beg1=beg1->next; delete p;}
end1=NULL; n=0;}
void pervidrab: outputfile (){
if (beg1==NULL){throw errorm («Нечего выводить» ," pervidrab: outputfile ()");}
ofstream fon;
pervidrab *p;
char file[20];
int i=0;
p=beg1;
cout<<" Имя выходного файла: «;
cin>>file;
fon.open (file);
if (fon.fail ()){throw errorf («Не удалось создать файл», «pervidrab: outputfile ()», file);}
fon<<<<" *" ;
fon<<" | Вид работы | Количество | «;
fon<')<<<" - «;
while (p≠NULL){
fon<<" |" <<<" |" <<<" | «;
p=p->next; i++;}
fon<<<<" * «;
cout << «Вывод произведён. «;
fon.close ();
}
void pervidrab: sortvidrab (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," pervidrab: sortvidrab ()");}
int fl;
pervidrab *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void pervidrab: sortkoll (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," pervidrab: sortkoll ()");}
int fl;
pervidrab *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
perdate *perdate:beg1(NULL), *perdate:end1(NULL); int perdate: n (0);
void perdate: per_date (){
if (firma:beg1==NULL){throw errorm («Не из чего формировать» ," perdate: per_date ()");}
int l;
firma *p1;
perdate *p2;
p2=new perdate;
p1=firma:beg1;
p2->date = p1->date;
p2->koll=1;
p2->next=NULL;
beg1=p2;
end1=p2;
n++;
p1=p1->next;
while (p1≠NULL){
p2=beg1;
l=0;
while (p2≠NULL){
if (p1->date == p2->date){p2->koll++; l=1; break;}
p2=p2->next;}
if (l==0) {try{p2=new perdate;}
catch (bad_alloc) {perdate: clear (); throw errorm («Недостаточно памяти», «perdate: per_date ()»);}
p2->next=NULL; p2->date = p1->date; p2->koll=1; end1->next=p2; end1=p2; n++;}
p1=p1->next;}
}
void perdate: output (){
if (beg1==NULL){throw errorm («Не на что смотреть» ," perdate: output ()");}
perdate *p;
int i;
p=beg1;
i=0;
cout<<<<" *" ;
cout<<" | Дата | Количество | «;
cout<')<<<" - «;
while (p≠NULL){
cout<<" |" <" |" <<<" | «;
p=p->next; i++;}
cout<<<<" * «;
}
void perdate: clear (){
perdate *p;
while (beg1≠NULL){p=beg1; beg1=beg1->next; delete p;}
end1=NULL; n=0;}
void perdate: outputfile (){
if (beg1==NULL){throw errorm («Нечего выводить» ," perdate: outputfile ()");}
ofstream fon;
perdate *p;
char file[20];
int i=0;
p=beg1;
cout<<" Имя выходного файла: «;
cin>>file;
fon.open (file);
if (fon.fail ()){throw errorf («Не удалось создать файл», «perdate: outputfile ()», file);}
fon<<<<" *" ;
fon<<" | Дата | Количество | «;
fon<')<<<" - «;
while (p≠NULL){
fon<<" |" <" |" <<<" | «;
p=p->next; i++;}
fon<<<<" * «;
cout << «Вывод произведён. «;
fon.close ();
}
void perdate: sortdate (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," perdate: sortdate ()");}
int fl;
perdate *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->datedate){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->datedate){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void perdate: sortkoll (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," perdate: sortkoll ()");}
int fl;
perdate *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->koll>p3->koll){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
perprise *perprise:beg1(NULL), *perprise:end1(NULL); int perprise: n (0);
void perprise: per_prise (){
if (firma:beg1==NULL){throw errorm («Не из чего формировать» ," perprise: per_prise ()");}
int l;
firma *p1;
perprise *p2;
p2=new perprise;
p1=firma:beg1;
p2->prise = p1->prise;
p2->vidrab = p1->vidrab;
p2->nazv = p1->nazv;
p2->next=NULL;
beg1=p2;
end1=p2;
n++;
p1=p1->next;
while (p1≠NULL){
p2=beg1;
l=0;
while (p2≠NULL){
if (p1->prise == p2->prise && p1->vidrab == p2->vidrab && p1->nazv == p2->nazv){l=1; break;}
p2=p2->next;}
if (l==0) {try{p2=new perprise;}
catch (bad_alloc) {perprise: clear (); throw errorm («Недостаточно памяти», «perprise: per_prise ()»);}
p2->next=NULL; p2->prise = p1->prise; p2->vidrab = p1->vidrab; p2->nazv = p1->nazv; end1->next=p2; end1=p2; n++;}
p1=p1->next;}
}
void perprise: output (){
if (beg1==NULL){throw errorm («Не на что смотреть» ," perprise: output ()");}
perprise *p;
int i;
p=beg1;
i=0;
cout<<<<" *" ;
cout<<" | Цена | Вид работы | Название фирмы | «;
cout<')<<<" - «;
while (p≠NULL){
cout<<" |" <<<" |" <<<" |" <<<" | «;
p=p->next; i++;}
cout<<<<" * «;
}
void perprise: clear (){
perprise *p;
while (beg1≠NULL){p=beg1; beg1=beg1->next; delete p;}
end1=NULL; n=0;}
void perprise: outputfile (){
if (beg1==NULL){throw errorm («Нечего выводить» ," perprise: outputfile ()");}
ofstream fon;
perprise *p;
char file[20];
int i=0;
p=beg1;
cout<<" Имя выходного файла: «;
cin>>file;
fon.open (file);
if (fon.fail ()){throw errorf («Не удалось создать файл», «perprise: outputfile ()», file);}
fon<<<<" *" ;
fon<<" | Цена | Вид работы | Название фирмы | «;
fon<')<<<" - «;
while (p≠NULL){
fon<<" |" <<<" |" <<<" |" <<<" | «;
p=p->next; i++;}
fon<<<<" * «;
cout << «Вывод произведён. «;
fon.close ();
}
void perprise: sortprise (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," perprise: sortprise ()");}
int fl;
perprise *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->prise>p3->prise){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->prise>p3->prise){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
void perprise: sortvidrab (){
if (beg1==NULL){throw errorm («Не чего сортировать» ," perprise: sortvidrab ()");}
int fl;
perprise *p1,*p2,*p3;
do{
fl=0;
p2=beg1;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
beg1=p3;
fl=1;}
p1=beg1;
while (p1->next->next≠NULL)
{p2=p1->next;
p3=p2->next;
if (p2->vidrab>p3->vidrab){
p2->next=p3->next;
p3->next=p2;
p1->next=p3;
fl=1;}
p1=p1->next;}}
while (fl==1);
end1=p1->next;}
Menu.cpp:
#include «Firma.h»
#include «Search.h»
#include «Error.h»
#include «Perech.h»
int main (){
SetConsoleCP (1251);
SetConsoleOutputCP (1251);
int j;
nach:
system («cls»);
while (1){
try{cout<< «1. Работа с основной таблицей.» << endl;
cout << «2. Перечень видов работ.» << endl;
cout << «3. Перечень цен с указанием вида работы и фирмы.» << endl;
cout << «4. Перечень дат исполнения с указанием числа счетов.» << endl;
cout << «5. Поиск по названию фирмы.» << endl;
cout << «6. Выход. «<< endl;
cout <> j; cout<