Starting from:
$30

$24

Lab 2 Problems Solution

This lab contains two questions.




Q1. Predict the outputs of the following program.(Before running it). Then run the code and check if your answers are correct.




```c++

#include <iostream

#include <cmath

using namespace std;

int main() {

int x = 6, y = 0, z = 3;

double a = 5.0, b= 4.0;

cout << x << x * a << endl; // line (a)

cout << (y / z) << "\nn\n" << z / x << endl; // line (b)

cout << sqrt(b) * sqrt(b) / x * z << endl; // line (c)

cout << (z % y) / (y % x) << endl; // line (d)

cout << x << "%" << y << "=" << "x % y" << "\n"; // line (e)

}

```




- What is the ouput at line (a)?

- What is the ouput at line (b)?

- What is the ouput at line (c)?

- What is the ouput at line (d)?

- What is the ouput at line (e)?




---




Q2. Write a complete C++ program that asks the user for a number of gallons and then outputs the equivalent number of liters. There are 3.78533 liters in a gallon. Use a declared constant. Since this is just an exercise, you need not have any comments in your program.

More products