Review of Variables and Math Operations

1.                What is printed by the following code?

#include <iostream>

#include <string>

using namespace std;

/*****************************************/

// program from chapter 2 of the Malik Book

// Date:

// Programmer:

/****************************************/

int main ( )

{

int firstNum, secondNum;

double z;

char ch;

string name;

firstNum = 4;

secondNum = 2 * firstNum + 6;

z = (firstNum + 1) /2.0;

ch = 'A';

cin >> secondNum;

cin >> z;

firstNum = 2 * secondNum + static_cast <int> (z);

cin >> name;

secondNum = secondNum + 1;

cin >> ch;

firstNum = firstNum + static_cast<int>(ch);

z = firstNum - z;

return 0;

}

2.                What is printed by the following code?

#include <iostream>

using namespace std;

/*********************************/

//Illustrating assignment and operations

/*********************************/

int main ( )

{

int i = 2, j = 99;

int ans ;

i = i + 1;

i ++;

i = 5;

j = 9;

i = i - 1;

i --;

j --;

ans = i + j;

ans = i++  + j;

ans = ++i + j;

ans = i-- + j;

ans = --i + j;

ans += 2;

ans *= 2;

ans += j + 2 * i;

return 0;

}

3.                Write a C++ program that

1)    prompts the user to input 3 decimal numbers (with a fraction part)

2)    Prints the three decimal numbers.

3)    Converts each decimal number to the nearest integer.

4)    Prints the three converted numbers.

4.                Complete the following program:

//This program inputs a Celsius temperature

//and outputs both the Celsius

//temperature and its equivalent Fahrenheit temperature.

#include<iostream>

using namespace std;

int main()

{

float celsius;

float faren;

//prompt the user to input celsius temp

cin >> celsius;

//compute the equivalent fahrenheit

cout << "Celsius: " << celsius << " degrees" << endl;

// print out Fahrenheit now

return 0;

}