我是靠谱客的博主 唠叨香菇,最近开发中收集的这篇文章主要介绍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");
*/

最后

以上就是唠叨香菇为你收集整理的C++面向对象程序设计编程题答案的全部内容,希望文章能够帮你解决C++面向对象程序设计编程题答案所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(26)

评论列表共有 0 条评论

立即
投稿
返回
顶部