C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[55497] Re:c++ 성적관리프로그램
소녀시대 [] 2612 읽음    2008-12-19 14:01
countStd에 숫자가 들어가는건데
txt 파일에는 학생수가 없네요

o 님이 쓰신 글 :
: 폴더안의 txt파일에서 불러와 출력하는데요..
: 쓰레기값이 들어갑니다...
: ㅠ_ㅠ뭐 잘못된것이 있나요?
:
: <txt파일>
: Smith 23 21 20
: Carpenter 25 30 20
: Stevens 30 25 20
: John 15 20 15
:
: -------------------------------------------------------------------------------
:
: #include <iostream>
: #include <string>
: #include <fstream>
:
: using namespace std;
:
: struct Student
: {
:        string name;
:        int midterm;
:        int final;
:        int homework;
:        int total;
:        char grade;
: };
:
: void score(Student&, const string, const int, const int, const int);
: void print(Student[], const int);
:
: int main()
: {
:     int countStd;
:     ifstream fin;
:     fin.open("scores.txt");
:     if(fin==NULL)
:     cout<<"Error";
:     fin>>countStd;
:
:     Student *myStd = new Student[countStd];
:
:     for(int i=0; i<countStd; i++)
:     {
:             string name;
:             int midterm, final, homework;
:             fin>>name>>midterm>>final>>homework;
:             score(myStd[i], name, midterm, final, homework);
:     }
:
:     print(myStd, countStd);
:     delete[] myStd;
:     return 0;
: }
:
: void score(Student& s, const string name, const int s1, const int s2, const int s3)
: {
:       s.name = name;
:       s.midterm = s1;
:       s.final = s2;
:       s.homework = s3;
:       s.total = s1+s2+s3;
:       switch((int)s.total / 10)
:       {
:             case 10: case 9: s.grade='A';
:                  break;
:             case 8: s.grade='B';
:                  break;
:             case 7: s.grade='C';
:                  break;
:             case 6: s.grade='D';
:                  break;
:             default:
:                     s.grade='F';
:       }
:
: }
:
: void print(Student s[],const int count)
: {
:      cout<<"이름\t"<<"\t중간"<<"\t기말"<<"\t과제"<<"\t총점"<<"\t등급\n";
:      cout<<"****************************************************************************\n";
:      for(int i=0; i<count; i++)
:      {
:              cout<<s[i].name<<"\t"<<s[i].midterm<<"\t"<<s[i].final<<"\t"<<s[i].homework<<"\t"<<s[i].total<<"\t"<<s[i].grade<<endl;
:      }
: }

+ -

관련 글 리스트
55494 c++ 성적관리프로그램 o 2670 2008/12/19
55497     Re:c++ 성적관리프로그램 소녀시대 2612 2008/12/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.