C++面向对象程序设计编程题答案

## C++面向对象程序设计编程题答案
自己练习c++时写的一些代码供大家参考,如有错误请大家指出
//1
/*
	float x, y;
	cin >> x;
	if (x < 1)y = x;
	else if (x >= 1 && x <= 10)y = 2 * x - 1;
	else y = 3 * x - 11;
	cout << y << endl;
	system("pause");
*/
//2
/*
	int i = 0, start;
	for (start = 100;start < 1000;start++)
		if ((start % 10 + start / 10 % 10 + start / 100) % 2 == 0)
			i++;
	cout << i << endl;
	system("pause");
*/
//3
/*
	int a,n=0;
	cin >> a;
	while (a != 0)
	{
		a /= 10;
		n++;
	}
	cout << n;
	system("pause");
*/
//4
/*
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		for (int j = 0;j < n - i;j++)
			cout << ' ';
		for (int j = 0;j < 2 * i - 1;j++)
			cout << i;
		cout << endl;
	}
	system("pause");
*/

//5
/*
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		for (int j = 0;j < n - i;j++)
			cout << ' ';
		for (int j = 0;j < 2 * i - 1;j++)
			cout << '*';
		cout << endl;
	}
	for (int i = 1;i < n;i++)
	{
		cout << "  ";
		for (int j = 0;j < 2 * n - 5;j++)
			cout << '*';
		cout << endl;
	}
	system("pause");
*/
//6
/*
	int n;
	int sum=0;
	int num=1;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		num *= i;
		sum += num;
	}
	cout << sum;
	system("pause");
*/
//6
/*
	int n = 2, i = 3, j = 2;
	while (n < 500)
	{
		cout <<"n:"<< n <<"i:"<<i<<"j:"<<j<< endl;
		n += 3;
		i += 5;
		j += 7;
	}
	system("pause");
*/
//7
/*
	int num = 0;
	int k = 0;
	for(int i=0;i<=10;i++)
		for (int j = 0;j <= (100 - 10 * i) /5 ;j++)
		{
			k = 100 - 10 * i - 5 * j;
			cout << "i:" << i << "j:" << j << "k:" << k << endl;
		}
	system("pause");
*/
//9
/*
	const char*str1 = "ABCDE";
	const char*str2 = "JKLMN";
	for (int i = 0;i < 5;i++)
		for (int j = 0;j < 5;j++)
			if ((i == 0 && j == 0) || (j == 0 && (i == 3 || i == 4)))
				continue;
			else
				cout << "甲队:" << str1[i] << " vs " << "乙队:" << str2[j] << endl;
	system("pause");
*/

//10
/*
	const char*p[5] = { "zhang","wang","li","zhao","弃权:" };
	int n[5] = {0,0,0,0,0};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	cout << "zhang:" << n[0] << " wang:" << n[1] << " li:" << n[2] << " zhao:" << n[3]<<" 弃权:"<<n[4]<<endl;
	cout << "您的选择的是:" << endl;
	COORD pos[6] = {6,0,13,0,18,0,25,0,13,1,32,0};
	cout << endl;
	int flag;
	SetConsoleCursorPosition(hOut, pos[4]);
	cin >> flag;
	SetConsoleCursorPosition(hOut, pos[4]);
	cout << ' ';
	while (flag != -1)
	{
		if (flag > 0 && flag < 5)
		{
			n[flag - 1]++;
			SetConsoleCursorPosition(hOut, pos[flag-1]);
			cout << n[flag - 1];
		}
		else {
			n[4]++;
			SetConsoleCursorPosition(hOut, pos[5]);
			cout << n[4];
		}
		SetConsoleCursorPosition(hOut, pos[4]);
		cin >> flag;
		SetConsoleCursorPosition(hOut, pos[4]);
		cout << ' ';
	}
	system("pause");
*/

//10
/*
	int *pArr = new int[5]{1,2,3,4,5};
	int n = 1;
	int temp;
	temp = n;
	n = pArr[3];
	pArr[3] = temp;
	for (int i = 0;i < 5;i++)
		cout << pArr[i] << endl;
	system("pause");
*/
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值