write a program bus ticket. program must have departure time, arrival time, list of the passengers and transit check point.
1
Expert's answer
2012-04-24T07:14:20-0400
Program& bus_ticket. cpp stores and reads data using file bus.txt. Firstly, you have to create database using function& “add” from program. Then you can add data (function “add”) or watch data from file (function “show”). Input data format: Bus number: integer Department time:& hour(integer) :& min(integer) Arrival time: hour(integer) :& min(integer) Check point: string (input 0 as a check point to stop entering check points) Passenger name: string (input 0 as a passenger name to stop entering passenger’s name)
This program was created with Microsoft Visual Studio Pro 2010. #include<iostream> #include<process.h> #include<fstream> #include<string> #include<vector> #include<algorithm> using namespace std;
struct time { int hour; int min; }; ostream &operator<<(ostream &os, time &t){ os<<t.hour<<':'<<t.min; return os; } istream &operator>>(istream &is, time &t){ char c1; int h,m; is>>h>>c1>>m; if(!is) return is; if(c1!=':') {is.clear(ios_base::failbit);return is;} t.hour=h; t.min=m; return is;}
void add(){ int number; time dep_time; time arrival_time; string name,check; ofstream outf; outf.open("bus.txt",ios::app); if(!outf) {cout<<"unable to open \n"; return;} cout<<"input bus number: "; cin>>number; outf<<" "<<number<<" "; cout<<"\n input department time: ";cin>>dep_time; outf<<dep_time<<" "; cout<<"\n input arrival time: "; cin>>arrival_time; outf<<arrival_time<<" "; cout<<"\n input check points: \n"; do {cout<<"\n enter check point name:\t"; cin>>check; outf<<check<<" ";}while(check!="0"); cout<<"\n input passengers name: \n"; do {cout<<"\n enter name of passenger \t"; cin>>name; if(name!="0"){outf<<name<<" ";}else{outf<<name;}}while(name!="0"); if(!outf){cout<<"\n write is impossible \n";return;} }
void show(){ int number; time dep_time; time arrival_time; string name,check; ifstream of; of.open("bus.txt"); if(!of){cout<<"\n unable to open "; return;} while(true){ if(of.eof()){return;}
cout<<"\n bus number is: \t";of>>number;cout<<number; & cout<<"\n department time is: \t";of>>dep_time;cout<<dep_time; & cout<<"\n arrival time is: \t";of>>arrival_time;cout<<arrival_time; cout<<"\n check points are:\t"; & do {
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment