Question 1:
a) The statement #include is normally added at the strating of a program. What is the purpose of this statement?
b)
- Describe what is meant by explicit type conversion.
- Give a simple example to support your answer to part (i)
c) Find out the trace table for the given program:
1. //Program to illustrate arithmetic operations
2. #include
3. using namespace std;
4.
5. int main() {
6. int ThisVal, ThatVal, ThisVal2;
7. const int TheVal = 5;
8.
9. ThisVal = 3;
10. ThatVal= 2 * ThisVal + 7 / ThisVal * TheVal;
11. ThisVal2 = ThatVal * ThisVal / 9 + 8;
12.
13. cout << “ThisVal = “ << ThisVal;
14. cout << “; ThatVal = “ << ThatVal << endl;
15. cout << ThisVal2 = “ << ThisVal2;
16. cout << “; TheVal = “ << TheVal << endl;
17.
18. return 0;
19. }
d) Write a program which displays all the odd numbers from 1 to 100 on separate lines. Use for loop.
e) What is the output when the given code fragment is executed?
char ch;
char title[] = "Programming";
ch = title[1];
title[3] = ch;
cout << title << endl;
cout << ch << endl;