Вы находитесь на странице: 1из 1

# UNIVERSITY OF WEST FLORIDA

## ELECTRICAL & COMPUTER ENGINEERING DEPT

C++ FOR ENGINEERS (EEL 4834)
HOMEWORK #1, Due Tuesday Feb 1
Spring 2011

1) What, if anything, prints when each of the following C++ statements is executed? If nothing prints, then
answer “nothing” Assume x=2 and y=3.
a) cout << x;
b) cout << x + x;
c) cout << “x =”;
d) cout << “x = “ << x;
e) cout << x + y << “ = “ << y + x;
f) z = x + y;
g) cin >> x >> y ;
h) // cout << “x +y = “ << x + y;
i) cout << “\n”;

2) Which of the following C++ statements contain variables whose values are replaced? Specify those variables.
a) cin >> b >> c >> d >> e >> f;
b) p = i + j + k -7;
c) cout << “Values of a and b are:” << a<<’ ‘ << b;
d) cout << “a = 5”;

3) Given the algebraic equation y=(2x3 + 5)/(x+1), which of the following, if any, are correct C++ statements for
this equation?
a) y = 2 * x * x * x + 5/(x+1);
b) y = 2 * (x * x * x + 5)/(x+1);
c) y = ( 2 * x ) * x * ( x + 5 );
d) y = (( 2 * x ) * x * x + 5)/(x+1);
e) y = (2 * ( x * x * x ) + 5)/x+1;
f) y = (2 * x^3+ 5)/(x+1);

4) State the order of evaluation of the operators in each of the following C++ statements and show the value of x
after each statement is performed.
a) x = 8 + 4 * 10 / 2 – 1;
b) x = 4 % 4 + 4 * 4 – 4 / 4;
c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );

## 5) Write a program to:

• prompt the user to enter two numbers
• get the two numbers from the user
• print the sum, product, difference, and quotient of the two numbers (something like: The two numbers
you entered were xx and xx. Their sum = xx, their product = xx, and their quotient = xx.) Be
careful when the second number is 0 (need an if-else statement).

6) Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the
larger number followed by the words “is larger”. If the numbers are equal, print the message “These
numbers are equal”.

7) Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area.
Use the constant value 3.14159 for π. Do these calculations in output statements.

8) Write a program that reads in two integers and determines and prints if the first is a multiple of the second.
(Hint: Use the modulus operator to determine if the first is a multiple of the second.)