Accelerated C++ 3 working with batches of data
来源:互联网 发布:java判断闰年的条件 编辑:程序博客网 时间:2024/05/16 06:40
s.percision(n)
Sets the precision of stream s to n for future output (or leaves it unchanged if n is omitted). Returns the previous precision.
setprecision(n)
Returns a value that, when written on an output stream s, has the effect of calling s.precidion(n). Defined in <iomanip>
#include <algorithm>#include <iomanip>#include <ios>#include <iostream>#include <string>#include <vector>int main() { // ask for and read student's name std::cout << "Please enter your first name: " ; std::string name; std::cin >> name; std::cout << "Hello, " << name << "!" << std::endl; // ask for and read the midterm and final grades std::cout << "Please enter your midterm and final exam grades: "; double midterm, final; std::cin >> midterm >> final; // ask for and read the homework grades std::cout << "Enter all your homework grades, " "followed by end-of-file: "; std::vector<double> homework; double x; // invariant: homework contains all the homework grades while(std::cin >> x) { homework.push_back(x); } // check that the student entered some homework grades typedef std::vector<double>::size_type vec_sz; vec_sz size = homework.size(); if (size == 0 ) { std::cout << "You must enter your grades. " "Please try again." << std::endl; return 1; } // sort the grades std::sort(homework.begin(), homework.end()); // compute the median homework grade vec_sz mid = size / 2; double median; median = size % 2 ? homework[mid] : (homework[mid - 1] + homework[mid]) / 2; // compute and write the final grade std::streamsize prec = std::cout.precision(); std::cout << "Your final grade is " << std::setprecision(3) << 0.2 * midterm + 0.4 * final + 0.4 * median << std::setprecision(prec) << std::endl; return 0;}
阅读全文
0 0
- Accelerated C++ 3 working with batches of data
- Chapter 03 Working with batches of data
- Working with EXIF data
- Working with Primitive Data Types
- pandas working with text data
- pandas working with missing data
- Working with Generators of Python
- Accelerated C++<3-2>
- Accelerated C++<4-3>
- AIR:Articles:Working with Binary Data
- Best Practices for Working with Texture Data
- Working with multiple data-sources in UITableView
- android TV-Working with Channel Data
- Android TV -5.2- Working with Channel Data
- 第三章:WORKING WITH TEXT DATA
- Fundamentals of Working with the Database
- Average loss decreases with batches increasing
- MAXScript101_3.3 Working with Modifeirs
- 后台调用前台的含有多个参数的JS方法
- HTTP HTTPS 协议
- Java中的boolean类型
- PHP网页输入框中的换行与PHP读入的Excel换行的区别
- SpringBoot集成redis集群存储字符串和对象
- Accelerated C++ 3 working with batches of data
- Linux 上使用UDEV绑定共享存储
- 获取datatable的前几条数据
- myelipse调试及step into/over/return的区别
- mysql的not in 导致查询无结果原因
- 如何学习ulimit的值
- 面向编程概念
- 简单的MD5加密解密
- 计蒜客1