Work 版 (精华区)
发信人: victor (☆★那一剑的风情★☆), 信区: Work
标 题: 金山的考题
发信站: 哈工大紫丁香 (2002年11月17日16:35:47 星期天), 站内信件
**你好,
欢迎你应聘金山,下面是我们提供的一份网上试题。请答完题后尽快寄给我们。
另外,如果你有一定的程序经验,欢迎提供你的代码让我们可以参考(如果不设计到
机密、版权问题的话)。
/* ---------------------------------------------- */
/* 重要:请写出你的答题思路 */
一、阅读以下代码,写出程序运行结果。
class Base
{
public:
Base() {}
~Base() {}
virtual void SayHello() { printf("Hello "); }
virtual void SayWord() { printf("World!\n"); }
};
void Say(Base& obj)
{
obj.SayHello();
obj.SayWord();
}
class BaseOne : public Base
{
protected:
virtual void SayHello() {}
};
class BaseTwo : public BaseOne
{
protected:
virtual void SayWord() { printf("Kingsoft!\n"); }
};
void main()
{
Base Obj;
BaseOne Obj1;
BaseTwo Obj2;
Say(Obj);
Say(Obj1);
Say(Obj2);
}
二、任给四个不同的正整数,每个正整数最多使用1次,请问这四个正整数能够加和的结果
共有多少种,同时请按以下格式列出每种有多少个分布以及不分先后次序的实例。
例如,对于1,2,3,4四个数,输出如下:
加和的结果共有10种,分别是:
1有1种分布:
1 = 1
10有1种分布:
10 = 1 + 2 + 3 + 4
6有2种分布:
6 = 1 + 2 + 3
6 = 2 + 4
...
请描述你的思路,并且用C/C++或者Pascal语言实现。
三、按要求编写以下函数。
功能: 将给定缓冲区中的#字符移到字符串尾部
函数名称:ChangeToTail
入口参数:pSZ指向缓冲区的指针, nSize缓冲区长度
出口: pSZ所指缓冲区中的#字符被移到缓冲区尾部
返回值: 在出口缓冲区中第一个#的位置,若缓冲区中无#字符则返回-1
说明: 如传入(#W#W#W#WW#, 10) 则传出时应转换为WWWWW#####并且返回值为5
int ChangeToTail(BYTE* pSZ, UINT nSize)
{
// Todo:请在此加入您的代码
}
四、阅读以下程序,纠正其中的错误。
class CCelsius
{
public:
CCelsius() { m_nC = 0; }
~CCelsius() {}
short ToFahrenheit() { return m_nC * 9 / 5 + 32; }
void SetC(short nCelsius) { m_nC = nCelsius; }
short GetC() { return m_nC; }
protected:
short m_nC;
};
class CFahrenheit
{
public:
CFahrenheit() { m_nF = 0; }
~CFahrenheit() {}
short ToCelsius() { return (m_nF - 32) * 5 / 9; }
void SetF(short nFahrenheit) { m_nF = nFahrenheit; }
short GetF() { return m_nF; }
protected:
short m_nF;
};
class CTemperature : public CCelsius , public CFahrenheit
{
public:
CTemperature();
~CTemperature();
BOOL CreateLevel(UINT nSize);
void ReleaseLevel();
UINT GetLevel(int nCelsius);
protected:
UINT m_nSize;
short* m_pLevel;
};
/* ------------------------------ */
CTemperature::CTemperature()
{
m_nSize = 0;
m_pLevel = NULL;
}
CTemperature::~CTemperature()
{
ReleaseLevel();
}
BOOL CTemperature::CreateLevel(UINT nSize)
{
ASSERT(m_pLevel == NULL);
if (m_pLevel)
return FALSE;
m_pLevel = new short[nSize];
if (m_pLevel == NULL)
return FALSE;
for (UINT i = 0; i < nSize; i++)
m_pLevel[i] = 100 * i * i;
m_nSize = nSize;
return TRUE;
}
void CTemperature::ReleaseLevel()
{
if (m_pLevel)
{
delete [] m_pLevel;
m_nSize = 0;
m_pLevel = NULL;
}
}
UINT CTemperature::GetLevel(int nT)
{
ASSERT(m_pLevel);
for (UINT nLevel = 0; nLevel < m_nSize; nLevel++)
{
if (m_pLevel[nLevel] > nT)
break;
}
return nLevel;
}
void OutC(CCelsius* pC)
{
if (pC)
printf("摄氏%d度等于华氏%d度\n", pC->GetC(), pC->ToFahrenheit());
}
void OutF(CFahrenheit* pF)
{
if (pF)
printf("华氏%d度等于摄氏%d度\n", pF->GetF(), pF->ToCelsius());
}
void OutL(CTemperature* pT)
{
if (pT)
{
printf("摄氏%d度的等级为:%d\n", pT->GetC(), pT->GetLevel(pT->GetC()));
printf("华氏%d度的等级为:%d\n", pT->GetF(), pT->GetLevel(pT->GetF()));
}
}
/* ------------------------------ */
void main()
{
CTemperature* pTemperature = new CTemperature;
if (pTemperature == NULL)
return;
CCelsius* pCelsius = (CCelsius*)pTemperature;
pCelsius->SetC(100);
OutC(pCelsius);
CFahrenheit* pFahrenheit = (CFahrenheit*)pCelsius;
pFahrenheit->SetF(400);
OutF(pFahrenheit);
pTemperature->CreateLevel(3);
OutL(pTemperature);
CTemperature* pTempOther = new CTemperature;
if (pTempOther == NULL)
return;
*pTempOther = *pTemperature;
delete pFahrenheit;
OutL(pTempOther);
delete pTempOther;
}
五、说说你最近写的,或者你构思的一个程序,并且尽量去描述你考虑到的关于该程序的
一些想法,比如说你为什么要做这样一个程序,你又如何设计它?。
--
我在天空写下你的名字,却被风带走了;
我在沙滩上写下你的名字,却被浪花带走了;
于是,我在大街的每个角落写下你的名字,
我靠,我被警察带走了。
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.230.170]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.166毫秒