Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each of the given program segments, determine if there is an error in the co

ID: 3551349 • Letter: F

Question

For each of the given program segments, determine if there is an error in the code. If there is an error, specify whether it is a logic error or a syntax error, circle the error in the program, and write the corrected code in the space provided after each problem. If the code does not contain an error, write "no error." [Note: It is possible that a program segment may contain multiple errors.

PART 1___________________________________________________________________________-

1 #include <iostream>

2

3 using std::cout;

4 using std::endl;

5

6 #Include <iomanip>

7

8 using std::setw;

9

10 int main()

11 {

12     int n[ 3][ 3] = { {1, 2, 3}, { 4, 5, 6},     { 7, 8, 9}};

13

14     cout << setw( 10) << n[ 0 ][ 0]    << n[ 0][1]

15            << n[ 0] [ 2] << endl << n[ 1 ][ 0 ]

16           << n[ 1][1] << n[1][2] << endl

17           << n[ 2][0] << n[2][1] << n[ 2][2]

18          << endl;

19     return 0;

20 }

_______________________________________________________________________________

PART 2(see below)

1 #include <iostream>

2

3 using std::cout;

4 using std::endl;

5

6 #include <iomanip>

7

8 using std::hex;

9 using std::dec;

10 using std::oct;

11 using std::setbase;

12

13 int main()

14 {

15     double n = 32;

16

17     cout << n << " in hexadecimal is: "

18            << hex << n << endl

19            << n << " in octal is: "

20            << oct << n << endl

21            << n << " in decimal is: "

22           << dec << n << endl;

23

24     return 0;

25 }

Explanation / Answer

PART 1)

#include <iostream>


using std::cout;

using std::endl;


#Include <iomanip> // here "Include" should be changed as "include" and this is syntax error.


using std::setw;


int main()

{

int n[ 3][ 3] = { {1, 2, 3}, { 4, 5, 6}, { 7, 8, 9}};


cout << setw( 10) << n[ 0 ][ 0] << n[ 0][1]

<< n[ 0] [ 2] << endl << n[ 1 ][ 0 ]

<< n[ 1][1] << n[1][2] << endl

<< n[ 2][0] << n[2][1] << n[ 2][2]

<< endl;

return 0;

}

PART 2)

NO ERROR