Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include "computercraft.h"
- #include <conio.h>
- Term *term = new Term;
- Color *colors = new Color;
- Paintutils *paintutils = new Paintutils();
- using namespace std;
- int qNum = 1;
- bool testing = true;
- int numQ = 8;
- int score = 0;
- int passamm = 80;
- int Answers[8] = {3,1,3,1,2,4,3,3};
- char qlookup[4] = {'A','B','C','D'};
- string Questions[8][7] = {
- {"How does a resistor, resist current?","By tightening the electron flow. ","By carrying an opposing field. ","By lowering the electron energy state. ","By drawing electrons to GND."},
- {"Which direction do electrons flow from? ", "GND", "VCC", "LEFT", "RIGHT"},
- {"How does an LED emit light?", "By heating up super hot. ", "By pulling light from the air", "By dropping electron energy states. ", "By conducting photons."},
- {"How much energy do electrons have at their \n GND state?","None","7 Joules", "18 Joules","5 volts"},
- {"Which of the fallowing can a Transistor be doped \n with ","NNP","PNP","PPP","NNN"},
- {"How are operation code's usually processed when \n making an 8bit CPU? ","0x173F","1101-0000","Its not processed in the CPU. ","Instruction in high nibble, operand in low."},
- {"Which popular IC is often used for a clock","74LS245","74HCS04","NE555","Timer456"},
- {"I turned on my shift register and all \n the bits are high!, what should i \n do?","Turn if off then on again. ","Buy a new shift register. ","Tie the inputs to a pulldown resistor. ","Block the inputs from GND. "},
- };
- int points[8] = {10,10,15,10,10,15,10,5};
- void tout(string txt)
- {
- int px = term->printx;
- int py = term->printy;
- term->setCursorPos(px,py);
- cout << txt << endl;
- term->printy++;
- }
- void drawQuestion(int number)
- {
- number--;
- paintutils->drawBoxFilled(1,1,50,20,7,7);
- paintutils->drawBoxFilled(1,1,50,1,colors->blue,colors->blue);
- term->setCursorPos(1,1);
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->blue);
- cout << "(" << number+1 << ". " << "Question worth - " << points[number] << "pts. " << endl;
- term->setCursorPos(42,1);
- cout << score << "/" << passamm << "pts";
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(3,3);
- cout << Questions[number][0] << endl;
- paintutils->drawBox(0,0,51,21,0);
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(4,7);
- tout("(A. " + Questions[number][1] );
- tout("(B. " + Questions[number][2] );
- tout("(C. " + Questions[number][3] );
- tout("(D. " + Questions[number][4] );
- }
- void flashselection(int sel)
- {
- for (int i = 0; i < 2; i++)
- {
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->yellow);
- term->setCursorPos(4,6+sel);
- cout << "(" << qlookup[sel-1] << ". " << Questions[qNum-1][sel] << endl;
- Sleep(200);
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(4,6+sel);
- cout << "(" << qlookup[sel-1] << ". " << Questions[qNum-1][sel] << endl;
- Sleep(200);
- }
- }
- void getTestResults()
- {
- testing=false;
- paintutils->drawBoxFilled(1,1,50,20,7,7);
- paintutils->drawBoxFilled(1,1,50,1,colors->blue,colors->blue);
- term->setCursorPos(1,1);
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->blue);
- cout << "Test Results. " << endl;
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(3,3);
- cout << "End of test results. " << endl;
- paintutils->drawBox(0,0,51,21,0);
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(4,7);
- cout << "Score: " << score << "/" << passamm << "pts";
- term->setCursorPos(4,8);
- cout << "Required passing grade: " << passamm;
- term->setCursorPos(4,9);
- tout(" ");
- term->setCursorPos(4,10);
- cout << "Status: ";
- if(score >= passamm)
- {
- term->setTextColor(colors->green);
- cout << "Passed! ";
- }
- else
- {
- term->setTextColor(colors->red);
- cout << "Failed. ";
- }
- term->setCursorPos(18,13);
- cout << "Press any key. " << endl;
- getch();
- }
- void nextQuestion()
- {
- term->setBackgroundColor(colors->black);
- term->Clear();
- term->setCursorPos(1,1);
- drawQuestion(qNum);
- }
- bool checkAnswer(int q, int ans)
- {
- flashselection(ans);
- bool corr = false;
- // Checks the users answer and displays the correct one.
- if(ans == Answers[q-1]) // Minus 1 because of table indexing at 0
- {
- corr = true;
- score += points[q-1];
- }
- if(!corr)
- {
- // Display answer as incorrect.
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->red);
- term->setCursorPos(4,6+ans);
- cout << "(" << qlookup[ans-1] << ". " << Questions[q-1][ans] << endl;
- }
- // Display answers as correct.
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->green);
- term->setCursorPos(4,6+Answers[q-1]);
- cout << "(" << qlookup[Answers[q-1]-1] << ". " + Questions[q-1][Answers[q-1]] << endl;
- qNum++;
- if(qNum > numQ)
- {
- getTestResults();
- }
- else
- {
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->lightGray);
- term->setCursorPos(18,13);
- cout << "Press any key. " << endl;
- getch();
- nextQuestion();
- }
- return corr;
- }
- bool getInput()
- {
- // Module will later be used to take key input.
- term->setCursorBlink(false);
- char inp = getch();
- inp = toupper(inp);
- if(inp == 'A') return checkAnswer(qNum,1);
- if(inp == 'B') return checkAnswer(qNum,2);
- if(inp == 'C') return checkAnswer(qNum,3);
- if(inp == 'D') return checkAnswer(qNum,4);
- return getInput();
- term->setCursorBlink(true);
- }
- void exittesting()
- {
- term->setTextColor(colors->white);
- term->setBackgroundColor(colors->black);
- term->setCursorPos(1,22);
- cout << "Thank you for using Lewisk Testing, this program will now exit. " << endl;
- cout << " Press any key. " << endl;
- term->setTextColor(colors->black);
- term->setBackgroundColor(colors->black);
- }
- int main()
- {
- paintutils->initialize(term);
- term->Clear();
- term->setCursorPos(1,1);
- drawQuestion(qNum);
- while(testing)
- {
- getInput();
- }
- exittesting();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement