0% found this document useful (0 votes)
23 views5 pages

NAME

Uploaded by

mansha.yameen456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

NAME

Uploaded by

mansha.yameen456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: FAHAD MANSHA Reg: 25-ARID-799

1. Write each of the following as a C++ expression.

a. 32 times a plus b
Answer: int a, b;

int result = 32 * a + b;

b. The character that represents 8


Answer: char ch = '8';

c. The string that represents the name Julie Nelson.


Answer: string name = "Julie Nelson";

d. (b² - 4ac) / 2a
Answer: int a, b, c;

int result = (b * b - 4 * a * c) / (2 * a);

e. (a + b) / c * (e * f) - gh
Answer: int a, b, c, g, h;

float e, f;

float result = ((a + b) / c) * (e * f) - g * h;

f. (-b + (b² - 4ac)) / 2a


Answer: int a, b, c;
double result = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);

---

2. Suppose x, y, z, and w are int variables. What value is assigned


to each of these variables after the last statement executes?

x = 5;

z = 3;

y = x - z;

z = 2 * y + 3;

w = x - 2 * y + z;

z = w - x;

w++;

Answer:
x=5

y=2

z=3

w=9

---
3. Suppose x, y, and z are int variables and w and t are double
variables. What value is assigned to each of these variables after
the last statement executes?

x = 17;

y = 15;

x = x + y / 4;

z = x % 3 + 4;

w = 17 / 3 + 6.5;

t = x / 4.0 + 15 % 4 - 3.5;

Answer:
x = 20

z=6

w = 11.5

t = 4.5

---

4. Suppose x, y, and z are int variables and x = 2, y = 5, and z = 6.


What is the output of each of the following statements?

a. cout << "x = " << x << ", y = " << y << ", z = " << z << endl;
Answer: x = 2, y = 5, z = 6
b. cout << "x + y = " << x + y << endl;
Answer: x + y = 7

c. cout << "Sum of " << x << " and " << z << " is " << x + z << endl;
Answer: Sum of 2 and 6 is 8

d. cout << "z / x = " << z / x << endl;


Answer: z / x = 3

e. cout << "2 times " << x << " = " << 2 *x << endl;
Answer: 2 times 2 = 4

---

5. What is the output of the following statements? Suppose a


and b are int variables, c is a double variable, and a = 13, b = 5,
and c = 17.5.

a. cout << a + b – c << endl;


Answer: 0.5

b. cout << 15 / 2 + c << endl;


Answer: 24.5
c. cout << a / (double)b + 2 * c << endl;
Answer: 39.6

d. cout << 14 % 3 + 6.3 + b / a << endl;


Answer: 7.3

e. cout << (int)c % 5 + a – b<< endl;


Answer: 11

f. cout << 13.5 / 2 + 4.0 * 3.5 + 18 << endl;


Answer: 37.75

You might also like