华南师大计算机学院软件工程专硕机试(2017考研)

前言

前两天考研公布成绩,看成绩结合群里人的分数大概率是进复试了,于是就翻出之前的机试题来看下难度,查缺补漏再去找一些类似的题目。

所有题目代码用C++编写

题目均为回忆版

 

1.输入一个数字,为其高,一个符号*,输出该符号组成的平行四边形形状

 

源码

#include<iostream>
using namespace std;
int main(){
    int n;
    cout<<"please input a number:";
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=n-i-1;j>=0;j--){
            cout<<"  ";
        }
        for(int k=0;k<n;k++){
            cout<<"*";
        }
        cout<<endl;
    }
    return 0;
}

 

结果:

please input a number:5
          *****
        *****
      *****
    *****
  *****

 

 

二、是猴子吃桃问题,每天都吃剩下的一半,再多吃一个,直到第十天剩下一个桃子,问第一天猴子有多少个桃。

源码:

(递归)

#include<iostream>
using namespace std;

int function(int i){
    if(i==1)
        return 1;
    return 2*(function(i-1)+1);
}

int main()
{
    cout<<function(10)<<endl;
}

(for循环)

#include<iostream>
using namespace std;
int main(){
    int number = 1; //第十天的数量
    for(int i=0;i<9;i++){
        number = (number + 1) * 2;
    }
    cout<<number<<endl;
    return 0;
}

结果:

1534

 

 

三、输入一系列的数字,输出他们正负数个数,输入0截止,要用函数实现 

源码

#include<iostream>
using namespace std;

int LargerThanZero = 0;     //大于零的个数
int SmallerThanZero = 0;    //小于零的个数

void Function(int n){
    if(n>0)
        LargerThanZero++;
    else if(n<0)
        SmallerThanZero++;
}

int main(){
    cout<<"please input numbers:";
    int n;
    cin>>n;
    while(n!=0){
        Function(n);
        cin>>n;
    }

    cout<<"Stop"<<endl;
    cout<<"Larger Than Zero:"<<LargerThanZero<<endl;
    cout<<"Smaller Than Zero:"<<SmallerThanZero<<endl;
}

 

结果:

please input numbers:1 9 2 3 -7 6 -6 -1 0
Stop
Larger Than Zero:5
Smaller Than Zero:3

 

 

四、是用一个类来记录学生成绩和他班级,里面有几个函数,静态成员和动态成员都有

因为题目是回忆版的,题目概述不清,根据之前看过的教材大概自己设置几个函数与静态成员

#include<iostream>
#include<string>
using namespace std;

class Student{
    public:
        Student(string n,int c,double sco){
            name=n;
            Class=c;
            score=sco;
            num++;
            total+=sco;
            average=total/(double)num;
        }
        static double Got_Total(){
            return total;
        }
        static int Got_num(){
            return num;
        }
        static double Got_Ave(){
            return average;
        }
        void display();                 //显示个人信息
        void Change_Score(double n);    //更改分数
        void Change_Class(int c);       //更改班级
    private:
        string name;
        int Class;
        double score;
        static double total;
        static int num;
        static double average;
};


void Student::display(){
    cout<<"Name:"<<name<<endl;
    cout<<"Class:"<<Class<<endl;
    cout<<"Score:"<<score<<endl;
}

void Student::Change_Class(int c){
    Class=c;
    cout<<"After Change:"<<endl;
    display();
}

void Student::Change_Score(double s){
    total-=score;
    score=s;
    total+=score;
    average=total/(double)num;
    cout<<"After Change:"<<endl;
    display();
}

double Student::total = 0;
int Student::num = 0;
double Student::average = 0;


int main(){
    Student Stu[5]={
        Student("Obama",1,99.0),
        Student("Mike",1,77.5),
        Student("Jackson",2,87.0),
        Student("Cherry",3,93.5),
        Student("Oscar",4,89.0)
    };

    for(int i=0;i<5;i++)
    {
        cout<<endl;
        Stu[i].display();
    }

    cout<<endl<<"Total:"<<Student::Got_Total()<<endl;
    cout<<"Numbers of Student:"<<Student::Got_num()<<endl;
    cout<<"Average:"<<Student::Got_Ave()<<endl;

    cout<<endl;
    Stu[0].Change_Score(100);
    cout<<endl<<"Total:"<<Student::Got_Total()<<endl;
    cout<<"Numbers of Student:"<<Student::Got_num()<<endl;
    cout<<"Average:"<<Student::Got_Ave()<<endl;
        
}

 

结果:

Name:Obama  
Class:1     
Score:99    

Name:Mike   
Class:1     
Score:77.5  

Name:Jackson
Class:2     
Score:87    

Name:Cherry
Class:3
Score:93.5

Name:Oscar
Class:4
Score:89

Total:446
Numbers of Student:5
Average:89.2

After Change:
Name:Obama
Class:1
Score:100

Total:447
Numbers of Student:5
Average:89.4

 

 

五、重载+,++,=等简单运算符

这题跟上面一样也是不太清楚,所以我以时间为例写一个重载运算符

#include<iostream>
using namespace std;


class Time{
    private:
        int sec;
        int min;
    public:
        Time(int m=0,int s=0){
            min=m;
            sec=s;
        }

        void operator = (Time a){
            min=a.min;
            sec=a.sec;
        }

        void display(){
            cout<<min<<":"<<sec<<endl;
        }

        friend Time operator +(Time &a,Time &b);
        Time operator ++ ();    //前置
        Time operator ++ (int); //后置
};

Time operator +(Time &a,Time &b){
    Time t;
    t.sec=a.sec+b.sec;
    t.min=a.min+b.min;
    if(t.sec>=60)
    {
        t.sec-=60;
        t.min++;
    }
    return t;
}

Time Time::operator++(){
    this->sec++;
    if(this->sec>=60)
    {
        this->sec-=60;
        this->min++;
    }
    return *this;
}

Time Time::operator++(int){
    Time t=*this;
    this->sec++;
    if(this->sec>=60)
    {
        this->sec-=60;
        this->min++;
    }
    return t;
}

int main(){
    Time a;
    cout<<"a:";
    a.display();
    cout<<"++a:";
    ++a;
    a.display();
    cout<<endl;

    cout<<"a++ (b) :";
    Time b=a++;
    b.display();
    cout<<"a:";
    a.display();

    cout<<"a+b:";
    Time c;
    c=a+b;
    c.display();

}

 

结果:

a:0:0
++a:0:1

a++ (b) :0:1
a:0:2
a+b:0:3

 

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
华东师范大学软件学院机试准备方面,CSDN是一个非常好的资源。 CSDN(中国软件开发者网络)是一个面向软件开发者的在线社区,拥有大量的技术博文、教程、源码和问答等资源。对于准备机试的学生来说,CSDN可以提供各种与计算机科学和软件开发相关的学习资料,帮助他们更好地进行准备。 首先,CSDN上有许多博主分享自己的机试经验和面试心得,这对于准备机试的学生非常有参考价值。他们可以从别人的经验中学习到一些应试技巧和策略,帮助自己更好地应对机试的各个环节。 其次,CSDN上有大量的技术教程和源码,可以帮助学生系统地学习机试所需的各个知识点。无论是数据结构、算法、操作系统还是数据库等,CSDN都有相应的教程资源可供学生学习和参考。学生可以通过自学这些教程,掌握机试所需的相关知识和技能。 此外,CSDN上还有很多开源项和实际项的源码,学生可以借鉴这些源码,学习实际项中的编程技巧和实现方法。这对于提高编程能力和解决实际问题非常有帮助,也能使学生在机试中更加熟练地运用自己所学的知识。 综上所述,在华东师范大学软件学院机试准备方面,CSDN是一个非常宝贵的资源。通过利用CSDN上的各种教程、博文和源码等资源,学生可以更好地准备机试,提高自己的应试能力和编程水平。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值