0% found this document useful (0 votes)
21 views

First 2010 (1st Sem)

Uploaded by

leenalghoshah
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)
21 views

First 2010 (1st Sem)

Uploaded by

leenalghoshah
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/ 4



CS 101
First Exam 2010 – 2011
Form A
Multiple Choice
Identify the choice that best completes the statement or answers the question.(each one point)

_C___ 1. The basic commands that a computer performs are ____, and performance of arithmetic and logical
operations.
a. input, file, list c. input, output, storage
b. output, folder, storage d. storage, directory, log
_C___ 2. A program called a(n) ____ translates instructions written in high-level languages into machine code.
a. assembler c. compiler
b. decoder d. linker
__A__ 3. Suppose that x is an int variable. Which of the following expressions always evaluates to true?
a. (x > 0) || ( x <= 0) c. (x > 0) && ( x <= 0)
b. (x >= 0) || (x == 0) d. (x > 0) && (x == 0)
__C__ 4. Which of the following expressions correctly determines that x is greater than 10 and less than 20?
a. 10 < x < 20 c. 10 < x && x < 20
b. (10 < x < 20) d. 10 < x || x < 20
__B__ 5. What is the output of the following C++ code?

int x = 35;
int y = 45;
int z;

if (x > y)
z = x + y;
else
z = y – x;

cout << x << " " << y << " " << z << endl;

a. 35 45 80 c. 35 45 –10
b. 35 45 10 d. 35 45 0

Short Answer

6. Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1;


What is the output of the following statements? (5 Points)

OUTPUT
A cout << " x == y : " << (x == y ) << endl; x == y: 0
B cout << " x != z : " << (x != z) << endl; X != z : 1
C cout << " y == z - 3 : " << ( y == z - 3) << endl; Y == z – 3: 1
D cout << " ! (z > w ) : " << ! (z > w ) << endl; ! (z > w): 0
E cout << " x + y < z : " << (x + y < z ) << endl; X+y<z:0


1


7. Suppose a, b, and c are int variables and a = 5 and b = 6. What value is assigned to each variable after each
statement executes? If a variable is undefined at a particular statement, report UND (undefined). (9
points)

a b c
9 7 und
a = (b++) + 3;
9 8 26
c = 2 * a + (++b);
10 99 27
b = 4 * (++c) - (a++);
Problem

8. Rewrite the following statement without using *= and ++ (pre-increment and post-increment),
assuming that var, a, and b are integers. (5 points)
var *= a++ - ++b;

var = var * a – (b+ 1);

a = a + 1;

b = b;

9. Rewrite the following statements using if statement: (6 points)


int x= -1;
x ? x++ : --x;
x ? cout<<x+1: cout<< x+2;

Int x = -1;

If(x)

X = x++;

Else

x = -x;

if (x)

cout << x+1;

else

cout << x + 2


2
10. Write s complete C++ program that reads a number x and then calculates and prints the value
of y according to the following equations: (12 points)

┌ x2 - 1 x >= 10
y= │ 1 0 =< x < 10;
└ 1-x3 x < 0.
#include <iostream>
using namespace std;

void main ()
{
float x,y;
cout << “Please Enter number x” << endl;
cin >> x;
if ( x >= 10)
y = x*x -1;
else
if ( 0 <= x && x < 10)
y = 1;
else
y = 1 - x * x * x;
cout << “y = ” << y << endl;
}

 
3


11. In the following code, correct any errors that would prevent the program from compiling or
running: ( rewrite the code ). (12 points)

include <iostream>

main ( )
{
int a, b;
bool found;
cout << "Enter two integers: ;
cin >> a >> b;
if a > a * b && 10 < b
found = 2 * a > b;
else
{
found = 2 * a < b;
if found
a = 3;
c = 15
if b
{
b = 0;
a = 1;
}
}

#include <iostream>

using namespace std;

int main ()
{
int a, b, c, found;
cout << "Enter two integers: ";
cin >> a >> b;

if (a > a * b && 10 < b)


found = 2 * a > b;
else
{
found = 2 * a < b;
if (found)
a = 3;
c = 15;
if (b)
{
b = 0;
a = 1;
}
}

return 0;
}

prepared by : alhaitham Tawalbeh 4

You might also like