Sheet#2
Question 1-Which of the following is a correct C++ identifier:
SS / N1 / A$total2 / D_D / S-3 / _amountbudget / ThisIsAlongOne / into / 2ndclass
So_is_this_one / It's / Xyz123 / bool
Question2 - Which of the following is correctly formed constant of type integer?
12,5 / “9” / ‘8’ / 34 / 12.3 / 4.0 / 1 45Question 3 - Declare the following using one statement:
double x;double y;
double z;
char a = ‘i’;
char b;
char c = ‘E’;
Question 4-Write a C++ statement to do the following:
a) Declare two variables of type character; each one is in a separate declaration statement.
b) Declare two variables of type character and initialize them with the values $ and? Respectively in the declaration. NOTE: use one declaration statement.
c) Prompt the user to enter three integer numbers to add and display the sum
d) Read three integers from the keyboard and store them in the variables x, y and z.
e) Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result.
Question5 - Write the following algebraic expressions as C++ expressions:
2−4
2−22
Question 6 - Each of the following assignment statement contains at least one error. Identify them:
Delta=x(y+(3x+(z+15)))
X=5=y+4
Question 7 - Given the algebraic equation y=a x3+7, which of the following, if and y are correct C++ statements for this equation?
a. Y= a*x*x*x+7;b. Y=a*x*x*(x+7);
c. Y=(a*x) * x*(x+7);
d. Y=(a*x)*x*x+7;
Question 8 - Correct the errors in the following programs:
#include<iostreamusing namespace std;
int main();
{
int x; y=2;
z = 4 ;
x=y+z;
cout<”x”;
//print the integer x
}
#include<iostream
using name space std;
int main
{
char a=”$”;
cout<a;
cin>b;
cout<b,
return o;
Question 9 - What is the output by each of the following code fragment?
int x=1;int main()
{
int x=3;
cout<x<endl;
cout<::x<endl;
return 0;
}
int a=1;
int b=-3;
int c=2;
b=a++;
c+=--a+b++;
cout<a<" "<b<" " <c;