⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4-7.cpp

📁 Accelerated C++ 课后练习题 本人自己完成、可供参考
💻 CPP
字号:
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

using namespace std;
int main()
{
	vector<double> store;
	double x;
	typedef vector<double>::size_type vec_sz;
	
	while(cin>>x)
		store.push_back(x); 

	
	vec_sz size;
	size=store.size();

	if(size==0)
		throw domain_error("an empty vector!");

	sort(store.begin(),store.end());	

	vec_sz mid=size/2;
	double average=size%2==0?(store[mid]+store[mid-1])/2:store[mid];
	cout<<"The average is:  "
		<<average<<endl;

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -