Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Программирование на C / C++ / Курсовая работа1.doc
Скачиваний:
48
Добавлен:
02.05.2014
Размер:
3.29 Mб
Скачать

3.Сортировка по наименованию марки:

До сортировки:

После сортировки:

4. Сортировка по цвету автомобиля:

До сортировки:

После сортировки:

5. Сортировка по стоимости автомобиля:

До сортировки:

После сортировки:

6. Сортировка по изготовителю:

До сортировки:

После сортировки:

7.Сортировка по максимальной скорости:

До сортировки:

После сортировки:

8. Поиск осуществляется по всем критериям: по марке автомобиля, его цвету, стоимости, изготовителю и максимальной скорости. Поиск может осуществляться как по одному, так и по нескольким критериям одновременно:

1) Поиск по марке автомобиля:

2) Поиск по цвету автомобиля:

3) Поиск по стоимости автомобиля:

4) Поиск по изготовителю автомобиля:

5) Поиск по максимальной скорости автомобиля:

9. Добавление записи производится поочередно:

Результат:

10. Удаление записей производится по номеру строки:

11. Редактирование базы данных производится по каждому полю строки:

Результат:

12. Создание новой базы данных:

Просмотр созданной базы данных:

13. Сохранение изменений. При этом создается файл, имя и расположение которого указывается пользователем:

Открытие только что сохраненного файла:

Просмотр сохраненной базы данных:

14. Выход из программы:

5. Листинг программы

#include<iostream.h>

#include<fstream.h>

#include<conio.h>

#include<stdlib.h>

#include<stdio.h>

#include<string.h>

#include<iomanip.h>

#include <io.h>

const int L=30;

struct avto

{

char model[L];

char cvet[L];

long int stoimost;

char izgotovitel[L];

int speed;

int d;

};

const int N=100;

class avtos

{

private:

avto a[N];

int n;

public:

void input_file();

void outputfile();

void alfsort();

void sohranenie();

void sort_chisl_1();

void sort_chisl_2();

void sort_chisl_3();

void sort_chisl_4();

void add();

void udalenie();

void redaktirovanie();

void input();

void poisk();

};

void main()

{

clrscr();

avtos a;

int pm;

while(1)

{cout<<endl;

cout<<"*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*"<<endl;

cout<<"* /"<<endl;

cout<<"/ 1.Otkritie faila *"<<endl;

cout<<"* 2.Vivod na ekran /"<<endl;

cout<<"/ 3.Alfofitnai sortirovka *"<<endl;

cout<<"* 4.Sortirovka po cvety /"<<endl;

cout<<"/ 5.Sortirovka po stoimosti *"<<endl;

cout<<"* 6.Sortirovka po izgotovitelu /"<<endl;

cout<<"/ 7.Sortirovka po skorosti *"<<endl;

cout<<"* 8.Poisk po polu /"<<endl;

cout<<"/ 9.Dobavlenie zapisi v bazu dannih *"<<endl;

cout<<"* 10.Udalenie zapisi iz bazi dannih /"<<endl;

cout<<"/ 11.Redaktirovanie *"<<endl;

cout<<"* 12.Sozdanie novoi bazi dannih /"<<endl;

cout<<"/ 13.Sohranenie *"<<endl;

cout<<"* 14.Vihod /"<<endl;

cout<<"/ *"<<endl;

cout<<"*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*"<<endl;

cout<<endl<<endl;

cout<<" Vash vibor 1-14: ";

cin>>pm;

cout<<endl<<endl;

switch(pm)

{

case 1:a.input_file();break;

case 2:a.outputfile();getch();break;

case 3:a.alfsort();break;

case 4:a.sort_chisl_1();break;

case 5:a.sort_chisl_2();break;

case 6:a.sort_chisl_3();break;

case 7:a.sort_chisl_4();break;

case 8:a.poisk();break;

case 9:a.add();break;

case 10:a.udalenie();break;

case 11:a.redaktirovanie();break;

case 12:a.input();break;

case 13:a.sohranenie();break;

case 14:

{

clrscr();

cout<<"\t\t TTTTTT HH HH EEEEEE \n";

cout<<"\t\t TT HH HH EE \n";

cout<<"\t\t TT HHHHHH EEEE \n";

cout<<"\t\t TT HH HH EE \n";

cout<<"\t\t TT HH HH EEEEEE \n\n";

cout<<"\t\t EEEEEE NNN NN DDDD \n";

cout<<"\t\t EE NN N NN D D \n";

cout<<"\t\t EEEE NN N NN D D \n";

cout<<"\t\t EE NN N NN D D \n";

cout<<"\t\t EEEEEE NN NNN DDDD \n\n";

getch();

}

return;

default:cout<<"Net tacogo puncta.";

getch();break;

}

}

}

void avtos::alfsort()

{

int fl,i,l;

avto t;

l=n-1;

do

{

fl=0;

for(i=0;i<l;i++)

if(strcmp(a[i].model ,a[i+1].model)>0)

{

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

fl=1;

}

l--;

}

while(fl==1);

return;

getch();

}

void avtos::input_file()

{

ifstream fin;

char file[L];

cout<<"Ukazite put k failu: ";

cin>>file;

fin.open(file);

if(fin==NULL)

{

cout<<"File ne otkrit";

getch();

exit(1);

}

n=0;

fin>>a[n].model>>a[n].cvet>>a[n].stoimost>>a[n].izgotovitel>>a[n].speed;

while(fin.good())

{

n++;

fin>>a[n].model>>a[n].cvet>>a[n].stoimost>>a[n].izgotovitel>>a[n].speed;

}

fin.close();

getch();

}

void avtos::outputfile()

{

int i;

cout<<setw(10)<<"Model "<<setw(15)<<"Cvet "<<setw(15)<<"Stoimost "<<setw(18)<<"Izgotovitel "<<setw(14)<<"Ckopoctb "<<endl;

cout<<endl;

for(i=0;i<n;i++)

cout<<setw(10)<<a[i].model<<setw(15)<<a[i].cvet<<setw(13)<<a[i].stoimost<<setw(18)<<a[i].izgotovitel<<setw(13)<<a[i].speed<<endl;

getch(); }

void avtos::sort_chisl_1()

{

int fl,i,l;

avto t;

l=n-1;

do

{

fl=0;

for(i=0;i<l;i++)

if(strcmp(a[i].cvet ,a[i+1].cvet )>0)

{

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

fl=1;

}

l--;

}

while(fl==1);

return;

getch();

}

void avtos::sort_chisl_2()

{

int fl,i,l;

avto t;

l=n-1;

do

{

fl=0;

for(i=0;i<l;i++)

if(a[i].stoimost>a[i+1].stoimost)

{

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

fl=1;

}

l--;

}

while(fl==1);

return;

getch();

}

void avtos::sort_chisl_3()

{

int fl,i,l;

avto t;

l=n-1;

do

{

fl=0;

for(i=0;i<l;i++)

if(strcmp(a[i].izgotovitel ,a[i+1].izgotovitel )>0)

{

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

fl=1;

}

l--;

}

while(fl==1);

return;

getch();

}

void avtos::sort_chisl_4()

{

int fl,i,l;

avto t;

l=n-1;

do

{

fl=0;

for(i=0;i<l;i++)

if(a[i].speed>a[i+1].speed)

{

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

fl=1;

}

l--;

}

while(fl==1);

return;

getch();

}

void avtos::sohranenie()

{

char file[L];

ofstream out;

int otvet;

cout<<"Sohranit izmeneniya?"<<endl<<"Yes(press 1),No(press 0)";

cin>>otvet;

if(otvet==1)

{

cout<<"Vvedite direktoriyu, kuda vj bj hoteli sohranit: ";

cin>>file;

out.open(file);

if(out==NULL)

cout<<"File ne sozdan"<<endl<<"Programm to be finished";

getch();

exit(1);

}

}

int i;

for(i=0;i<n;i++)

out<<setw(10)<<a[i].model<<setw(10)<<a[i].cvet<<setw(10)<<a[i].stoimost<<setw(13)<<a[i].izgotovitel<<setw(13)<<a[i].speed<<endl;

cout<<endl;

getch();

}

void avtos::redaktirovanie()

{

int c,r;

cout<<"Vvedite nomer stroki,kotoruiu nujno otredaktirovat: ";

cin>>c;

cout<<c<<"."<<a[c-1].model<<" "<<a[c-1].cvet<<" "<<a[c-1].stoimost<<" "<<a[c-1].izgotovitel<<" "<<a[c-1].speed<<endl;

cout<<"Izmenit naimenovanie? (1 Da/0 Net):"<<endl;

cin>>r;

if(r)

{

cout<<"Model: ";

in>>a[c-1].model;

}

cout<<"Izmenit cvet avto? (1 Da/0 Net):"<<endl;

cin>>r;

if(r)

{

cout<<"Cvet avto: ";

cin>>a[c-1].cvet;

}

cout<<"Izmenit stoimost? (1 Da/0 Net):"<<endl;

cin>>r;

if(r)

{

cout<<"stoimost";

cin>>a[c-1].stoimost;

}

cout<<"Izmenit izgotovitel? (1 Da/0 Net):"<<endl;

cin>>r;

if(r)

{

cout<<"Izgotovitel: ";

cin>>a[c-1].izgotovitel;

}

cout<<"Izmenit ckopocmb? (1 Da/0 Net):"<<endl;

cin>>r;

if(r)

{

cout<<"Ckopoctb:";

cin>>a[c-1].speed;

}

cout<<endl;

cout<<"Redaktirovanie zaversheno."<<endl;

return;

getch();}

void avtos::udalenie()

{

int i,c;

cout<<"Vvedite nomer stroki,kotoruiu neobhodimo udalit: "<<endl;

cin>>c;

if (c>n) cout<<"Dannaia stroka v baze dannih otsutstvuet."<<endl;

else

{

cout<<c<<"."<<a[c-1].model<<" "<<a[c-1].cvet<<" "<<a[c-1].stoimost<<" "<<a[c-1].izgotovitel<<" "<<a[c-1].speed<<endl;

for (i=c;i<=n;i++)

{

a[i-1] = a[i];

}

cout<<"Stroka "<<c<<" udalena."<<endl;

n=n-1;

}

return;

getch();

}

void avtos::add()

{

struct avto x;

cout<<"Vvedite dannie novogo avto: "<<endl;

cout<<n+1<<".";

cout<<"Nomer: "<<endl;

cin>>x.d;

cout<<"Model: ";

cin>>x.model;

cout<<"Cvet avto: ";

cin>>x.cvet;

cout<<"Stoimost avto: ";

cin>>x.stoimost;

cout<<"Izgotovitel: ";

cin>>x.izgotovitel;

cout<<"Ckopocmb: ";

cin>>x.speed;

cout<<endl;

a[n]=x;

n=n+1;

cout<<"Zapisi dobavleni."<<endl;

return;

getch();

}

void avtos::input()

{

int i;

cout<<"Vvedite kolichestvo strok:"<<endl;

cin>>n;

cout<<"Vvedite dannie avto:"<<endl;

for (i=0;i<n;i++)

{

cout<<i+1<<".";

cout<<"Nomer: "<<endl;

cin>>a[i].d;

cout<<"Model: ";

cin>>a[i].model;

cout<<"Cvet avto: ";

cin>>a[i].cvet;

cout<<"Stoimost avto: ";

cin>>a[i].stoimost;

cout<<"Izgotovitel: ";

cin>>a[i].izgotovitel;

cout<<"Ckopocmb: ";

cin>>a[i].speed;

cout<<endl;

}

cout<<"Dannie vvedeni."<<endl<<endl;

getch();}

void avtos::poisk()

{

int i,d=0,f=0,j=0;

int q,w,e,r,t;

char model[L];

long int stoimost;

int speed;

char cvet[L], izgotovitel[L];

cout<<"Proizvesti poisk po: "<<endl;

cout<<"Modeli? Da-1,Net-0: ";

cin>>q;

if(q==1) {cout<<"Vvedite Model:"; cin>>model;f++;}

cout<<"Iskat po cvetu avto? Da-1,Net-0: ";

cin>>w;

if(w==1) {cout<<"Vvedite cvet: ";cin>>cvet;f++;}

cout<<"iskat po stoimosti avto?Da-1,Net-0: ";

cin>>e;

if(e==1) {cout<<"Vvedite stoimost avto: "; cin>>stoimost;f++;}

cout<<"Iskat po izgotovitelu? Da-1,Net-0: ";

cin>>r;

if(r==1) {cout<<"Vvedite izgotovitel: ";cin>>izgotovitel;f++;}

cout<<"Iskat po ckopocmu? Da-1,Net-0: ";

cin>>t;

if(t==1) {cout<<"Vvedite ckopocmb: ";cin>>speed;f++;}

for(i=0;i<n;i++)

{

if(q==1) {if(strcmp(model, a[i].model)==0) d=d+1;}

if(w==1) {if(strcmp(cvet, a[i].cvet)==0) d=d+1;}

if(e==1) {if(stoimost==a[i].stoimost) d=d+1;}

if(r==1) {if(strcmp(izgotovitel, a[i].izgotovitel)==0) d=d+1;}

if(t==1) {if(speed==a[i].speed) d=d+1;}

if(d==f) {cout<<endl<<setw(5)<<i+1<<setw(12)<<a[i].model<<setw(11)<<a[i].cvet<<setw(14)<<a[i].stoimost<<setw(10)<<a[i].izgotovitel<<setw(15)<<a[i].speed<<endl; j=j+1;}

d=0;

}

if(j==0) cout<<"Poisk ne dal rezultata!"<<endl<<endl;

cout<<endl<<endl;

getch();

}