北京理工大学2005年计算机考研复试机试题

在这里插入图片描述

#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
bool length(string a,string b)
{
	return a.length()<b.length();
}
int main()
{
	string s;
	vector<string>str;
	cout<<"请输入字符串,以00结束"<<endl;
	while(cin>>s)
	{
		if(s=="00")
		break;
		str.push_back(s);
	}
	cout<<"按字典排序:"<<endl;
	sort(str.begin(),str.end());
	vector<string>::const_iterator i;
	for(i=str.begin();i!=str.end();i++)
	cout<<*i<<" ";
	cout<<endl;
	cout<<"按长度排序:"<<endl;
	sort(str.begin(),str.end(),length);
	for(i=str.begin();i!=str.end();i++)
	cout<<*i<<" ";
	cout<<endl;
	return 0;
}

在这里插入图片描述

#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 resolve()
		{
			day++;
			if(day==31)
			{
				month++;
				day=1;
			}
			if(month==13)
			{
				year++;
				month=1;
			}
			cout<<"加一天后的日期为:"<<year<<"-"<<month<<"-"<<day<<endl; 
		}
};
int main()
{
	int year,month,day;
	cout<<"请输入一个日期,以0 0 0结束"<<endl;
	while(cin>>year>>month>>day)
	{
		if(year==0&&month==0&&day==0)
		break;
		date d(year,month,day);
		if(day>30||year<1||month<1||day<1||month>12)
		{
			cout<<"没有这样的日期!"<<endl;
			cout<<"请重新输入"<<endl;
			
		}
		else
		d.resolve();
		cout<<"请输入一个日期,以0 0 0结束"<<endl;
	}
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;
class fushu
{
	private:
		int a,b;
	public:
		fushu(){
		};
		fushu(int i,int j)
		{
			a=i;
			b=j;
		}
		fushu operator+(fushu k)
		{
			return fushu(a+k.a,b+k.b);
		}
		void show()
		{
			cout<<a<<"+"<<"i"<<b<<endl;
		}
		int jia()
		{
			return a+b;
		}
};
int main()
{
	fushu c1(1,2),c2(2,3),c3(5,4),c4;
	cout<<"复数c1,c2,c3分别为:"<<endl;
	c1.show();
	c2.show();
	c3.show();
	c4=c1+c2+c3;
	cout<<"c1+c2+c3的和为:"<<endl;  
	c4.show();
	double c=c4.jia();
	cout<<"定义的double类型值为:"<<endl;
	cout<<c<<endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值