its not 5 questions but a few sub ones but i post anyway. i know some of the answer but just wated to confirm my answers.
B3. Why is it easier to program in high-level languages than in machine
language or assembly language?
B4. Where are programs stored in a computer system?
C1. What are the errors (if any) in the following lines of C++ code:
Code:
main()
int step, start, stop = 100;
step = 5; start = 10.5;
C2. Can a compiler tell if a program will do exactly what is expected of it?
(i.e. can it find logical programming errors?) Give reasons for your
answer.
C3. What are the errors (if any) in the following lines of C++ code:
Code:
int my pay;
Double salary;
int num1; num2;
char 2answers;
B3. How much memory (in bytes) is occupied by each of the following
variables?
double number; int count, index; char yesno;
B4. What is the output of the following code segment?
Code:
int num = 100;
cout << “Decimal : “ << dec << num << “\n”; cout << “Octal : “
<< oct << num << “\n”; cout << “Hexa : “
<< hex << num << “\n”;
Section C: C++ language Syntax & Debugging
C1. Why are include files like <iostream> needed?
C2. Spot and correct the errors in the following code:
Code:
#include <iostream>
using namespace std;
#include <iomanip> #define PI=3.14
Main()
{
int count; double colorVal
cout << “Enter an integer number ;
cin >> “count” ;
colorVal = PI*count;
cout << "\nThe color value is : " << setw(8)
<< fix << setprecision(2) << colorVal;
}
B1. Evaluate the following expressions:
(a) 21 % 4 % 2 * 3 + 2
(b) 25 % 3 + 2
(c) 18 + (5==5) * 10 % 4
(d) 5/2 + (85 >= 86)
B2. Study the following code and write the output.
Code:
main()
{
int x, y, z=4;
y = (7+6) % 5 / 2; cout << y << “\n” ;
z *= 3 + 2; cout << z << “\n” ;
x=y==z; cout << x << “\n” ;
}
Section C: C++ language Syntax & Debugging
C1. Will the compiler give any error for the following code?
Code:
double temp;
cout << “Enter a floating point number :”;
cin << temp;
B1. Consider the code given below:
Code:
int direction;
if (direction == 1)
cout << “Robot moving left\n”;
else if (direction == 2)
cout << “Robot moving right\n”;
else if (direction == 3)
cout << “Robot moving up\n”;
else if (direction == 4)
cout << “Robot moving down\n”;
else
cout << “Robot standing still\n”;
Re-write the above code using a switch statement.
Section C: C++ language Syntax & Debugging
C1. What is wrong (if anything) with the following code?
Code:
x=80;
if (x = 100) cout << "Excellent" ;
C2. Determine the errors in the following program.
Code:
main()
{
int a=5, b=10; char operation;
cout<<“Enter the operation [+, -, * or /]:);
cin >> operation ;
switch (operation)
case ‘+’ : c = a+b;
case ‘-’ : c = a-b;
case ‘*’ : c = a*b;
case ‘/’ : c = a/b;
};
cout << a << operation << b <<”=”<< c;
}
Section B: Programming Concepts
B1. What will be the output of the following code:
Code:
int i;
for(i=10; i<20; i=i+2)
{
cout << i*10 ;
}
B2. Rewrite the code in B1 using a while loop
B3. What is the output of the following code?
Code:
int count = 1, odd = 0;
do
{
if ( (count % 2) != 0 )
odd++;
count++;
}while (count<10);
cout << “odd = “ << odd;
Section C: C++ language Syntax & Debugging
C1. Spot and correct the errors in the following code segments:
(a)
Code:
int num;
for(num=1, num<=10, num=num+1)
{
cout << “The square of num is : << num*num ;
}
(b)
Code:
char input;
double voltage current;
while (input = y);
{
cout << “Enter the voltage and current : “;
cin >> voltage >> current;
cout << “The resistance is ” << voltage/current;
cout << Do you wish to continue [y/n] : “;
input << cin ;
}