Unregistered
|
вот типа программа моей одногрупницы (где она только ее взяла) ! вообщем она не компайлится ! Но мне интерсно что это за обьявление класса CAR ! И почему программа не работает ? | Код | #include <graphics.h> #include <conio.h> #include <dos.h> #include <stdlib.h> #include <alloc.h> #include <stdio.h>
#define PATHTODRIVER "c:\borlandc\bgi\"
class CAR; class plist //Syntax:<classkey> <classname> [<:baselist>] { <member list> } { private: //If a member is private, it can only be used by //member functions and friends of the class in //which it is declared.
struct elem { CAR *pelm; elem *prev,*next; elem(CAR* p, elem* p1) {pelm=p;prev=p1;next=NULL;}//const.~ };
elem *first; elem *last; elem *cur; size_t cnt;//(?)size_t:Type used for memory object sizes and repeat counts.
public: //If a member is public, //it can be used by any function.
plist() //constrrrr {first=NULL; //v proge isp. dvuhsvyaznij spisok last=NULL; cnt=0; //schetchik(?) cur=NULL; //cur-current }
void add(CAR *p) //Add()..dobavlenie mashin..(?) //(?)cikl v spiske { if (!last) { last=new elem(p,NULL); first=last; cur=last; } else { //Relyacionnaya model(!!!) last->next=new elem(p,last); last=last->next;
} cnt++; //schetchik(?) }
size_t count() { return cnt; } CAR *del() //udalenie iz spiska (i ego sdvig-?) { if (!cur) return NULL; if (cur->prev) cur->prev->next=cur->next; else first=cur->next; if (cur->next) cur->next->prev=cur->prev; else last=cur->prev; CAR* p=cur->pelm; elem* p1=cur; cur=cur->next; delete p1; cnt--; return p; }
CAR* reset() {//Clears the elapsed time accumulated from previous start/stop sequences. if (!first) return NULL; cur=first; return cur->pelm; }
CAR* operator++(int) { if (!cur) return NULL; CAR* p=cur->pelm; cur=cur->next; return p; }
CAR* operator[](size_t index) { if (index>=cnt) return NULL; cur=first; for (size_t i=0; i<index; i++) cur=cur->next; return cur->pelm; }
CAR* current() { if (!cur) return NULL; return cur->pelm; }
};
int ch; int i=0;
void init() //inicializaciya grafiki {int gd = VGA; int gm = VGAHI; initgraph(&gd, &gm, "");}
void back() //otrisovka grafiki(BACKground) {setfillstyle(2,8); //zakraska trotuara bar(0,0,270,190); bar(370,0,640,190); bar(0,290,270,480); bar(370,290,640,480);
setfillstyle(7,2); //zakraska travi bar(0,0,230,95); bar(0,0,160,155);
bar(410,0,640,95); bar(480,0,640,155);
bar(0,340,160,480); bar(0,380,230,480);
bar(410,380,640,480); bar(480,340,640,480);
setcolor(2); setfillstyle(1,BLACK); //svetofor backg bar(185,115,255,175); bar(385,115,455,175); bar(185,305,255,365); bar(385,305,455,365);
outtextxy(10,10," C A R S 2"); outtextxy(10,24,"beta v.18.9"); }
class CAR { //Syntax: <classkey> <classname> [<:baselist>] { <member list> }
//Classes are specific to C++. // þ <classkey> is one of the keywords "class", "struct", or "union". // þ <classname> can be any name unique within its scope. // þ <baselist> lists the base class(es) that this class derives from. // <baselist> is optional. // þ <member list> declares the class's data members and member functions.
//Within a class, // þ the data are called "data members" // þ the functions are called "member functions"
protected: //If a member is protected, its access is the same as for private. //In addition, the member can be used by member functions and friends of //classes derived from the declared class, but only in objects of the derived //type int x1;int y1; int x2;int y2; int color; int vis; public: //If a member is public, //it can be used by any function. int dx;int dy; CAR(int xx1,int yy1,int xx2,int yy2,int ddx,int ddy,int color); int GetX1(); int GetY1(); int GetX2(); int GetY2(); int GetColor(); static void svet(); //STATIK: //Preserves variable value // Syntax: // þ static <data definition>; // þ static <function definition>; //A function or data element is only known within the scope of the current //compile. //If you use the "static" keyword with a variable that is local to a function, //it allows the last value of the variable to be preserved between successive //calls to that function.
//Constructor(~) //Polimorfizm //tablica virt.Metodov //(®¡à §ã¥âáï ¯à¨ ª®¬¯¨«ï樨,xà ¨â ¤à¥á ¢á¥å ¢¨àâ.¬¥â®¤®¢)
//Constrrr CAR :: CCAR(int xx1,int yy1,int xx2,int yy2,int ddx,int ddy,int ccolor) { x1=xx1; x2=xx2; y1=yy1; y2=yy2; dx=ddx; dy=ddy; color=ccolor; vis=0; }
int CAR :: GGetX1() {return x1;} int CAR :: GGetY1() {return y1;} int CAR :: GGetColor() {return color;} int CAR :: GGetX2() {return x2;} int CAR :: GGetY2() {return y2;}
void CAR :: Draw() //otrisovka of cars {setfillstyle(11,color); bar(x1,y1,x2,y2); vis=1;} ////////////////////////////////// void CAR :: ssvet() //svetofori(grafika) { {i=i+1;} //schetchik svetofora if (i <= 300) //(skorost pereklucheniya) { setfillstyle(1,LIGHTRED); //otrisovka svstoforov bar(390,310,450,330); setfillstyle(1,LIGHTRED); bar(190,150,250,170); setfillstyle(1,LIGHTGREEN); bar(190,310,250,330); setfillstyle(1,LIGHTGREEN); bar(390,150,450,170);
// 2 SVETOFOR setfillstyle(1,LIGHTGREEN); //otrisovka svstoforov bar(390,340,450,360); setfillstyle(1,LIGHTGREEN); bar(190,120,250,140); setfillstyle(1,LIGHTRED); bar(190,340,250,360); setfillstyle(1,LIGHTRED); bar(390,120,450,140); } if (i > 300) { setfillstyle(1,LIGHTGREEN); //otrisovka svstoforov bar(390,310,450,330); setfillstyle(1,LIGHTGREEN); bar(190,150,250,170); setfillstyle(1,LIGHTRED); bar(190,310,250,330); setfillstyle(1,LIGHTRED); bar(390,150,450,170);
//2 SVETOFOR setfillstyle(1,LIGHTRED); //otrisovka svstoforov bar(390,340,450,360); setfillstyle(1,LIGHTRED); bar(190,120,250,140); setfillstyle(1,LIGHTGREEN); bar(190,340,250,360); setfillstyle(1,LIGHTGREEN); bar(390,120,450,140);
if (i==600) //interval svetofora {i=0; // to start(snachala) schetchika } } }
void CAR :: Delete() //ispolzurtsya v dvijenii { setfillstyle(1,0); // stiranie sleda of car bar(x1,y1,x2,y2); vis=0; } void CAR :: Move() { int i=0; if (vis) { Delete(); //deleting of car i=1; } x1+=dx;y1+=dy; //dvijenie v pered x2+=dx;y2+=dy; if (i) Draw(); //otrisovka of car } //**************************************************** //**************************************************** //**************************************************** //**************************************************** void main(void) // M A I N ! ! ! ! ! ! { int gdriver=DETECT; int gmode; int errorcode; initgraph(&gdriver,&gmode,PATHTODRIVER); errorcode=graphresult();
if (errorcode==grOk) { //inicializaciya grafiki back(); //graficheskoe oformlenie oerekrestka plist cars; //(plist-class) CAR *c,*c1; //c-㪠§ â¥«ì ª« áá car randomize(); //Randomize(); //Macro that initializes random number generator // Declaration: // þ void randomize(void); // Remarks: //randomize initializes the random number generator with a random value.
cars.add(c=new CAR(280,-40,310,0,0,1+random(3),3)); int rNS=random(640)+40/c->dy; c->Draw();//“ª § â¥«ì ‘ ¤¥« ¥â ®¡à 饨¥ ª Draw(-~-®¡ì¥ªâ ª« áá ) cars.add(c=new CAR(330,480,360,520,0,-1-random(3),3)); int rSN=random(640)-65/c->dy; c->Draw(); cars.add(c=new CAR(-40,250,0,280,1+random(3),0,3)); int rWE=random(640)+65/c->dx; c->Draw(); cars.add(c=new CAR(640,200,680,230,-1-random(3),0,3)); int rEW=random(640)-65/c->dx; c->Draw(); //rNS,rSN,rWE,rEW-geograficheskie napravleniya while (!kbhit()) //while not press any key { c->svet(); int j,k; for (j=0; j<cars.count(); j++) { c=cars[j]; cars.reset(); int stop=0; while(c1=cars++) { if (c1==c) continue; //proverka, net li vperedi mashini //po mat.formule(uchitivaetsya dlina,shirina i t.d.) if ((long(c->GetX1()+c->dx*3-c1->GetX1()+5)*long(c->GetX1()+c->dx*3-c1->GetX2()-5)<0L || long(c->GetX2()+c->dx*3-c1->GetX1()+5)*long(c->GetX2()+c->dx*3-c1->GetX2()-5)<0L) &&( long(c->GetY1()+c->dy*3-c1->GetY1()+5)*long(c->GetY1()+c->dy*3-c1->GetY2()-5)<0L || long(c->GetY2()+c->dy*3-c1->GetY1()+5)*long(c->GetY2()+c->dy*3-c1->GetY2()-5)<0L)) { //esli skoroct bolshe, chem u mashini vperedi, viravnivaem skorocti if (c1->dx*c->dx+c1->dy*c->dy>0) { if (c->dx) c->dx=c1->dx; else c->dy=c1->dy; } stop=1; break; } } if (stop) continue; //CONTINUE: //Passes control // Syntax: continue; //Causes control to pass to the end of the innermost enclosing while, do, or //for statement, at which point the loop continuation condition is //re-evaluated. if (c->dx>0) if (getpixel(400,340)==LIGHTRED && c->GetX2()<=270 && c->GetX2()+c->dx>=270) continue; if (c->dx<0) if (getpixel(400,340)==LIGHTRED && c->GetX1()>=370 && c->GetX1()+c->dx<=370) continue; if (c->dy>0) if (getpixel(400,320)==LIGHTRED && c->GetY2()<=190 && c->GetY2()+c->dy >=190) continue; if (c->dy<0) if (getpixel(400,320)==LIGHTRED && c->GetY1()>=290 && c->GetY1()+c->dx <=290) continue; c->Move();
} delay(8);//pausa
c=cars.reset(); //udalenie uehavshih mashin (za predeli ekrana) while(c) { if ( (c->GetX1()<0 && c->GetX2()<0) || (c->GetX1()>640 && c->GetX2()>640) || (c->GetY1()<0 && c->GetY2()<0) || (c->GetY1()>480 && c->GetY2()>480)) { cars.del(); delete c; c=cars.current(); } else cars++; c=cars.current();
//int main() //{ Table* p=new Table; // Table* q=new Table // delete p; // ...} } //Viviod sostoyanija pamyati char s[30]="Memory avaliable: "; //s(String) - char ultoa(coreleft(),s+18,10); //þ coreleft returns a measure of unused memory //þ ultoa converts an unsigned long to a string setfillstyle(7,2); bar(560,40,640,48);
setcolor(WHITE); outtextxy(420,40,s);
rNS--;//North-South rSN--;//South-North rWE--;//West-East rEW--;//East-West
//dobavlenie novih mashin if (rNS<=0) { cars.add(c=new CAR(280,-40,310,0,0,1+random(3),3)); rNS=random(600)+100; c->Draw(); }
if (rSN<=0) { cars.add(c=new CAR(330,480,360,520,0,-1-random(3),3)); rSN=random(600)+100; c->Draw(); }
if (rWE<=0) { cars.add(c=new CAR(-40,250,0,280,1+random(3),0,3)); rWE=random(600)+100; c->Draw(); }
if (rEW<=0) { cars.add(c=new CAR(640,200,680,230,-1-random(3),0,3)); rEW=random(600)+100; c->Draw(); }
}
closegraph(); } else { printf("Oshibka: %d\n",errorcode); puts("<Enter>"); getch(); } } }
|
|