
Листинг программы
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <iostream.h>
#include <graphics.h>
#include <math.h>
#include <TIME.H>
#include <SYS\TYPES.H>
// Struct
const int STR_SIZE =20;
struct record
{ char imia[STR_SIZE];
char telefon[STR_SIZE];
int god_ystanovki;
int colich_abonentov;
int plata_telefon;};
//function prototypes
int ZastBeg();
void ProsmotrBD();
void CreateBD();
void AddRecord();
void AddRecord(const record & r);
void LoadBD();
void SaveBD();
int ChooseRecord();
void EditRecord();
void DeleteRecord();
void FindRecord();
void SortBD();
int Exit();
void ZastEnd();
int Get(int min, long max);
//Globals
static record * records = 0;
static long int nrecords = 0;
const int menupuncts = 10;
static char menu[menupuncts][30] = {"Prosmotr bazi dannix",
"Dobavlenie zapisi",
"Create baze dannix",
"Load baza dannix",
"Save baze dannix",
"Edit record",
"Ydalenie zapisi",
"Sortirovka baze",
"Poisk zapisi",
"Exit" };
const int sortmenupuncts = 6;
static char sortmenu[sortmenupuncts][30] = {"Sortirovka po imeni",
"Sortirovka po telefon",
"Sortirovka po god_ystanovki",
"Sortirovka po colich_abonentov",
"Sortirovka po plata_telefon",
"Return to main menu" };
//MENU
int YesNoDialog()
{ printf("\n<Enter> - yes, <Esc> - no");
int c;
do
{c = getch();
}while(c != 13 && c != 27);
return c;}
int Menu()
{ int choice = 0;
int loop = 1;
while(loop == 1)
{ clrscr();
for(int i=0;i<menupuncts;++i)
{ if(i == choice)
printf("\n >%s< ", menu[i]);
else
printf("\n %s", menu[i]);}
printf("\n\nNazhmite vverx/vniz dlia peredvizhenia kursora, nazhmite <Enter> dlia vibora deistvia");
int c = getch();
switch(c)
{ case 72: --choice;break;
case 80: ++choice;break;
case 13: loop = 0;break;
default:break; }
if(choice < 0) choice = menupuncts - 1;
if(choice >= menupuncts) choice = 0;}
return choice;}
int ZastBeg()//ZAST_BEG
{ int gdriver = DETECT, gmode, errorcode;
int maxx, x1, x2, x3, y1, y2, y3, i, k, s;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\bor\\turbo5\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); }
maxx = getmaxx();
setbkcolor (2);
setlinestyle(DOTTED_LINE, 0, 3);
line(0,420, maxx, 420);
setfillstyle(1,15);
setlinestyle(0, 0, 2);
line(440,380, 560, 380);
line(440,100, 560, 100);
line(440,240, 560, 240);
line(570,110, 570, 370);
line(570,120, 570, 360);
line(430,110, 430, 370);
bar(439, 109, 561, 241);
line(470,105, 530, 105);
arc(440, 110, 90, 180, 10);
arc(560, 110, 0, 90, 10);
arc(440, 370, 180, 270, 10);
arc(560, 370, 270, 0, 10);
circle(460, 270, 12);
circle(460, 310, 12); //knopki :
circle(460, 350, 12);
circle(500, 270, 12);
circle(500, 270, 12);
circle(540, 270, 12);
circle(500, 310, 12);
circle(500, 350, 12);
circle(540, 310, 12);
circle(540, 350, 12);
settextstyle(4,0,14);
outtextxy(maxx/2-50, 30, "KURSOVAYA RABOTA");
setcolor(15);
settextstyle(1,0,2);
outtextxy(140,110,"Theme: PLATA ZA TELEPHON");
settextstyle(SANS_SERIF_FONT,0,1);
outtextxy(300,450,"Autor: Shikunov V.V., group:PC-118");
for(i=0; i<8; i++)
{ s=s+i;
for(k=0; k<50; k++){
setcolor(15);
arc(560, 110, 0, 90, 15+k);
arc(560, 110, 0, 90, 25+k);
arc(560, 110, 0, 90, 35+k);
delay(50);
setcolor(0);
arc(560, 110, 0, 90, 15+k);
arc(560, 110, 0, 90, 25+k);
arc(560, 110, 0, 90, 35+k);}
setfillstyle(2,17-i*2);
bar(440, 110, 560, 240);
setfillstyle(1,14-i);
floodfill(500, 350, 15);
floodf ill(460, 350, 15);
floodfill(460, 270, 15);
floodfill(500, 270, 15);
floodfill(540, 350, 15);
floodfill(540, 270, 15);
floodfill(500, 310, 15);
floodfill(460, 310, 15);
floodfill(540, 310, 15);}
closegraph();
int c = getch();
return c;}
void ZastEnd()//ZastEnd
{ clrscr();
printf("Dosvidania!");
getch();}
int Exit()//Vixod
{ clrscr();
printf("\n Vi yvereni chto xotite exit?");
return YesNoDialog();}
int main()
{ if(ZastBeg() != 27)
{ int loop = 1;
while(loop == 1)
{ int p = Menu();
switch(p)
{ case 0: ProsmotrBD(); break;
case 1: AddRecord(); break;
case 2: CreateBD(); break;
case 3: LoadBD(); break;
case 4: SaveBD(); break;
case 5: EditRecord(); break;
case 6: DeleteRecord(); break;
case 7: SortBD(); break;
case 8: FindRecord(); break;
case 9: if(Exit() != 27) loop = 0; break; }}}
else ZastEnd();
return 0;}
static char filename[32]; //FileDialog
char * FileDialog()
{ clrscr();
printf("Input imia file:");
fscanf(stdin, "%s", filename);
return filename;}
void InputRecord(record & rec) //Vvod zapisi
{ clrscr();
int c;
if(kbhit())getch ();
rec.imia[0] = 0;
rec.telefon[0] = 0;
do{ printf("\nInput imia (15 simvolov):");
while(rec.imia[0] == 0)gets(rec.imia);
printf("\nInput telefon (6 cifr):");
while(rec.telefon[0] == 0)gets(rec.telefon);
printf("\nInput god_ystanovki (1..2010):");
rec.god_ystanovki = Get(1, 2010);
printf("\nInput colich_abonentov (1..999):");
rec.colich_abonentov = Get(1, 999);
printf("\nInput plata_telefon (1..9999r):");
rec.plata_telefon = Get(1, 9999);
printf("\nVi yvereni?");
c = YesNoDialog();
}while(c != 13);}
void AddRecord(const record & r) //DobavlenieRecord
{ ++nrecords;
record * newrecords = new record[nrecords];
if(records) {
memcpy(newrecords, records, (nrecords - 1) * sizeof(record));}
delete[] records;
records = newrecords;
records[nrecords - 1] = r;}
Void AddRecord()
{ record r;
InputRecord(r);
AddRecord(r);}
int IsInString(const char *string, const char *search_for) //poisk zapisi
{ int maxpos=0;
while(search_for[++maxpos]!=0);
int len=0;
while(string[++len]!=0);
for (int i=0; i<len; i++)
{ int add=0;
while(string[i+add] == search_for[add])
{ if(add==maxpos-1)return 1;
++add;}}
return 0;}
int RecordsSimilar(const record & a,const record & b)
{ int result = 1;
if(b.imia[0] != '-' && b.imia[1] != 0)if(IsInString(a.imia, b.imia) == 0)result = 0;
if(b.telefon[0] != '-' && b.telefon[1] != 0)if(IsInString(a.telefon, b.telefon) == 0)result = 0;
if(b.god_ystanovki != -1)if(a.god_ystanovki != b.god_ystanovki)result = 0;
if(b.colich_abonentov != -1)if(a.colich_abonentov != b.colich_abonentov)result = 0;
if(b.plata_telefon != -1)if(a.plata_telefon != b.plata_telefon)result = 0;
return result;}
Void FindRecord()
{ if(!records)
{ clrscr();
printf("\nNet zapisi, nazhmite lubyu klavishy.");
getch(); }
else{ clrscr();
record rec;
if(kbhit())getch ();
rec.imia[0] = 0;
rec.telefon[0] = 0;
printf("Input nazvanie zagolovka zapisi,dlia poiska po\n");
printf("\nInput imia (15 simvolov),\nprint \"-\" if you don't want to search by this field:");
while(rec.imia[0] == 0)gets(rec.imia);
printf("\nInput telefon (6 cifr),\nprint \"-\" if you don't want to search by this field:");
while(rec.telefon[0] == 0)gets(rec.telefon);
printf("\nInput god_ystanovki (1..2010),\nprint -1 if you don't want to search by this field:");
rec.god_ystanovki = Get(-1, 2010);
printf("\nInput colich_abonentov (1..900),\nprint -1 if you don't want to search by this field:");
rec.colich_abonentov = Get(-1, 900);
printf("\nInput plata_telefon (1r..90000r),\nprint -1 if you don't want to search by this field:");
rec.plata_telefon = Get(-1, 90000);
record * oldrecords = records;
int oldnrecords = nrecords;
records = 0;
nrecords = 0;
int n = 0;
for(int i=0;i<oldnrecords;++i)
{if(RecordsSimilar(oldrecords[i], rec) == 1)
{ AddRecord(oldrecords[i]);
++n;}
} if(n>0)
{ printf("\n%d Zapis naidena! Nazhmite ludyu klavishy dlia prosmotra.", n);
getch();
ProsmotrBD();
} else
{ printf("Nichego ne naideno.");
getch(); }
if(records)delete[] records;
records = oldrecords;
nrecords = oldnrecords;}}
void OutputRecord(record & rec) //Vivod zapisi
{ printf("%-17s%-17s%-12d%-12d%-10d", rec.imia, rec.telefon, rec.god_ystanovki, rec.colich_abonentov, rec.plata_telefon);}
void OutputTable(int start, int n) //Vivod tablici
{ if(!records)
{ clrscr();
printf("\nNet zapisi, nazhmite lubyu klavishy.");
getch();
} else
{ if(start<0)start = 0;
if(start + n > nrecords) n = nrecords - start;
if(n>0)
{ printf("N: |imia |telefon |god_ystanovki|colich_abnentov|plata_telefon\n");
for(int i=start;i<start+n;++i)
{ printf("\n%-3d", (i % nrecords)+1);
OutputRecord(records[(i % nrecords)]);}}}}
int SortMenu()//SortirovkaMenu
{ int choice = 0;
int loop = 1;
while(loop == 1)
{ clrscr();
for(int i=0;i<sortmenupuncts;++i)
{ if(i == choice)
printf("\n >%s< ", sortmenu[i]);
else
printf("\n %s", sortmenu[i]); }
printf("\n\nNazhmite vverx/vniz dlia peredvizhenia kursora, nazhmite <Enter> dlia vibora deistvia.");
int c = getch();
switch(c)
{ case 72: --choice;break;
case 80: ++choice;break;
case 13: loop = 0;break;
default:break; }
if(choice < 0) choice = sortmenupuncts - 1;
if(choice >= sortmenupuncts) choice = 0; }
return choice;}
static record c;
void swap(record & a, record & b) //Sortirovka BD
{ c = a;
a = b;
b = c;}