Professional Documents
Culture Documents
Hardware : Refers to the parts of a computer that you can see and touch, including
the case and everything inside it.
Software : Refers to the instructions, or programs, that tell the hardware what to
do.
Data : Known facts in a form a computer can store and use.
(textual, numeric, etc)
Information : Processed data or any knowledge that can be communicated.
Algorithm : Instructions for solving a problem or sub-problem in a finite amount of
time using a finite amount of data.
Data type : The specification of how data or information is represented in the
computer.
Computer Data type specifications and instructions for carrying out operations
program : that are used by a computer to solve a problem.
Identifier : is a name used to identify a variable, function, class, module, or any
other user-defined item.
Computer : A programmable device that can store, retrieve, and process data.
Control
Unit
4. Draw a block diagram of the process of converting a program written in high level
language into machine code.
Library
Syntax Error
5.
C++ Program Flow Chart
#include<iostream> Start
using namespace std;
void main()
{ Read n
int n;
cout << "Enter a number:\n";
cin >> n; yes no
if (n % 2 == 0) n%2=0
{
if (n>0) yes no yes no
cout<< "It is even +ve"<< endl; n>0 n>0
else
cout<< "It is even -ve"<< endl;
} Print Print Print Print
else even +ve even -ve odd +ve odd -ve
{
if (n>0)
cout<< "It is odd +ve"<< endl;
else
cout<< "It is odd -ve"<< endl; End
}
} p
6.
C++ Program Flow Chart
#include<iostream>
Start
using namespace std;
void main() i= 1
{ int x;
for (int i=1; i<4 ; i++)
{ Read x
cout << "Enter a number:\n"; i=i+1
cin >> x; No I=1
if(x==7) No Yes
{ i=3 x=7
cout<< "You win"<<endl; Yes
break;
} //end of if Print you win
Print you lose
else if (i==3)
cout<< "you lose" <<endl;
} //end of for
} End
7.
C++ Program Flow Chart
#include<iostream> Start
using namespace std;
End
8.
C++ Program Flow Chart
#include<iostream> Start
using namespace std;
Print abs
End
9.
End
11.
End
12.
End
a) C is Uppercase char
b) 5 is a Digit
c) If we put any special character (as , . ; : etc.)
d) No we can't , because there is a comparison in if else statement
a) 8
b) 8
c) 8
d) 8
e) 8
int n;
cout << "Enter an integer: ";
cin >> n;
if (n < 10)
cout << "less than 10" << endl;
else if (n > 5)
cout << "greater than 5" << endl;
else
cout << "not interesting" << endl;
a) less than 10
b) greater than 5
c) greater than 5
d) no values
e)
a) start()
b) system()
c) main()
d) program()
a) . (dot)
b) ; (semi-colon)
c) : (colon)
d) ' (single quote)
3) Which of the following is a correct comment?
a) */ Comments */
b) **Comment**
c) /* Comment */
d) // Comment
e) { Comment }
f) Both c , d
g) None of the above
a) c=c+3
b) c+=3
c) c+++
d) c =+3
e) both c , d
f) none of the above
a) ^
b)
c) <<
d) >>
a) char ch ='b';
b) char ch ='0';
c) char ch ="cc";
a) (y < x < z)
b) ((y < x) && z)
c) ((y > x) || (y < z))
d) ((y < x) && (x < z))
9) Given the following code:
#include<iostream>
using namespace std;
void main ( )
{
int score;
cout << "Enter your test score: ";
cin >> score;
switch (score/10)
{
case 10:
case 9: cout << "Your grade is A" << endl; break;
case 8: cout << "Your grade is B" << endl; break;
case 7: cout << "Your grade is C" << endl; break;
case 6:
case 5: cout << "Your grade is D" << endl; break;
case 4:
case 3:
case 2:
case 1:
case 0: cout << "Your grade is F" << endl; break;
default: cout << "Error: score is out of range.\n";
}
cout << "Goodbye" << endl;
}
21. Put (F) for the false statement and correct it, otherwise put (T) :
1) The body of the while loop may never execute. T
2) The opposite of (x >3 || x < 10) is (x < 3 && x > 10). F (x >= 3 && x <= 10)
3) Loops are used when we need our program to make a choice between two or more things.
F Conditional Statements
4) It is legal to declare more than one variable in a single statement. T
5) The opposite of less than or equal is greater than or equal. F is only greater than
6) All switch statements can be converted into nested if-else statements. T
7) All nested if-else statements can be converted into switch statements. F some not all
8) A break statement in a switch stops your program. F stops the switch case
9) The compiler ignores comments and does not translate them into machine code. T
10) A data type of a value determines how this value is represented in computer memory. T
11) When you create a variable, you reserve some space in memory. T
12) The name of a variable can be composed of letters, digits, and special characters.
F and underscore only
13) An if statement must be followed by else statement, which executes when the Boolean
expression is false. F can be optional followed by else statement
14) The "do...while loop" repeats a statement or group of statements while a given condition is
true. It tests the condition before executing the loop body. F while loop
15) Program comments are explanatory statements that you can include in the C++ code that
you write and helps anyone reading it's source code. T
16) y = x++ means that we first increase x by 1 then assign the new value of x into y. F y=++x
17) y = --x is called post-decrement operation. F pre-decrement
18) if x = 5 then x / 2 = 2.5 . T
19) if y = 6 and x = 2 then x % y = 0 . F x%y=2 (there's 0 remaining of 2 in 6 + 2 remaining)
20) The % operator can be used with float and integer operands. F only with integer
22. Evaluate each of the following expressions, assuming in each case that m has the value 25
and n has the value 7:
a) m - 8 - n (ans. 10)
b) m = n = 3 (ans. m=3 and n=3)
c) m % n (ans. 4)
d) m % n++ (ans. 4)
e) m % ++n (ans. 1)
f) ++m - n-- (ans. 19)
23. In each of the following statements, assume that m has the value 5 and n has the value 2
before the statement executes. What will be the values of m and n will be after each of the
following statements executes?