~cpp
//BusSimulation.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include "BusSimulation.h"
void BusSimulation::readBusData()
{
m_fin>>m_roundDistance;
double velocity=0;
while(m_fin>>velocity)
{
Bus bus(velocity,m_roundDistance);
m_buses.push_back(bus);
}
}
void BusSimulation::increaseTime(int time)
{
for(vector<Bus>::iterator it=m_buses.begin(); it!=m_buses.end(); ++it)
it->increaseTime(time);
}
ostream& BusSimulation::printResult(ostream &out)
{
for(vector<Bus>::iterator it=m_buses.begin(); it!=m_buses.end(); ++it)
out<< it->getPosition()<<"\n";;
return out;
}
istream& BusSimulation::readTimeInput(istream &in, ostream &out)
{
int minute = 0;
int hour = 0;
out<<"몇시간 후의 버스 위치를 보시겠습니까?"<<"\n"<<"시간 : ";
in>>hour;
out<<"분 : ";
in>>minute;
increaseTime(hour*3600 + minute*60);
return in;
}
~cpp
//Bus.h
#ifndef _BUS_H_
#define _BUS_H_
class Bus {
private:
int m_velocity; // Km/h
double m_position; // Killo meter
int m_roundDistance; // Killo meter
int m_time; // second
public:
Bus(int velocity, int roundDistance) :
m_velocity(velocity), m_roundDistance(roundDistance) {m_time=0; m_position=0;}
void increaseTime(int time) {m_time+=time; m_position+=(time*m_velocity/3600)%m_roundDistance;}
double getPosition(){return m_position;}
};
#endif