Question

QUESTION 4                                        &nbsp

QUESTION 4                                                                                                                                                      16 marks
4.1        Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4.                               (4)
4.2        Declare two inttwo‐dimensional arrays, namely  
    play1with ROWSIZEnumber of rows and COLSIZEnumber of columns, and
                                                                             
play2with ROWSIZEnumber of rows and COLSIZEnumber of columns

4.3 Assume that values have been assigned to all the elements of play1and play2. Also assume that
an int variable trickyhas been declared and intialised to 0. Use nested forloops and write
down the necessary C++ statements to do the following:

For example, if play1 and  play2 are initialised as follows:
1 5 3 7 4 6 3 7
6 8 5 8 and        5 0 7 8
3 3 3 5 8 7 6 5
7 8 1 5 7 3 4 5
respectively, then the value of tricky will be:
5+11+3+7+11+8+12+8+11+10+9+5+7+11+5+5=128

Display the value of tricky. Do NOT write a complete program or any functions. Write down ONLY the
required statements.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you like the answer, please give a Thumps up.

Kindly comment, if you need any modifications.

The required statements are

for(int i=0;i<ROWSIZE;i++)
   {
       for(int j=0;j<COLSIZE;j++)
       {
           if(play1[i][j]==play2[i][j])
               tricky+=play1[i][j];/
           else
               tricky+=play1[i][j]+play2[i][j];
       }
   }
   cout<<"Tricky ="<<tricky<<endl;

Complete Program

#include<iostream>
using namespace std;
//Declare two integer constants ROWSIZE equal to 4 and COLSIZE equal to 4.
#define ROWSIZE 4
#define COLSIZE 4
int main()
{
   //Declare and initialize two two‐dimensional arrays,play1 and play2

   int play1[ROWSIZE][COLSIZE]={{1,5,3,7},{6,8,5,8},{3,3,3,5},{7,8,1,5}};
   int play2[ROWSIZE][COLSIZE]={{4,6,3,7},{5,0,7,8},{8,7,6,5},{7,3,4,5}};

   //Declare and initialize variable tricky to 0
   int tricky=0;

   //Each row of play1 is compared element by element to the corresponding row of play2
   //If the elements are equal, add the value of one element to tricky
   //If the elements are not equal, add the sum of the two elements to the value of trıcky
   for(int i=0;i<ROWSIZE;i++)
   {
       for(int j=0;j<COLSIZE;j++)
       {
           if(play1[i][j]==play2[i][j])
               tricky+=play1[i][j];//If the elements are equal, add the value of one element to tricky
           else
               tricky+=play1[i][j]+play2[i][j];//If the elements are not equal, add the sum of the two elements to the value of trıcky
       }
   }
   cout<<"Tricky ="<<tricky<<endl;
}

Program Screenshot

#include<iostream> using namespace std; 1/Declare two integer constants ROWSIZE equal to 4 and COLSIZE equal to 4. #define RO

Output

Tricky =128

Add a comment
Know the answer?
Add Answer to:
QUESTION 4                                        &nbsp
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4.1 4.2 (4) (4) Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4....

    4.1 4.2 (4) (4) Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4. Declare two inttwo-dimensional arrays, namely playlwith ROWSIZEnumber of rows and COLSIZEnumber of columns, and play2with ROWSIZEnumber of rows and COLSIZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of playland play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following: Each...

  • QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal...

    QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWSIZE equal to 4 and COLSIZEequal to 4. Declare two inttwo-dimensional arrays, namely playlwith ROWSIZEnumber of rows and COLSIZEnumber of columns, and play with ROWSIZEnumber of rows and COLSIZEnumber of columns, (4) (4) 4.3 Assume that values have been assigned to all the elements of playland play. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements...

  • QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to...

    QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to 4 and Ca.SI ZEequal to 4. Declare two i nt two-dimensional arrays, namely playlwith ROWI ZEnumber of rows and COLSI ZEnumber of columns, and play2with RONGI ZEnumber of rows and COLSI ZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of pl ayland play 2. Also assume that ani nt variable trickyhas been declared and intialised to 0. Use...

  • QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to...

    QUESTION 4 16 marks 4.1 4.2 (4) (4) Declare two integer constants RONGI ZE equal to 4 and Ca.SI ZEequal to 4. Declare two i nt two-dimensional arrays, namely playlwith ROWI ZEnumber of rows and COLSI ZEnumber of columns, and play2with RONGI ZEnumber of rows and COLSI ZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of pl ayland play 2. Also assume that ani nt variable trickyhas been declared and intialised to 0. Use...

  • QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWI ZE equal to 4 and...

    QUESTION 4 16 marks 4.1 4.2 Declare two integer constants ROWI ZE equal to 4 and CO.SI ZEequal to 4. (4) Declare two i nt two-dimensional arrays, namely (4) playlwith ROMSI ZEnumber of rows and COL SI ZE number of columns, and pl ay2 with ROMI ZEnumber of rows and COL SI ZEnumber of columns, 4.3 Assume that values have been assigned to all the elements of pl ayland play. Also assume that ani nt variable tricky has been declared...

  • 4.3 Assume that values have been assigned to all the elements of playland play2. Also assume...

    4.3 Assume that values have been assigned to all the elements of playland play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following: Each row of playlis compared element by element to the corresponding row of play2. If the elements are equal, add the value of one element to tricky. If the elements are not equal, add the sum of the two...

  • Note: Please answer the question in clear and legible steps. Nothing too advanced, this is a...

    Note: Please answer the question in clear and legible steps. Nothing too advanced, this is a question for introductory C++ class. Thank you. QUESTION: Write C++ statements to declare the following arrays. The name of the array is up to you. Use a const int variable for the array size. a) An array that will hold 7 integers, using an initializer list to set all values to 0. b) An array that will hold 100 doubles. c) An array that...

  • 1. Write a function that converts a string into an int. Assume the int is between...

    1. Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() function. 2. Write a function prototype for problem 1. 3. Write a function call for the function you defined in problem 1. 4. Write a function that converts an int between 10 and 99 into a string. 5. Write a function prototype for problem 4. 6. Write a function call for function you...

  •     (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first...

        (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20.     (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...

  • Write a method named printGrid that accepts two integer parameters rows and cols. The output is...

    Write a method named printGrid that accepts two integer parameters rows and cols. The output is a comma-separated grid of numbers where the first parameter (rows) represents the number of rows of the grid and the second parameter (cols) represents the number of columns. The numbers count up from 1 to (rows x cols). The output are displayed in column-major order, meaning that the numbers shown increase sequentially down each column and wrap to the top of the next column...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT