(a) Name three key features of object oriented programming. Is C++: (b) compiled or interpreted ; (c) statically or dynamically type-checked? (d) a subset of ANSI C, a superset of ANSI C, or neither?
(a) What is the purpose of access control to data values?
(b) In the code fragment below, which variables are accessible and which
are not?
class A {
int x;
int y, z;
public:
int a;
private:
int b, c;
};
(c) How may a private variable be made public to one selected function only?
Evaluate the following expressions assuming that the initial
values given are set for each one:
int i = 2; int j = 3; char c = 'Z'; float f = 32.2; (Z has ASCII value 90)
Expr1: 1 <= j < 3Expr2: c - 20 / 10 % jExpr3: i -- - -- jExpr4: i + j + f / 2Expr5: j = 5 && iExpr6: j += 5 && cExpr7: j += c -= 2 * iExpr8: i - 2 || c || j / 10In the following program fragment, state what the scope and lifetime is of each of the names (include all the names).
int x;
extern int y;
static int z;
void function1(int a, int b)
{
int c;
static int d;
while (c) {
int e;
e = c + 1;
{ int e = 10;
if (e == c)
return;
}
}
}
Given this class declaration:
class A {
private:
int x, y;
public:
A() { x = y = 10; }
A(int xx, int yy) { x = xx; y = yy; }
...
};
which of the following will finish with an object a having x = 10 and y = 5?
A a(5);A a(5, 10);A a();a.y = 5;A a(10, 5);For the class A, below, define the two constructors given in appropriate ways.
class A {
const int y;
int x;
public:
A() ....????....
A(int xx) ....????....
...
};
In what two situations are reference variables best used Which of the following are correct and which are not, give a suitable declaration of class A?
What does the following program print?
#include <iostream.h>
int main()
{
class A {
private:
char *str;
public:
A(char *s) { str = s; }
char operator-(int i) { return str[i]; }
};
A s1("this is a string");
cout << s1-8 << endl;
}