목록으로 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
섬네일
JSP
1 | 10. 18 | 조회
118
JSP 1
| 11. 27 | 조회
116
XML
dqw | 11. 23 | 조회
114
XML 124
XML
124 | 11. 23 | 조회
113
XML 124
C언어
profile 너에게제공 | 03. 28 | 조회
112
C언어 3-28
6 | 10. 11 | 조회
110
8 | 10. 11 | 조회
109
JSP
9 | 10. 18 | 조회
108
JSP 9
C언어
profile 너에게제공 | 11. 29 | 조회
107
C언어 A
profile 너에게제공 | 10. 04 | 조회
106
C언어
asf | 11. 23 | 조회
105
C언어 af
profile 너에게제공 | 04. 10 | 조회
104