Progamming with C++ and java
MA 478 TIME: 3 HOURS
Instruction: Answer all questions in the answer booklet provided
1) C++ is an extension of C, which was developed by Bjarne Stroustrup at Bell
Laboratories during 1983–1985.
2) The features of C are supported by C++
3) An international standard for C++, known as C++98, was created by the
International Standard Organization (ISO) in 1998 and currently 2011.
4) Java uses C++ syntax, it is easy to learn Java if you know C++.
5) The library like iostream is called a header file in C++, because it is usually
included at the head of a program.
6) C++ programs are built from pieces called classes and functions.
7) A string must be enclosed in quotation marks.
8) The value 0 indicates that the program has terminated with a successful exit.
9) In C++, a comment is preceded by two slashes (//) on a line, called a line comment
10) Like any other programming language, C++ has its own rules of grammar, called
syntax.
11) The C++ compiler command performs three tasks in sequence namely
preprocessing, compiling, and linking.
12) The machine-code file is also known as an object file.
13) Give the output of the code below
Int main ()
{
Cout << “celcius 35 is fahrenheit degree” << endl;
Cout << (9/5) * 35 + 32 << endl;
Return 0;
celcius 35 is fahrenheit degree
67
14) The cout object along with the stream insertion operator (<<) can be used to
display a string on the console.
15) Every statement in C++ must end with a semicolon, known as the statement
terminator.
16) Functions are programming units that represents complex operations
17) Variables are used to represent values that may be changed in the program. T/F
18) A variable must be declared before it can be assigned a value.
19) A variable declared in a function must be assigned a value. Otherwise, the variable
is called uninitialized and its value is unpredictable.
20) Fix the error in the code above;
Int main ()
{
Int i = k + 1;
Cout << I << endl;
Int i = 1;
Cout << i << endl;
Return 0;
}
21) A named constant is an identifier that represents a permanent value.
22) The word const is a C++ keyword for declaring a constant.
Fill the spaces in the table if neceessary;
Name Synonymy Storage Size
23) Short
24) long
25) float
26) double
27) If you know the value stored in a variable is always nonnegative, declare it as
unsigned
28) The double type is usually twice as big as float.
29) In C++, the % operator is for integers only.
30) The operators +, -, *, /, and % can be combined with the assignment operator to
form augmented operators.
31) There are no spaces in the augmented assignment operators. For example, + =
should be +=. T/F
32) Show the printout of the following code
Int a = 6;
a *= a + 1;
cout << a << endl;
a /= 2;
cout << a << endl;
33) The increment (++) and decrement (--) operators are for incrementing and
decrementing a variable by 1. T/F
34) Show the printout of the code below
Int a = 6;
Int b = a++;
Cout << a <<endl;
Cout << b << endl;
35) Give the output of the code below
Int a = 6;
Int b = ++a;
Cout << a <<endl;
Cout << b << endl;
36) The pow(a, b) function can be used to compute 𝑎 .
37) pow is a function defined in the cmath library.
38) The program can decide which statements to execute based on its information.T/F
39) A Boolean expression is an expression that evaluates to a Boolean value: true or
false.
40) C++ provides eight relational operators, which can be used to compare two values.
T/F
41) An if statement is a construct that enables a program to specify alternative path of
execution.
42) Give the syntax for one-way if statement
43) Correct the code below
If i > 0;
{
Cout << “I is positive” << endl;
}
44) Duplicated statements in if-else statements and testing equality of double values
are common pitfalls. T/F
45) The braces can be omitted if the block contains a single statement.
46) The logical operators !, &&, and || can be used to create a compound Boolean
expression. T/F
Complete the table below
Operator Name Description
!
&&
||