게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 고수님들 질문있습니다!
게시물ID : programmer_8424짧은주소 복사하기
작성자 : 문선명
추천 : 0
조회수 : 606회
댓글수 : 8개
등록시간 : 2015/03/03 18:36:00
옵션
  • 본인삭제금지
현재 노력중인 학생입니다.초보라서  전부 다 짜달라고 했다가 완전히 혼났습니다. 
아래 코드를 보시면! 최고 최저 평균 톤수를 구할수는 있는데!
각 톤수에 100톤씩 빼서 최고 최저 평균 톤수를 구할수 있는방법을 알고 싶습니다.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Data
{
 string name;
 double weight;
 double wra;
 double speed;
 double sra;
 string result;
};
int main()
{
 string InFile; 
 Data data[8000];
 int OutCount = 0;
 double OutMax = 0, OutMin = 0;
 double OutTot = 0;//평균을 위한 합
 double OutMaxH=0, OutMinH=0, OutTotH=0;
 double Bspeed=0, Bweight=0;

 fstream InStream;
 cout << endl << "Please enter the name of a text file: ";
 cin >> InFile;
 cout << endl;
 InStream.open(InFile.c_str(), ios::in );
 getline(InStream , InFile);//처음 한줄 그냥 읽기
 InStream >> data[OutCount].name >> data[OutCount].weight>> data[OutCount].wra >> data[OutCount].speed>> data[OutCount].sra >> data[OutCount].result;
 OutMax = OutMin = data[OutCount].weight;//최고와 최저 높이 초기화
 OutMaxH = OutMinH = data[OutCount].speed;
 OutTot += data[OutCount].weight;
 OutTotH += data[OutCount].speed;
 OutCount++;

 while(1)
 {  
  if(OutCount)
  {
   InStream >> data[OutCount].name;
    
   if(InStream.eof()) break;//파일의 끝이면 읽기 끝
   InStream >> data[OutCount].weight>> data[OutCount].wra >> data[OutCount].speed>> data[OutCount].sra >> data[OutCount].result;
   if(OutMax < data[OutCount].weight)//최고 높이 구함
    OutMax = data[OutCount].weight;
   if(OutMin > data[OutCount].weight)//최저 높이 구함
    OutMin = data[OutCount].weight;
   OutTot += data[OutCount].weight;

   OutCount++;   
  }else;
 }
 cout << "최고의 톤수 : " << OutMax << endl;
 cout << "최저의 톤수 : " << OutMin << endl;
 cout << "평균 톤수 : " << OutTot/OutCount << endl;



 return 0;

===============================================================================================


혹시나 해서 데이터는 다음과 같습니다.


선명 총톤수 충돌 상대의 크기 비율 속도(노트) 상대속도 결과
경동프론티어호 1587 0.441713926 8 18 손상
해양호 701 2.263908702 10 18 손상
제이호 149 0.021677852 9 10 긁힘
대용호 3.23 46.13003096 1 10 손상
96신현호 149 0.019932886 8.8 13.8 손상
한진호 2.97 50.16835017 5 13.8 전복
제7해창호 147 0.020816327 8 16 긁힘
영해호 3.06 48.03921569 8 16 파손
제2청해호 1041 54.9932757 11 21 파손
현대중공업1689호 57248 0.018184041 10 21 손상
광양가스호 3901 0.725711356 10.2 22.3 손상
제15주경호 2831 1.377958319 12.1 22.3 파손
제1삼진호 864 0.00849537 10.5 11.5 긁힘
하나호 7.34 117.7111717 1 11.5 파손
제11흥국호 2722 0.002421014 10.5 18.5 긁힘
제102영성호 6.59 413.0500759 8 18.5 파손
승해호 5914 0.686675685 10 16.8 파손
정양호 4061 1.456291554 6.8 16.8 파손
포스브레이버리호 110593 0.508938179 7 9 손상
모닝익스프레스 56285 1.964875189 2 9 파손
청해진고속훼리1호 3872 0.811983471 14 34 긁힘
주연호 3144 1.231552163 20 34 손상
제15흥국호 4481 0.262441419 13 25 손상
1동명호 1176 3.81037415 12 25 손상
시버드호 1470 0.006122449 10.5 19 손상
세일호 9 163.3333333 8.5 19 파손
제15흥국호 4481 0.031019862 12 12 손상

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