【转帖】
姓名:______________ 联系电话:_______________ 简历编号:____________
学校:______________ 专业:___________________ 学历:________________
一. 单选题(每题4分,15题,共60分)
1.考虑函数原型void hello(int a,int b=7,char*pszC="*"),下面的函数调用钟,属于不合法调用的是:Ahello(5) o(5,8) o(6,"#") o(0,0,"#")2.下面有关重载函数的说法中正确的是: A.重载函数必须具有不同的返回值类型 B.重载函数形参个数必须不同 C.重载函数必须有不同的形参列表 D.重载函数名可以不同3.分析一下程序的运行结果:#include
class CBase{public:CBase(){cout<<”constructing CBaseclass”<
本程序从正文文件读入一篇英文短文,统计该短文中不同单词和它的`出现次数,并按词典编辑顺序将单词及它的出现次数输出到正文文件中.
程序用一棵有序二叉树存储这些单词及其出现的次数,一边读入一边建立.然后中序遍历该二叉树,将遍历经过的二叉树上的节点的内容输出.
程序中的外部函数
int getword(FILE* pFile,char* pszWordBuffer,int nBufferLen);
从与pFile所对应的文件中读取单词置入pszWordBuffer,并返回1;若单词遇文件尾,已无单词可读时,则返回0.
#include
#include
#include
#include
#define SOURCE_FILE ""
#define OUTPUT_FILE ""
#define MAX_WORD_LEN 128
typedef struct treenode
{
char szWord[MAX_WORD_LEN];
int nCount;
structtreenode* pLeft;
struct treenode* pRight;
}BNODE;
int getword(FILE* pFile,char* pasWordBuffer,int nBufferLen);
void binary_tree(BNODE** ppNode,char* pszWord)
{
if(ppNode != NULL && pszWord !=NULL)
{
BNODE* pCurrentNode = NULL;
BNODE* pMemoNode = NULL;
int nStrCmpRes=0;
____(1)_____;pCurrentNode=*ppNode
while(pCurrentNode)
{
nStrCmpRes = strcmp(pszWord, ___(2)___);pCurrentNode->nCount
if(!nStrCmpRes)
{
___(3)___; pCurrentNode->nCount++
return;
}
else
{
___(4)___; pMemoNode=pCurrentNode
pCurrentNode = nStrCmpRes>0?pCurrentNode->pRight :pCurrentNode->pLeft;
}
}
}
pCurrent=new BNODE;
if(pCurrentNode != NULL)
{
memset(pCurrentNode,0,sizeof(BNODE));
strncpy(pCurrentNode->szWord,pszWord,MAX_WORD_LEN-1);
pCurrentNode->nCount=1;
}
if(pMemoNode==NULL)
{
___(5)___; *ppNode= pCurrentNode
}
else if(nStrCmpRes>0)
{
pMemoNode->pRight=pCurrentNode;
}
else
{
pMemoNode->pLeft=pCurrentNode;
}
}
void midorder(FILE* pFile,BNODE* pNode)
{
if(___(6)___) return;!pNode||!pFile
midorder(pFile,pNode->pLeft);
fprintf(pFile,"%s%dn",pNode->szWord,pNode->nCount);
midorder(pFile,pNode->pRight);
}
void main()
{
FILE* pFile=NULL;
BNODE* pRootNode=NULL;
char szWord[MAX_WORD_LEN]={0};
pFile=fopen(SOURCE_FILE,"r");
if(pFile==NULL)
{
printf("Cant open file %sn",SOURCE_FILE);
return;
}
while(getword(pFile,szWord,MAX_WORD_LEN)==1)
{
binary_tree(___(7)___);// pRootNode,szWord
}
fclose(pFile);
pFile=fopen(OUTPUT_FILE,"w");
midorder(pFile,pRootNode);
fclose(pFile);
}
三. 附加题(每题30分,2题,共60分)
1. 从程序健壮性进行分析,下面的FillUserInfo函数和Main函数分别存在什么问题?
#include
#include
#define MAX_NAME_LEN 20
struct USERINFO
{
int nAge;
char szName[MAX_NAME_LEN];
};
void FillUserInfo(USERINFO* parUserInfo)
{
stu::cout<<"请输入用户的个数:";
int nCount=0;
std::cin>>nCount;
for(int i=0;i {
std::cout<<"请输入年龄:";
std::cin>>parUserInfo->nAge;
std::string strName;
std::cout<<"请输入姓名:";
std::cin>>strName;
strcpy(me,strName.c_str());
}
}
int main(int argc,char* argv[])
{
USERINFO arUserInfos[100]={0};
FillUserInfo(arUserInfos);
printf("The first name is:");
printf(arUserInfos[0]me);
printf("n");
return 0;
}
2. 假设你在编写一个使用多线程技术的程序,当程序中止运行时,需要怎样一个机制来安全有效的中止所有的线程?请描述其具体流程.