SAP笔试题

本文列举了SAP笔试中涉及到的编程挑战,包括使用模板消除依赖、异常处理、类的设计与继承、函数重载、排序算法、双重链表排序等。此外,还提到了关于游戏策略、数据库查询、字符串与字符串缓冲区的区别、强制类型转换、数据库索引等问题,展示了SAP笔试的广泛性和深入性。
摘要由CSDN通过智能技术生成
发信人: skysnow (王生洪), 信区: Job
标 题: SAP笔试题
发信站: 日月光华 (2004年03月18日19:33:15 星期四), 站内信件
 
1.Below is usual way we find one element in an array:
const int *find1(const int* array, int n, int x)
{
 
    const int* p = array;
    for(int i = 0; i < n; i++)
    {
 
        if(*p == x)
        {
 
            return p;
        }
        ++p;
    }
    return 0;
}
In this case we have to bear the knowledge of value type "int", the size of array, even the existence of an array. Would you re-write it using template to eliminate all these dependencies?
//指针的引用用来确定一个数组的存在
Template<class type, int n>const type *find1(const type *& array, const type & x)
{
  
    const type * p = array;
    for(int i = 0; i < n; i++)
    {
  
        if(*p == x)
        {
  
            return p;
        }
        ++p;
    }
    return 0;
}
 
2. Assume you have a class like
class erp
{
 
    HR* m_hr;
    FI* m_fi;
public:
    erp()
    {
 
        m_hr = new HR();
        m_fi = new FI();
    }
    ~erp()
    {
 
    }
};
if "new FI()" failed in the constructor, how can you detect this problem and release the properly allocated member pointer m_hr?
C++里面不到万不得已别用TRY-CATCH,用 
    
  erp()   
  {   
  auto_ptr<HR>   auto_hr (new   HR());   
  auto_ptr<FI>   auto_fi (new   FI());   
  m_hr   =   auto_hr.release();   
  m_fi   =   auto_fi.release();   
    
  }   
3. Check the class and variable definition below:
#include <iostream>
#include <complex>
using namespace std;
class Base
{
 
public:
    Base() { cout<<"Base-ctor"<<endl; }
    ~Base() { cout<<"Base-dtor"<<endl; }
    virtual void f(int) { cout<<"Base::f(int)"<<endl; }
    virtual void f(double) {cout<<"Base::f(double)"<<endl; }
    virtual void g(int i = 10) {cout<<"Base::g()"<<i<<endl; }
};
class Derived: public Base
{
 
public:
    Derived() { cout<<"Derived-ctor"<<endl; }
    ~Derived() { cout<<"Derived-dtor"<<endl; }
    void f(complex<double>) { cout<<"Derived::f(complex)"<<endl; }
    virtual void g(int i = 20) {cout<<"Derived::g()"<<i<<endl; }
};
Base b;
Derived d;
Base* pb = new Derived;
Select the correct one from the four choices:
Cout<<sizeof(Base)<<endl;
A. 4    B.32    C.20    D.Platform-dependent
Ad?
Cout<<sizeof(Derived)<<endl;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值