#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
using std::cin; using std::setprecision;
using std::cout; using std::string;
using std::endl; using std::streamsize;
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 endoffile : ";
int count=0;
double sum=0;
double x;
// 과제 성적 입력
while(cin>>x) {
++count;
sum+=x;
}
//출력
streamsize prec=cout.precision();
cout<<"Your final grade is "<<setprecision(3)
<<0.2 * midterm + 0.4 *final + 0.4 * sum/count;
<<setprecision(prec)<<endl;
return 0;
}
c++에 대한 무뇌한 저로써 생소한 것이 좀 있죠
처음보는 인클루드..
#include <iomanip>
#include <ios>
흠 일단 뭐 대충 보시면 아시겟지만 그리 어려운 코드는 아닙니다.
이름과 성적을 입력받아 결과를 출력하는겁니다.
ios -> c++에서는 .h를 쓰지 않죠
일단 ios는 streamsize를 정의할때 쓰는 거고
streamsize가 뭐냐? 나도 잘 모름
일단 입출력 라이브러리의 크기를 나타내는 타입이라고 볼수 있음
iomanip -> setprecision를 정의합니다.
setprecision은 자릿수를 정의하기 위한 함수(?) 입니다.
주의할점은 while(cin>>x)
보시면 아시겟지만 end of file이 아닐때까지 반복하겠죠?
자세한 설명은 책을 사서 보삼..ㅡㅡ