Do you believe it's from our C++ exam?

J

joehust

Caculate the value of i after each step
int x=2, y=x+30;

struct A{

static int x;

int y;

public:

operator int( ){ return x+y; }

A operator ++(int){ return A(x++, y++); }

A(int x=::x+2, int y=::y+3){ A::x=x; A::y=y; }

int &h(int &x);

};

int &A::h(int &x)

{

for(int y=1; y!=1 || x<201; x+=11, y++)

if(x>200) { x-=21; y-=2;}

return x-=10;

}

int A::x=23;

void main( ){

A a(54, 3), b(65), c;

int i, &z=i, A::*p=&A::y;

i=b.x; //.................................¢Ù

z=a.x; //.................................¢Ú

i=c.*p; //.................................¢Û

i=a++; //.................................¢Ü

i=::x+c.y; //.................................¢Ý

i=a+b; //.................................¢Þ

b.h(i)=7; //.................................¢ß

}

and another one, write down the ouput of this program

#include <iostream.h>

struct A{A( ){ cout<<'A';}};

struct B{B( ){ cout<<'B';}};

struct C: A{C( ){ cout<<'C';}};


struct D: virtual B, C{D( ){ cout<<'D';}};

struct E: A{

C c;

E( ): c( ){ cout<<'E';}

};

struct F: virtual B, C, D, E{

F( ){ cout<<'F';}

};

void main( ){

A a; cout<<'\n';

B b; cout<<'\n';

C c; cout<<'\n';

D d; cout<<'\n';

E e; cout<<'\n';

F f; cout<<'\n';

}
 
V

Victor Bazarov

Caculate the value of i after each step
[..]

Aside from the use of global variables (which has its place),
and 'void main', what's your objection? Is it too easy? Too hard?
Did you find that you could do it, but most couldn't? What?
and another one, write down the ouput of this program

[..]

Again, 'void main', and the use of an obsolete header <iostream.h>.
So? Did you solve it? It's not that difficult, and I am *sure* it
addresses just the topics your course contained.

V
 
A

anon

struct A{

static int x;

int y;

public:

operator int( ){ return x+y; }

A operator ++(int){ return A(x++, y++); }

A(int x=::x+2, int y=::y+3){ A::x=x; A::y=y; }

int &h(int &x);

};

LOL @ struct A. It is written as x and y are private.

Easy exam, wasn't it?
 
G

Guest

LOL @ struct A. It is written as x and y are private.

Easy exam, wasn't it?

Maybe, but you failed. Since it's a struct all members are public by
default, so x and y are public, and the 'public:' is unnecessary.
 
A

anon

Erik said:
Maybe, but you failed. Since it's a struct all members are public by
default, so x and y are public, and the 'public:' is unnecessary.

I might have expressed myself wrongly, but read again what I wrote. To
me it looks like whoever wrote it expected x and y to be private.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,164
Latest member
KerrieWind

Latest Threads

Top