What is the expected result of the following program?
Which code, inserted at line 10, generate the output "50"?
#include <iostream>
using namespace std;
class Base {
int age;
public:
Base () {
age=5;
};
//insert code here
void Print() { cout << age;}
};
void setAge(Base &ob) {ob.age = 0;}
int main () {
Base a;
a.Print();
setAge(a);
a.Print();
return 0;
}
Analyze the code below. If it contains an error, indicate its place in the program.
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this?>s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o?>Print();
}
The following declaration:
int i = 0b10;
What is the output of the program?
#include <iostream>
using namespace std;
#define PRINT(i) cout<<i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
What is the output of the program given below?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3, s4;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3<< s4;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 5;
do {
i??;
cout<<i;
}
while(i >= 0);
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
namespace newname = myNamespace1;
using namespace newname;
cout << x << " ";
cout << y;
return 0;
}
PDF + Testing Engine
|
---|
$66 |
Testing Engine
|
---|
$50 |
PDF (Q&A)
|
---|
$42 |
C++ Institute Free Exams |
---|
![]() |