U E D R , A S I H C RSS

CPP_Study_2005_1/Basic Bus Simulation/김태훈

No older revisions available

No older revisions available



~cpp 
#include <iostream>
#include <fstream> 
#include <vector>
#include <iomanip> //setprecision 
#include <ios> //precision 

using namespace std;

const BUS_NO = 7;

class cbus
{
public:

	void change_speed(const int n) { speed=n; }
	float buspos(const int min,const int lanelen) { 
		float hour = ((float)min)/60.0;
		float pos;

		pos = hour * speed;
		while(pos>=lanelen) 	pos-=lanelen;
		

		return pos;

	}

private:
	int speed;

};


int main()
{
	ifstream fin("input.txt");
	
	vector<cbus> vbus;
	cbus tmpclass;

	int lanelen,i;

	//버스노선 길이와 버스 속도 구하기
	fin >> lanelen; //버스노선 길이
	for(i=1;i<=BUS_NO;++i) { //버스 속도
		int tmpint;
		fin >> tmpint;
		tmpclass.change_speed(tmpint);
		vbus.push_back(tmpclass);
	}
	
	int min;
	int hour;
	
	cout << "몇시간 후의 버스 위치를 보시겠습니까?" << endl << "시간 : ";
	cin >> hour;
	cout << "분 : ";
	cin >> min;

	for(vector<cbus>::iterator j=vbus.begin();j<vbus.end();++j)
	{
		streamsize pre;
		pre = cout.precision();
		cout << setprecision(3);
		cout << j->buspos(min+hour*60,lanelen) << " km" << endl;
		cout << setprecision(pre);
	}
	
	return 0;
}



Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:43
Processing time 0.0187 sec