게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 기초 공부하는 대학생입니다. 막히는게 있어서 도와주셨으면 합니다.
게시물ID : programmer_14661짧은주소 복사하기
작성자 : 곰같은힘이여
추천 : 0
조회수 : 575회
댓글수 : 5개
등록시간 : 2015/11/29 10:13:53
옵션
  • 본인삭제금지
학교 과제로 txt 파일에서 최소 15명의 학생 이름, ID번호, 4개의 시험점수를 불러온 뒤 출력하고
각 학생들의 최종 점수를 계산후 최종 점수의 평균과 최대, 최소값을 구하는 프로그램을 만들고 있습니다.
일단 제가 만든걸 봐주셨으면 합니다.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream grades;
    grades.open("grades.txt");
   
    float weight[4]; //weight of 4 exams, 각 시험의 점수 비중, 프로그램 맨 처음에 출력되어야 함

    grades >> weight[0] >> weight[1] >> weight[2] >> weight[3];

    cout << "Weight of exam: " << weight[0] << ", " << weight[1] << ", " << weight[2] << ", " << weight[3] << endl;

    while (grades)
    {
        char name[100]; // student name 학생 이름
        double stdid; // student id no. ID번호
        float grade[4]; // student grade 시험점수
        float fingrade; // final grade 최종점수
        float classavg;
        grades >> name >> stdid >> grade[0] >> grade[1] >> grade[2] >> grade[3];
       
        fingrade = (grade[0]*weight[0])+ (grade[1]*weight[1]) + (grade[2]*weight[2]) + (grade[3]*weight[3]);
       
       
        cout << "Name: " << name << ", ID: " << stdid << ", Record: " << grade[0] << ", " << grade[1] << ", " << grade[2] << ", " << grade[3] << endl;
        cout << "Final grade of this student is " << fingrade << endl<<endl;
    }
   

    grades.close();
    system("pause");
    return 0;
}


각 학생들의 이름(name), ID번호(stdid),  시험점수 4개(grade)랑 최종점수(fingrade)를 출력하는데까지는 성공했는데

각 최종점수들의 평균과 최대, 최소값을 어떻게 구해야 할지 모르겠습니다.

고수분들 조언좀 부탁드립니다.
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호