/**********HADRON.HPP************/ // A Hadron is a collection of three quarks. If they are complementary // the hadron is said to be stable. #ifndef QUARK_CPP #include "quark.cpp" #endif #ifndef HADRON_HPP #define HADRON_HPP class Hadron { private: Quark first, second, third; public: Hadron(const Quark f, const Quark s, const Quark t) { first = f; second = s; third = t;} Quark buildThird(const Quark f, const Quark s); // builds compliment // Hadron from two Quarks int isStable(); // tests first, second and third }; #endif#ifndef QUARK_INCLUDES #define QUARK_INCLUDES #include #include #include #include #include #include #include #include #ifndef QUARK_HPP #include "quark.hpp" #endif #endif/* Quark: Any of a group of hypothetical elementary particles haveing electrical charges of magnitude one-third or two-thirds that of the electron, regarded as constituents of all hadrons. */ #ifndef QUARK_HPP #define QUARK_HPP const int NumOfAtts = 4; const int NumOfTypes = 3; const int NumQuarksInHadron = 3; const int spin = 0, color = 1, phase = 2, shape = 3; class Quark { private: int myAtts[NumOfAtts]; public: Quark() { myAtts[spin] = 0; myAtts[color] = 0; myAtts[phase] = 0; myAtts[shape] = 0; } Quark(const int sp, const int co, const int ph, const int sh) { myAtts[spin] = sp; myAtts[color] = co; myAtts[phase] = ph; myAtts[shape] = sh; } Quark(const int arrayIndex[4]) { myAtts[spin] = arrayIndex[spin]; myAtts[color] = arrayIndex[color]; myAtts[phase] = arrayIndex[phase]; myAtts[shape] = arrayIndex[shape]; } Quark(const Quark& qmodel) { myAtts[spin] = qmodel.myAtts[spin]; myAtts[color] = qmodel.myAtts[color]; myAtts[phase] = qmodel.myAtts[phase]; myAtts[shape] = qmodel.myAtts[shape]; } Quark(const Quark *qmodel) { myAtts[spin] = qmodel->myAtts[spin]; myAtts[color] = qmodel->myAtts[color]; myAtts[phase] = qmodel->myAtts[phase]; myAtts[shape] = qmodel->myAtts[shape]; } Quark& operator=(const Quark &q); int operator==(const Quark &pair); void print() const; // virtual ~Quark() {delete myAtts;} friend Hadron; }; #endif//****************Selection**************** #ifndef HADRON_CPP #include "hadron.cpp" #endif #ifndef QUARK_INCLUDES #include "qrk_incl.hpp" #endif #include "getmix.cpp" void main() { QuarkHandle *quarkStack = getMixedQuarks(); int count = 0; // tracks position in quarkStack QuarkHandle quarkDisplay[12]; for(int i = 0; i < 12; i++) { quarkDisplay[i].pQuark = quarkStack[i].pQuark; count ++; } clrscr(); int rangeTest(char *choice, int *prevChoices); int nTemp = 0; void showQuarks(QuarkHandle *q); showQuarks(quarkDisplay); cout << endl << "Pick Three Quarks: " << endl; int qSelections[3] = {0}; char *temp; for(i = 1;i < 4; i++) // three selections { do { cout << endl << "Quark #" << i << "> "; cin >> temp; nTemp = rangeTest(temp, qSelections); } while(nTemp==0); qSelections[i-1] = nTemp; quarkDisplay[nTemp-1].pQuark->print(); } Quark t1 = quarkDisplay[qSelections[0]-1].pQuark; Quark t2 = quarkDisplay[qSelections[1]-1].pQuark; Quark t3 = quarkDisplay[qSelections[2]-1].pQuark; Hadron sQuarks(t1,t2,t3); if(sQuarks.isStable()) { cout << "Three Quarks for muster Mark!"; }else cout << "Sorry, that's not a Hadron."; getch(); } int rangeTest(char *x, int pc[3]) { int xNum = atoi(x); if(xNum < 1) { cout << "Letters, Zero and Negative Numbers are not acceptable."; return 0; } if(xNum > 12) { cout << "There are no Quarks at that address."; return 0; } for(int i = 0; i < 3; i++) { if(xNum == pc[i]) { cout << "Quark " << xNum << " already selected."; return 0; } } return(xNum); } void showQuarks(QuarkHandle *q) { int outdisp = 0; for(int i = 0; i < 3; i++) { for(int j = 0; j < 4; j++) q[outdisp++].pQuark->print(); cout << endl << endl; } } #ifndef QUARK_INCLUDES #include "qrk_incl.hpp" #endif #ifndef QARRAY_CPP #define QARRAY_CPP const Quark quarkArray[81] = { Quark(0,0,0,0), Quark(0,0,0,1), Quark(0,0,0,2), Quark(0,0,1,0), Quark(0,0,1,1), Quark(0,0,1,2), Quark(0,0,2,0), Quark(0,0,2,1), Quark(0,0,2,2), Quark(0,1,0,0), Quark(0,1,0,1), Quark(0,1,0,2), Quark(0,1,1,0), Quark(0,1,1,1), Quark(0,1,1,2), Quark(0,1,2,0), Quark(0,1,2,1), Quark(0,1,2,2), Quark(0,2,0,0), Quark(0,2,0,1), Quark(0,2,0,2), Quark(0,2,1,0), Quark(0,2,1,1), Quark(0,2,1,2), Quark(0,2,2,0), Quark(0,2,2,1), Quark(0,2,2,2), Quark(1,0,0,0), Quark(1,0,0,1), Quark(1,0,0,2), Quark(1,0,1,0), Quark(1,0,1,1), Quark(1,0,1,2), Quark(1,0,2,0), Quark(1,0,2,1), Quark(1,0,2,2), Quark(1,1,0,0), Quark(1,1,0,1), Quark(1,1,0,2), Quark(1,1,1,0), Quark(1,1,1,1), Quark(1,1,1,2), Quark(1,1,2,0), Quark(1,1,2,1), Quark(1,1,2,2), Quark(1,2,0,0), Quark(1,2,0,1), Quark(1,2,0,2), Quark(1,2,1,0), Quark(1,2,1,1), Quark(1,2,1,2), Quark(1,2,2,0), Quark(1,2,2,1), Quark(1,2,2,2), Quark(2,0,0,0), Quark(2,0,0,1), Quark(2,0,0,2), Quark(2,0,1,0), Quark(2,0,1,1), Quark(2,0,1,2), Quark(2,0,2,0), Quark(2,0,2,1), Quark(2,0,2,2), Quark(2,1,0,0), Quark(2,1,0,1), Quark(2,1,0,2), Quark(2,1,1,0), Quark(2,1,1,1), Quark(2,1,1,2), Quark(2,1,2,0), Quark(2,1,2,1), Quark(2,1,2,2), Quark(2,2,0,0), Quark(2,2,0,1), Quark(2,2,0,2), Quark(2,2,1,0), Quark(2,2,1,1), Quark(2,2,1,2), Quark(2,2,2,0), Quark(2,2,2,1), Quark(2,2,2,2) }; struct QuarkHandle { const Quark *pQuark; int idx; }; QuarkHandle *getMixedQuarks() { QuarkHandle qHandle[81]; randomize(); for(int i = 0; i < 81; i++) { qHandle[i].pQuark = &quarkArray[i]; qHandle[i].idx = random(500) + 1; } for(i = 0; i < 81; i++) { int min = i; for(int j = i+1; j <= 80; j++) if( qHandle[j].idx < qHandle[min].idx) min = j; QuarkHandle temp = qHandle[i]; qHandle[i] = qHandle[min]; qHandle[min] = temp; } return qHandle; } #endif/*****************Hadron.cpp****************/ #ifndef QUARK_CPP #include "quark.cpp" #endif #ifndef HADRON_HPP #include "hadron.hpp" #endif #ifndef HADRON_CPP #define HADRON_CPP Quark Hadron::buildThird(const Quark first, const Quark second) { Quark *third = new Quark; for(int count = 0; count < NumOfAtts; count++) { if(first.myAtts[count] == second.myAtts[count]) { third->myAtts[count] = first.myAtts[count]; }else { third->myAtts[count] = ((3 - first.myAtts[count]) - second.myAtts[count]); } } return *third; } int Hadron::isStable() { int true = 0; Quark temp(buildThird(first, second)); if(temp == third) true = 1; return true; } #endif/************Quark Includes**************/ #ifndef QUARK_INCLUDES #define QUARK_INCLUDES #include #include #include #include #include #include #include #include "quark.hpp" #endif #ifndef QUARK_INCLUDES #include "qrk_incl.hpp" #endif #ifndef QUARK_CPP #define QUARK_CPP Quark &Quark::operator=(const Quark &q) { if(myAtts != q.myAtts) { myAtts[spin] = q.myAtts[spin]; myAtts[color] = q.myAtts[color]; myAtts[phase] = q.myAtts[phase]; myAtts[shape] = myAtts[phase]; } return *this; } int Quark::operator==(const Quark &second) { for(int count = 0; count < NumOfAtts; count++) { if(myAtts[count] != second.myAtts[count]) return 0; // not equal } return 1; // equal } void Quark::print() const { // int graphInit(); // graphInit(); char spin; int quarkShape = 0; int colorAtt = 0; switch(myAtts[0]) // letter representation of spin { case 0: spin = 'T'; break; case 1: spin = 'B'; break; case 2: spin = 'L'; break; } switch(myAtts[1]) // color { case 0: colorAtt = 2; break; // Green case 1: colorAtt = 3; break; // Yellow case 2: colorAtt = 4; break; // Red } switch(myAtts[2]) // blink/reverse representation of phase { case 2: textcolor(colorAtt); // normal textbackground(0); break; case 1: textcolor(0); // reverse textbackground(colorAtt); break; case 0: textcolor(colorAtt += 128); // blink textbackground(0); break; } quarkShape = myAtts[3] +1; // shape represented by # of chars for(int count=0; count < quarkShape; count++) { cprintf("%c", spin); } textbackground(0); for(count=0;count < (15-quarkShape); count++) { cprintf(" "); } } /*****************************************************************/ int graphInit() { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; /* initialize graphics, local variables*/ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { cout << "Graphics error: " << grapherrormsg(errorcode) << endl << "Press any key to halt:"; getch(); exit(1); /* terminate with error code */ } return (0); } #endif#include #include #include #include #ifndef QUARK_HPP #define QUARK_HPP #include "quark.hpp" #endif const Quark quarkArray[81] = { Quark(0,0,0,0), Quark(0,0,0,1), Quark(0,0,0,2), Quark(0,0,1,0), Quark(0,0,1,1), Quark(0,0,1,2), Quark(0,0,2,0), Quark(0,0,2,1), Quark(0,0,2,2), Quark(0,1,0,0), Quark(0,1,0,1), Quark(0,1,0,2), Quark(0,1,1,0), Quark(0,1,1,1), Quark(0,1,1,2), Quark(0,1,2,0), Quark(0,1,2,1), Quark(0,1,2,2), Quark(0,2,0,0), Quark(0,2,0,1), Quark(0,2,0,2), Quark(0,2,1,0), Quark(0,2,1,1), Quark(0,2,1,2), Quark(0,2,2,0), Quark(0,2,2,1), Quark(0,2,2,2), Quark(1,0,0,0), Quark(1,0,0,1), Quark(1,0,0,2), Quark(1,0,1,0), Quark(1,0,1,1), Quark(1,0,1,2), Quark(1,0,2,0), Quark(1,0,2,1), Quark(1,0,2,2), Quark(1,1,0,0), Quark(1,1,0,1), Quark(1,1,0,2), Quark(1,1,1,0), Quark(1,1,1,1), Quark(1,1,1,2), Quark(1,1,2,0), Quark(1,1,2,1), Quark(1,1,2,2), Quark(1,2,0,0), Quark(1,2,0,1), Quark(1,2,0,2), Quark(1,2,1,0), Quark(1,2,1,1), Quark(1,2,1,2), Quark(1,2,2,0), Quark(1,2,2,1), Quark(1,2,2,2), Quark(2,0,0,0), Quark(2,0,0,1), Quark(2,0,0,2), Quark(2,0,1,0), Quark(2,0,1,1), Quark(2,0,1,2), Quark(2,0,2,0), Quark(2,0,2,1), Quark(2,0,2,2), Quark(2,1,0,0), Quark(2,1,0,1), Quark(2,1,0,2), Quark(2,1,1,0), Quark(2,1,1,1), Quark(2,1,1,2), Quark(2,1,2,0), Quark(2,1,2,1), Quark(2,1,2,2), Quark(2,2,0,0), Quark(2,2,0,1), Quark(2,2,0,2), Quark(2,2,1,0), Quark(2,2,1,1), Quark(2,2,1,2), Quark(2,2,2,0), Quark(2,2,2,1), Quark(2,2,2,2) }; void shuffle() { struct QuarkHandle { const Quark *pQuark; int idx; } qHandle[81]; randomize(); for(int i = 0; i < 81; i++) { qHandle[i].pQuark = &quarkArray[i]; qHandle[i].idx = random(500); } //************************************************************ // Sort randomized qHandles so that quarkArray is randomised. for(i = 0; i < 81; i++) { int min = i; for(int j = i+1; j <= 80; j++) if( qHandle[j].idx < qHandle[min].idx) min = j; QuarkHandle temp = qHandle[i]; qHandle[i] = qHandle[min]; qHandle[min] = temp; } //************************************************************ }