C++/MFC 试题 (2)

三.简答题 (64 分 )

1. 请简述 C 、 C++ 、 VC 、 MFC 在概念上的区别 (4 分 )

2 .请写一个函数重载的简单例子 (4 分 )

3. 用什么函数开启新进程、线程。 (4 分 )

4.SendMessage 和 PostMessage 有什么区别 (4 分 )

5.WaitForSingleObject 有何作用; m_pThrd 的类型是 CWinThread* 时, WaitForSingleObject(m_pThrd->m_hThread, INFINITE); 有何作用。 (4 分 )

6. __stdcall 、 __cdecl 、 __pascal 在什么方面有所不同。 (4 分 )

7 .请把下述代码加上异常处理。 (6 分 )

int MyWriteFile(CString strFileName, CString strText)

{

       int nRet = 0;

       CFile myFile;

       myFile.Open(strFileName, CFile::modeWrite|CFile::shareExclusive|CFile::modeCreate, NULL);

       int nLen = strText.GetLength();

       myFile.Write((char*)(LPCSTR)strText, nLen);

       myFile.Close();

       return nRet;

}

8 .请解释“ func ”为何种类型,这种类型的作用什么,变量 ttt 的值是多少? (6 分 )

typedef int (*func)(int, int*);

int xxx(int a, int *p)

{

       return a + *p;

}

int dowork(func aaa, int bbb, int *ccc)

{

       return aaa(bbb, ccc);

}

int sss = 4;

int ttt = dowork(&xxx, 3, &sss);

9 .请问下述代码中 : int operator+(… )起什么作用? this 是什么? ccc 的值最终为多少? (6 分 )

class Fruit

{

public:

       Fruit()

       {

              weight = 2;

       }

       Fruit(int w)

       {

              weight = w;

       }

       int operator+(Fruit f)

       {

              return this->weight * f.weight;

       }

private:

       int weight;

};

       Fruit aaa;

       Fruit bbb(4);

       int ccc = aaa + bbb;

10. 请解释下面代码采用了何种 C++ 特性( C 语言不具备),作用是什么? (6 分 )

template<typename T>

T sum(T a, T b)

{

       return (a + b);

}

11 .请解释 aaa.h 中下面代码的功能 (5 分 )

#if !defined(AFX_MYSUDU_H__9B952BEA_A051_4026_B4E5_0598A39D2DA4__INCLUDED_)

#define AFX_MYSUDU_H__9B952BEA_A051_4026_B4E5_0598A39D2DA4__INCLUDED_

... ...

#endif

12 . CMemoryState 主要功能是什么 (5 分 )

13 .请阅读下述代码,写出程序执行的结果( 6 分)

#include <iostream>

using namespace std;

class CBase

{

public:

virtual void print()

{

    cout<< "base" << endl;

}

void DoPrint()

{

    print();

}

};

class CChild1: public CBase

{

public:

virtual void print()

{

    cout<< "child1" << endl;

}

};

class CChild2: public CBase

{

public:

virtual void print()

{

    cout<< "child2" << endl;

}

};

void DoPrint(CBase *base)

{

base->DoPrint();

}

void main()

{

CBase* base = new CBase();

CChild1* child1 = new CChild1();

CChild2* child2 = new CChild2();

DoPrint(child1);

DoPrint(child2);

DoPrint(base);

delete base;

base = child1;

base->print();

delete child1;

delete child2;

}

posted on 2011-05-06 19:50  _Clarence  阅读(231)  评论(0编辑  收藏  举报

导航