叠拓测试笔试题
2. both test3 and test4 are pointer object of struct s.
8. What’s the output of the code? (10 points)
1) #include <iostream>
using namespace std;
class Base
{
public:
virtual void f(float x){ cout << "Base::f(float) " << x << endl; }
void g(float x){ cout << "Base::g(float) " << x << endl; }
void h(float x){ cout << "Base::h(float) " << x << endl; }
};
class Derived : public Base
{
public:
virtual void f(float x){ cout << "Derived::f(float) " << x << endl; }
void g(int x){ cout << "Derived::g(int) " << x << endl; }
void h(float x){ cout << "Derived::h(float) " << x << endl; }
};
void main(void)
{
Derived d;
Base *pb = &d;
Derived *pd = &d;
pb->f(3.14f);
pd->f(3.14f);
pb->g(3.14f);
pd->g(3.14f);
pb->h(3.14f);
pd->h(3.14f);
}
Result:
Derived::f(float) 3.14
Derived::f(float) 3.14
Base::g(float) 3.14
Derived::g(int) 3.14
Base::h(float) 3.14
Derived::h(float) 3.14
不错哦
2) #include <iostream>
using namespace std;
class A
{
public:
A(){ doSth(); }
virtual void doSth(){cout <<"I am A";}
};
class B:public A
{
public:
virtual void doSth(){ cout <<"I am B";}
};
void main(void)
{
B b;
}
Result: I am B
9. Write a function to convert a word from the "big-endian" format to the "little-endian" format. (15 points)
void convertToLittleEndian(unsigned int *data)
{
unsigned int temp = 0;
ASSERT(data == NULL);
temp = *data;
*data = (((temp & 0x000000FF) << 24)
| ((temp & 0x0000FF00) << 8)
| ((temp & 0x00FF0000) >> 8)
| ((temp & 0xFF000000) >> 24));
}
10, please implement the function memcpy(void *dest, const void *src, size_t size) (15 points)
void *memcpy(void *dest, const void *src, size_t size)
{
char *pDest = dest;
char *pSrc = src;
ASSERT((dest == NULL) || (src == NULL));
while (size-- > 0)
{
*pDest++ = *pSrc++;
}
return (void *)dest;
}
更多推荐:
- 计算机二级vf笔试真题
- 全国计算机二级笔试
- 计算机二级access笔试