- Posts:
- 76
- Group:
- Admins
- Member
- #1
- Joined:
- Jun 25, 2008
- gender
- male
|
...try running this. I made it for my C++ class a while back. 
- Code:
-
// ###### INTRO ##### // /* CCBC CINS 201 - Project 1 Program designed and coded by Roland in March 2008.
Can be used as a test for proficiency in 25 Latin roots, and is easily customizable to fit other definitions. This program ONLY uses the "iostream" include statement, so it could probably be made a heck of a lot smaller if you made the answers random instead of having to put them in a matrix like I did.
Please do not steal this without permission. In fact, just don't steal this at all. */
// ###### INCLUDES ###### //
#include <iostream> using namespace std;
// ###### PROTOTYPES ###### //
void DisplayLatinRoot(int id); void DisplayEnglishDefinitions(int id); void GenerateQuestion(int id, int AnswerMatrix[25][4], int UserResponses[25]); void ShowAmountCorrect(int UserResponses[25]);
// ###### MAIN ###### //
void main() { int UserResponses[25]; // Whether the user got a question right or not will be stored here. int AnswerMatrix[25][4] = // Each number in this matrix represents an english definition. // Every row represents a question, and every column represents // choices A,B,C, and D, repectively. { {0,3,6,14}, {6,1,19,2}, {5,7,16,2}, {7,3,5,21}, {11,13,4,9}, {24,16,1,5}, {12,18,6,20}, {7,4,14,17}, {1,12,18,8}, {23,16,4,9}, {10,1,24,13}, {18,2,11,22}, {8,23,12,3}, {16,13,24,20}, {14,4,17,10}, {7,16,4,15}, {22,16,9,14}, {17,6,9,22}, {18,14,21,6}, {5,10,19,15}, {11,19,7,20}, {5,21,12,8}, {3,2,17,22}, {23,17,15,1}, {12,24,6,5} }; cout << "Welcome to my sweet Latin root test. Pick the correct definition for each\n" << "root to get the best score. Only use the capital letters A, B, C, and D when\n" << "choosing a response.\n\n"; for (int i=0; i<25; i++) { GenerateQuestion(i,AnswerMatrix,UserResponses); } ShowAmountCorrect(UserResponses); }
// ###### FUNCTIONS ###### // void DisplayLatinRoot(int id) // displays the latin roots. For example, when id=1 it displays the // latin root meaning "lead from", the english id 1 { if (id == 0) { cout << "abduc"; } if (id == 1) { cout << "aceto"; } if (id == 2) { cout << "acro"; } if (id == 3) { cout << "affer"; } if (id == 4) { cout << "ambly"; } if (id == 5) { cout << "amino"; } if (id == 6) { cout << "anatol"; } if (id == 7) { cout << "anthro"; } if (id == 8) { cout << "arc"; } if (id == 9) { cout << "austral"; } if (id == 10) { cout << "azyg"; } if (id == 11) { cout << "barb"; } if (id == 12) { cout << "bdella"; } if (id == 13) { cout << "buno"; } if (id == 14) { cout << "coccus"; } if (id == 15) { cout << "dendr"; } if (id == 16) { cout << "embol"; } if (id == 17) { cout << "exiguus"; } if (id == 18) { cout << "oecious"; } if (id == 19) { cout << "phyll"; } if (id == 20) { cout << "plagio"; } if (id == 21) { cout << "rhin"; } if (id == 22) { cout << "sept"; } if (id == 23) { cout << "ungul"; } if (id == 24) { cout << "zon"; } }
void DisplayEnglishDefinitions(int id) // displays the enlish definitions for each root. For example, when id=0 it displays the // english definition of "abduc", the latin id 0 { if (id == 0) { cout << "lead from"; } if (id == 1) { cout << "acid"; } if (id == 2) { cout << "summit"; } if (id == 3) { cout << "carrying to"; } if (id == 4) { cout << "blunt"; } if (id == 5) { cout << "fetal envelope"; } if (id == 6) { cout << "east"; } if (id == 7) { cout << "human"; } if (id == 8) { cout << "arch"; } if (id == 9) { cout << "southern"; } if (id == 10) { cout << "unpaired"; } if (id == 11) { cout << "beard"; } if (id == 12) { cout << "sucker"; } if (id == 13) { cout << "hill"; } if (id == 14) { cout << "berry"; } if (id == 15) { cout << "tree"; } if (id == 16) { cout << "thrown in"; } if (id == 17) { cout << "slender"; } if (id == 18) { cout << "house of"; } if (id == 19) { cout << "leaf"; } if (id == 20) { cout << "oblique"; } if (id == 21) { cout << "rhin"; } if (id == 22) { cout << "seven"; } if (id == 23) { cout << "hoof"; } if (id == 24) { cout << "girdle"; } } void GenerateQuestion(int id, int AnswerMatrix[25][4],int UserResponses[25]) // This function takes the values from the AnswerMatrix and turns them into a question // on the screen, allows the user to respond, and stores whether they got it right or not // in UserResponses. { char ResponseLetter; int ResponseValue = 0, FormatCheck = 1; //Displays question screen cout << id+1 << ". Latin Root: "; DisplayLatinRoot(id); cout << "\n\nA. "; DisplayEnglishDefinitions(AnswerMatrix[id][0]); cout << "\nB. "; DisplayEnglishDefinitions(AnswerMatrix[id][1]); cout << "\nC. "; DisplayEnglishDefinitions(AnswerMatrix[id][2]); cout << "\nD. "; DisplayEnglishDefinitions(AnswerMatrix[id][3]); cout << "\n\nChoose the correct letter: "; while (FormatCheck == 1)// Makes sure that the user inputs a correct character { cin >> ResponseLetter; FormatCheck = 0; // Translates user response into actual "id" value if (ResponseLetter == 'A') { ResponseValue = AnswerMatrix[id][0]; } else if (ResponseLetter == 'B') { ResponseValue = AnswerMatrix[id][1]; } else if (ResponseLetter == 'C') { ResponseValue = AnswerMatrix[id][2]; } else if (ResponseLetter == 'D') { ResponseValue = AnswerMatrix[id][3]; } else // bad response { cout << "Wrong input, try again: "; FormatCheck = 1; } } if (ResponseValue == id) //correct answer { cout << "\nCorrect!"; UserResponses[id] = 1; } else { cout << "\nWrong!" << endl << "The correct answer is: "; // wrong answer DisplayEnglishDefinitions(id); UserResponses[id] = 0; } cout << "\n\n\n\n\n"; // adds a bunch of lines after the question }
void ShowAmountCorrect(int UserResponses[25]) // calculates the amount of correct answers and displays it on the screen. A "1" in the UserResponses // array represents a correct answer, a "0" represents a wrong one. { int CorrectAnswers = 0, WrongAnswers = 0; cout << "\n Incorrect: "; for (int i=0; i<25; i++) { if (UserResponses[i] == 1) { CorrectAnswers = CorrectAnswers + 1; } else // Displays the answers the user gets wrong { cout << endl << i+1 << ". "; DisplayLatinRoot(i); cout << " - "; DisplayEnglishDefinitions(i); } } WrongAnswers = 25 - CorrectAnswers; cout << "\n\nYou got " << CorrectAnswers << " correct and " << WrongAnswers << " wrong!\n\n"; // gives the user a grade if (CorrectAnswers < 15) { cout << "You got an F!\n"; } else if (CorrectAnswers < 18) { cout << "You got a D!\n"; } else if (CorrectAnswers < 20) { cout << "You got a C!\n"; } else if (CorrectAnswers < 23) { cout << "You got a B!\n"; } else { cout << "You got an A!\n"; } }
|