?? 3-5.cpp
字號:
#include<algorithm>
#include<iomanip>
#include<ios>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> name;
vector<double> scort;
while(1)
{
cout<<"Please enter your first name: ";
string s,r;
cin>>s;
if(s=="exit")
break;
cout<<"Hello, "<<s<<"!"<<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);
cin.clear(); //清除錯(cuò)誤標(biāo)記
cin>>r; //吸收錯(cuò)誤輸入
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];
name.push_back(s);
scort.push_back(median);
}
for(vector<string>::size_type i=0;i<name.size();++i)
cout<<name[i]<<" "<<scort[i]<<endl;
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -