목록으로 2012.11.15. 14:59
C언어

s

youtube


const int MAX=3; // 학생 수를 상수 MAX로 지정

class Student
{
 string name;
 int score[3];
 int sum;
 double avg;
    public:
  string getName(){return name;}
  int getScore(int i){return score[i];}
  int getSum(){return sum;}
  double getAvg(){return avg;}
  void setName(string n){name = n;}
  void setScore(int i, int s){score[i]=s;}
  void setSum(){sum=score[0]+score[1]+score[2];}
  void setAvg(){avg=sum/3.0;}

};

int main()
{       
    Student std[MAX]; // Student 객체 배열 std 선언
    ifstream input;       
    int i;

    string name;
    int score1, score2, score3;

    input.open("c:\student.txt");  // c:\student.txt  파일 열기

    if (input.fail())  // 파일 열기에 실패하면
        return 0;


    i = 0;
    while (input.eof()==false)   // 파일의 끝이 아니면
    {
        input >> name >> score1 >> score2 >> score3;  // 파일에서 읽기

      std[i].setName(name);
   std[i].setScore(0,score1); // 객체 배열에 저장
   std[i].setScore(1,score2);
   std[i].setScore(2,score3);
   std[i].setSum();
   std[i].setAvg();

 

 

       cout <<std[i].getName() <<std[i].getScore(0)<<std[i].getScore(1)<<
     std[i].getScore(2)<<"t"<< std[i].getSum()<<"t"<<std[i].getAvg() <<
     endl;    // 화면에 출력

 

 

        i++;
    }
    input.close();
}

 

댓글 0

댓글 작성 권한이 없습니다. 로그인하기

NO
TITLE
섬네일
E비즈니스
profile 너에게제공 | 10. 16 | 조회
8
E비즈니스 E_비즈니스 PPT
E비즈니스
profile 너에게제공 | 10. 26 | 조회
7
E비즈니스 f
E비즈니스
profile 너에게제공 | 11. 05 | 조회
6
E비즈니스 맞춤형안경
E비즈니스
| 11. 11 | 조회
5
E비즈니스 위생정리
E비즈니스
| 11. 15 | 조회
4
E비즈니스 블랙리스트
E비즈니스
profile 너에게제공 | 12. 03 | 조회
3
E비즈니스 r견적
E비즈니스
profile 너에게제공 | 12. 10 | 조회
2
E비즈니스 스마트메뉴
E비즈니스
2 | 12. 20 | 조회
1
E비즈니스 javascript:void(0);