美文网首页
BIT-CS-2005年复试机试

BIT-CS-2005年复试机试

作者: 小白之白小明 | 来源:发表于2019-02-02 17:03 被阅读2次

1、给定一个程序,关于字符串的,要求输入并调试,说出此程序的意图。意图是按字母顺序对两个字符串比较排序。第二问要求用尽可能少的语句对该程序进行修改,使其能够对两个字符串比较长度排序。

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>  //动态数组(不定长数组)
using namespace std;
//定义排序比较函数
bool len(string a, string b)
{
    return (a.length()<b.length());
}
int main()
{
    string s;
    vector<string> str;
    cout << "请输入字符串,以00结束:";
    while (cin >> s) {
        if (s == "00")
            break;
        str.push_back(s);
    }
    sort(str.begin(), str.end());
    //使用迭代器访问vector
    vector<string>::iterator numer;
    for (numer = str.begin(); numer != str.end(); numer++)
        cout << *numer << " ";
    cout << endl;
    
    sort(str.begin(), str.end(), len);
    //使用下标访问元素
    for (int i = 0; i < str.size(); i++)
        cout << str[i] << " ";
    cout << endl;

    system("pause");
    return 0;
} 

2、编写一个日期类,要求按 xxxx-xx-xx 的格式输出日期,实现加一天的操作,不考虑闰年问题,所有月份设为 30 天。本题黑盒测试时,输入 2004 年 3 月 20日,得到加一天后时间为 2004-3-21 ,能得一部分分数。输入 2004 年 3 月 30 日,得到加一天后时间为2004-4-1,能得一部分分数。输入 2004 年 12 月 30日,得到加一天后时间为 2005-1-1 ,且有时间越界处理,能得全部分数。本题满分 30。

#include<iostream>
using namespace std;
class date{
private:
    int year, month, day;
public:
    date() {};   
    date(int i, int j, int k) :year(i), month(j), day(k) {};   //构造函数初始化列表
    void show() {
        day += 1;
        if (day == 31) {
            month++;
            day = 1;
        }
        if (month == 13) {
            year++;
            month = 1;
        }
        cout << year << "-" << month << "-" << day;
    }
    
};
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    date n(a,b,c);
    n.show();
    system("pause");
    return 0;
} 

3.编写一个复数类,要求有 4 条。一是有构造函数能对复数初始化。二是对复数 c1 ,c2 ,c3 能实现连加运算,令c=c1+c2+c3+ 此处可以重载加法操作符。三是有函数实现两个复数相加,并按照 a+ib的形式输出。四是能实现对一个复数 c=a+ib,定义 double x=c 有效,使 x 的值为实部和虚部之和。本题满分 50。

#include<iostream>
using namespace std;
class fushu {
private:
    double a, b;
public:
    fushu (){}
    fushu(int i, int j) :a(i), b(j) {}
    fushu operator + (fushu kk) {
        return fushu(a + kk.a, b + kk.b);
    }
    void show() {
        cout << a << "+" << b << "i"<<endl;
    }
    double get() {     //实部+虚部
        return (a + b);    
    }
};
int main()
{
    fushu a(1, 2), b(2, 3), c(3, 4), d;
    d = a + b + c;
    d.show();
    double x=d.get();
    cout << x;
    system("pause");
    return 0;
} 

相关文章

  • BIT-CS-2005年复试机试

    1、给定一个程序,关于字符串的,要求输入并调试,说出此程序的意图。意图是按字母顺序对两个字符串比较排序。第二问要求...

  • BIT-CS-2007年复试机试

    1、一个小球,从高为H的地方下落,下落弹地之后弹起高度为下落时的一半,比如第一次弹起高度为H/2,如此反复,计算从...

  • BIT-CS-2000年复试机试

    1、输入任意 4 个字符(如:abcd),并按反序输出(如:dcba)。 2、设 a、b、c 均是 0 到 9 之...

  • BIT-CS-2002年复试机试(A)

    1、某人有 8 角的邮票 5 张,1 元的邮票 4 张,1元 8 角的邮票 6 张,用这些邮票中的一张或若干张可以...

  • BIT-CS-2004年复试机试

    1、建立一个角类,在这个类中重载减号运算符,并实现求出角度的正弦值的函数。

  • BIT-CS-2001年复试机试(B)

    1、请输入高度 h,输出一个高为 h,上底边长为 h的等腰梯形(例如 h=4,图形如下)。 2、请编写一个程序,从...

  • BIT-CS-2002年复试机试(B)

    1、打印所有不超过 n(n<256)的,其平方具有对称性质的数。如 11*11=121。 2、编写一个求菲波那奇数...

  • 试新 感受科技的力量

    华为Mate 9试机照 华为Mate 9试机照 Mate 9试机照 华为Mate 9试机照 华为Mate 9试机照...

  • BIT-CS-2001年复试机试(A)(约瑟夫环链表法)

    1、编写程序,计算下列分段函数 y=f(x)的值。 y= -x+2.5,0<= x <2 y=2-1.5(x-3)...

  • BIT-CS-2006年复试机试(class&vecto

    1、写一个程序判断字符串中数字的位置(不限制使用面向对象编程)例如:输入 a3b4c5,输出 2 4 6 。 2、...

网友评论

      本文标题:BIT-CS-2005年复试机试

      本文链接:https://www.haomeiwen.com/subject/xllcsqtx.html