Pls use C++ to answer thank you! Pls use C++ to answer thank you! Pls use C++ to answer thank you!

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Pls use C++ to answer thank you! Pls use C++ to answer thank you! Pls use C++ to answer thank you!

Post by answerhappygod »

Pls use C++ to answer thank you! Pls use C++ to answerthank you! Pls use C++ to answer thank you!
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 1
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 1 (61.21 KiB) Viewed 36 times
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 2
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 2 (27.95 KiB) Viewed 36 times
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 3
Pls Use C To Answer Thank You Pls Use C To Answer Thank You Pls Use C To Answer Thank You 3 (13.73 KiB) Viewed 36 times
Section C (20%) - Long Questions Answer any ONE out of the TWO questions in this section in the answer book provided. Each question carries 20 marks. If you answer more than one question, only the first attempted question will be marked. Indicate in your answer book clearly which question you are attempting. Question Cl The program below simulates a "pair-matching memory game". At first, the 4 x 6 game board is covered with 12 pairs of symbols and each box on the game board is closed ('X'). Each turn, the player opens 2 boxes on the game board (assume user input is valid). If the symbols at these 2 boxes are the same, these boxes will remain open (i.e., showing the symbols). Otherwise, they will be closed (i.e., showing 'X') again. The player needs to use the fewest turns to open all boxes on the game board by finding all symbols in pairs. Symbols that are used in the game are shown in Table 1 below: ASCII Symbol 33 34 35 36 37 38 ! " # $ % #include #include #include using namespace std; const char CLOSE = 'X'; const int ROW = 4; const int COL = 6; class Box ( public: Box () { private: ( Table 1. List of symbols that are used in the game symbol <= 0; opened false; 39 40 void open() { opened = true; } bool isOpen() { return opened; } char symbol; // stores symbol in a box }; void setSymbol (Box g [ROW] [COL]) { 41 42 43 44 + 8 ) bool opened; // stores if a box is opened // Your codes for C1 (a) should be inserted here 1
Question C1 (continued) void print (Box g [ROW] [COL], int r1, int cl, int x2, int c2) { // Your codes for C1 (b) should be inserted here } bool check (Box g [ROW] [COL], int ri, int cl, int r2, int c2) { // Your codes for C1 (c) should be inserted here bool gameEnd (Box g [ROW] [COL]) { } // Your codes for C1 (d) should be inserted here void choose (int n, int &rl, int &cl, int &r2, int &c2) { cout << "Choose position " << n << ":" << endl; } cout << "row col? "; if (n = 1) else cin >> r1 >> cl; cin >> r2 >> c2; cout << endl; int main() { srand(time (0)); int rl, cl, r2, c2; int turns = 0; Box gameBoard [ROW] [COL]; setSymbol (gameBoard); do { rl=cl = r2 c2 = -1; cout << "Turns: " << ++turns << endl; cout << "__ ----" << endl; print (gameBoard, rl, cl, r2, c2); choose (1, rl, cl, r2, c2); print (gameBoard, rl, cl, r2, c2); choose (2, r1, cl, r2, c2); print (gameBoard, rl, cl, r2, c2); if (check (gameBoard, r1, cl, r2, c2)) cout << "A match, Good!" << endl; else cout << "Not a match!" << endl;
Question C1 (continued) } system ("pause"); system("cls"); while (!game End (gameBoard)) ; cout << "Game ends. You used " << turns << " turns. \n"; return 0; The sample output below will be shown when all parts are completed correctly. Approriate use of loop structure and constant variables are expected in your answers. Sample Output: (the vertical display is shown in row format due to space concern) Turns: 1 0 1 2 3 4 5 0 X X X X X X 1 X X X X X X 2 X X X X X X 3 X X X X X X Choose position 1: row col? 0 0 (Screen is refreshed) Turns: 2 0 1 2 3 4 5 0 X X X X X X 1 X X X X X X 2 X X X X X X 3 X X X X X X Choose position 1: row col? 0 1 (Screen is refreshed) Turns: 3 0 1 2 3 4 5 0 X $ X X X X 1 X X $ X X X 2 X X X X X X 3 X X X X X X Choose position 1: row col? 0 5 (Screen is refreshed) 0 1 2 3 4 5 0, X X X X X 1 X X X X X X 2 X X X X X X 3 X X X X X X Choose position 2: row col? 1 2 0 1 2 3 4 5 0X $X X X X 1 X X X X X X 2 X X X X X X 3 X X X X X X Choose position 2: row col? 1 2 0 X 0 1 2 3 4 5 X X X + 1 X X $ X X X 2 X X X X X X 3 X X X X X X Choose position 2: row col? 1 5 0 2 3 4 5 0 X X X X X " 1 X X X X X 2 X X X X X X 3 X X X X X X Not a match! 1 0 1 2 3 4 5 0X SX X X X 1 X X X X X 2 X X X X X X 3 X X X X X X A match, Good! 0 1 2 3 4 5 0X $X X X + 1 X X $ X X ! 2 X X X X X X 3 X X X X X X Not a match!
Question C1 (continued) Turns: 4 0 1 2 3 4 5 X X X X 0 X 1 X X $ X X X 2 X X X X X X 3 X X X X X X Choose position 1: row col? 1 1 (After a number of turns, and more positions are open...) Turns: 271 0 1 2 3 4 5 0 $ * & + 1 # + $* 2 & & ' 0 X 0 1 2 3 4 5 X X X X 1 XS X X X 2 X X X X X X 3 X X X X X X Choose position 2: row col? 0 5 # X * X " 3) 8( (") Choose position 1: row col? 15 0 1 2 3 4 5 S% 11 + $ 0 1 2 & " (Screen is refreshed) Game ends. You used 27 turns. " X F 11 & 3) 8 ( ( ) Choose position 2: row col? 25 + # ! ★ 0 1 2 3 4 5 0X SX X X + 1 X + $X X X 2 X X X X X X 3 X X X X X X A match, Good! 0 0 1 2 3 4 5 $ * & + 1 + $ # ! & " 1 2 &, 3) A match, 1 11 (( :) Good!
(c) Complete the check() function that checks whether symbol at box (r1, cl) is the same as that in box (r2, c2). If so, the function opens the two boxes, and returns true. Otherwise, it returns false. (4 marks) (d) Complete the game End() function that returns true if the game ends, and returns false otherwise. The game ends if all boxes on the game board are opened. (4 marks)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply