📄 3-0.cpp
字号:
#include<algorithm>
#include<iomanip>
#include<ios>
#include<iostream>
#include<string>
#include<vector>
/*
using std::cin;
using std::sort;
using std::cout; //来自原文的申明
using std::endl; //这些申明为什么不可用??????
using std::setprecision;
using std::streamsize;
using std::string;
using std::vector;
*/
using namespace std; //更改成这样就可以了
int main()
{
cout<<"Please enter your first name: ";
string name;
cin>>name;
cout<<"Hello, "<<name<<"!"<<endl;
cout<<"Please enter your midterm and final exam grades: ";
double midterm,final;
cin>>midterm>>final;
cout<<"Enter all your homework grades, "
"followed by end-of-file: ";
vector<double> homework;
double x;
while(cin>>x)
homework.push_back(x);
typedef vector<double>::size_type vec_sz;
vec_sz size=homework.size();
if(size==0)
{
cout<<endl<<"You must enter your name grades. "
<<"please try again."<<endl;
return 1;
}
sort(homework.begin(),homework.end());
vec_sz mid=size/2;
double median;
median=(size%2==0)?(homework[mid]+homework[mid-1])/2
:homework[mid];
streamsize prec=cout.precision();
cout<<"Your final grade is "<<setprecision(3)
<<0.2*midterm+0.4*final+0.4*median
<<setprecision(prec)<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -