C++Primer第四章习题

//4.21.1
#include<iostream>
#include<vector>

using namespace std;
int main()
{
	vector<int> vi = {1,2,3,4,5,6,7};
	for (auto &e : vi)
	{
		e = (e % 2 != 0) ? e * 2 : e;
		cout << e << " ";
	}
	return 0;
}
//4.21.2
#include<iostream>
#include<vector>

using namespace std;
int main()
{
	vector<int> vi = {1,2,3,4,5,6,7};
	auto beg = vi.begin(),ed = vi.end();
	while (beg != ed)
	{
		if ((*beg) % 2 != 0)
		{
			cout << *beg << endl;
			*beg *= 2;
		}
		beg++;
	}
	return 0;
}
//3.42.1
#include<iostream>
#include<vector>
#include<string>

using namespace std;
int main()
{
	int num;
	string s;
	while (cin >> num)
	{
		s = (num > 90) ? "high pass" : (num > 75) ? "low pass" : (num >= 60) ? "pass" : "fail";
		cout << s << endl;
	}
	return 0;
}
//3.42.2
#include<iostream>
#include<vector>
#include<string>

using namespace std;
int main()
{
	int num;
	string s;
	while (cin >> num)
	{
		if (90 <= num&&num <= 100)
		{
			cout << "high pass" << endl;
		}
		else if (75 <= num&&num<90)
		{
			cout << "low pass" << endl;
		}
		else if (60 <= num&&num<75)
		{
			cout << "pass" << endl;
		}
		else if (0 <= num&&num < 60)
		{
			cout << "fail" << endl;
		}
		else
			cout << "erro" << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38619342/article/details/83004199