2015东南大学计算机系复试C++自己做的题解

明天就是复试的笔试环节,先做了去年的笔试题,除了没看懂题目的第三题,其他都做出来了。
这是题目:2015东南大学计算机系复试C++自己做的题解_第1张图片
第一题:

#include
#include
#include
using namespace std;

int main()
{
    double x,i=1.0;
    double temp=1.0,sum=1.0,temp1=0.0;
    cin>>x;
    while(1)
    {
        temp1=temp;
        temp*=x/i;
        sum+=temp;
        ++i;
        //cout<
        if(fabs(temp-temp1)<=1e-7 && temp != temp1)
            break;
    }
    cout<10)<<std::fixed<

第二题:

#include
using namespace std;

void func(string s,int length)
{
    if(length>=0)
    {
        if(s[length-1]<='9' && s[length-1]>='0')
        {
            cout<1];
            func(s,length-1);
        }
        else
        {
            func(s,length-1);
        }
    }   
}

int main()
{
    string s;
    getline(cin,s);
    func(s,s.length());
    return 0;
}

第四题:

#include
#include
using namespace std;

void FindRepStr(char str[] , const char findStr[] , const char replaceStr[])
{
    string s1(str),s2(findStr),s3(replaceStr);
    int pos;
    pos = s1.find(s2);
    while(pos!=-1)
    {
        s1.replace(pos,s2.length(),s3);
        pos = s1.find(s2);
    }
    cout<int main()
{
    //cin输入字符串太麻烦了,偷个懒 
    char * str = "helloworld";
    char * s2 = "l";
    char * s3 = "app";
    FindRepStr(str , s2 , s3);
    return 0;
}

第五题:

#include
#include
using namespace std;

class Teacher
{
    public :
        int number;
        string name;
        string sex;
        int birthday;
        int inday;

    //构造函数 
    Teacher(int Number,string Name,string Sex,
    int Birthday=19000000,int Inday)    
    {
        number = Number;
        name = Name;
        sex = Sex;
        birthday = Birthday;
        inday = Inday;
        cout<<"编号为:"<" 姓名为:"<" 性别为:"<" 生日为:"<" 入职日期为:"<//复制构造函数 
    Teacher(const Teacher &t)
    {
        number = t.number;
        name = t.name;
        sex = t.sex;
        birthday = t.birthday;
        inday = t.inday;

    }

    //2016是否退休
    bool Retire_2016()
    {
        if(((2016 - birthday/10000) > 55 && sex == "male")
            ||(((2016 - birthday/10000) > 60) && sex == "female"))
        {
            cout<<"应退休的教师姓名为: "<" 编号为: "<return true;
        }
        else 
            return false;
    } 

    //是否继续聘用女教师
    bool Continue_retire_female()
    {
        if( (2016 - birthday/10000) > 60 && sex == "female" && (2016 - inday/10000) < 35)
        {
            cout<<"继续聘用的女教师姓名为:"<" 编号为: "<return true;
        }
        else 
            return false;
    } 
};

int main()
{
    int number,birthday,inday;
    string name,sex;
    //自己选择测试数据的数量 
    int n;
    cin>>n; 
    for(int i=0;icin>>number>>name>>sex>>birthday>>inday;
        Teacher t(number,name,sex,birthday,inday);
        if(t.Retire_2016())
        {
            //cout<<"应退休的教师姓名为: "<
            if(t.Continue_retire_female())          
                //cout<<"继续聘用的女教师姓名为:"<

            continue;
        }

    }
    //测试复制构造函数 
    Teacher t(number,name,sex,birthday,inday);
    Teacher t2(t);
    cout<" "<return 0;
}

你可能感兴趣的:(c++)