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

Lab04_5.cpp is provided. It compiles but when you run it, it displays only the h

ID: 3730827 • Letter: L

Question

Lab04_5.cpp is provided. It compiles but when you run it, it displays only the headings “compound assignment” and “increment and decrement” on the console. No meaningful results are displayed because the insertion statements have been commented out.

First, examine the code in Lab04_5.cpp. Imagine that the insertion statements have been uncommented, and complete the Expected columns of this table:

Insertion

Expected

Observed

Insertion

Expected

Observed

compound assignment

increment and decrement

01

a: 4

01

a: 2

02

02

03

03

04

04

05

05

06

06

07

07

08

08

09

09

10

10

11

12

13

14

15

16

// Filename Lab04_5.cpp

// YOUR NAME:

// CCCC CSC120 Fall 2009

// DATE:

#include <iostream>

using namespace std;

int main()

{

int a = 1;

int b = 1;

int c = 1;

int d = 1;

cout << "compound assignment" << endl;

a = a + 3;

b += 3;

// cout << "01 a: " << a << endl;

// cout << "02 b: " << b << endl;

a = a - c;

b -= c;

// cout << "03 a: " << a << endl;

// cout << "04 b: " << b << endl;

a = a * 5;

b *= 5;

// cout << "05 a: " << a << endl;

// cout << "06 b: " << b << endl;

a = a / 5;

b /= 5;

// cout << "07 a: " << a << endl;

// cout << "08 b: " << b << endl;

a = a % 2;

b %= 2;

// cout << "09 a: " << a << endl;

// cout << "10 b: " << b << endl;

cout << "increment and decrement" << endl;

a = a + 1;

b += 1;

// cout << "01 a: " << a << endl;

// cout << "02 b: " << b << endl;

c++;

++d;

// cout << "03 c: " << c << endl;

// cout << "04 d: " << d << endl;

a = b = 0;

a = c++;

b = ++d;

// cout << "05 a: " << a << endl;

// cout << "06 b: " << b << endl;

// cout << "07 c: " << c << endl;

// cout << "08 d: " << d << endl;

a = a - 1;

b -= 1;

// cout << "09 a: " << a << endl;

// cout << "10 b: " << b << endl;

c--;

--d;

// cout << "11 c: " << c << endl;

// cout << "12 d: " << d << endl;

a = b = 0;

a = c--;

b = --d;

// cout << "13 a: " << a << endl;

// cout << "14 b: " << b << endl;

// cout << "15 c: " << c << endl;

// cout << "16 d: " << d << endl;

return 0;

}

Insertion

Expected

Observed

Insertion

Expected

Observed

compound assignment

increment and decrement

01

a: 4

01

a: 2

02

02

03

03

04

04

05

05

06

06

07

07

08

08

09

09

10

10

11

12

13

14

15

16

Explanation / Answer

compound assignment
01       a: 4
02       b: 4
03       a: 3
04       b: 3
05       a: 15
06       b: 15
07       a: 3
08       b: 3
09       a: 1
10       b: 1
increment and decrement
01       a: 2
02       b: 2
03       c: 2
04       d: 2
05       a: 2
06       b: 3
07       c: 3
08       d: 3
09       a: 1
10       b: 2
11       c: 2
12       d: 2
13       a: 2
14       b: 1
15       c: 1
16       d: 1