Question
I want the put the dataset.txt in my program so it will read the information because right now it is not. This is the code
I want the put the "dataset.txt" in my program so it will read the information because right now it is not. This is the code from the previous question.
#include
using namespace std;
class Racer{
// private members private: int bib; string name; double distance; string time; double avg; public:
// constructor Racer(){ bib=0; name=""; distance=0.0; time=""; avg=0.0; }
// constructor with arguments Racer(int a,string b,double c,string d){ bib=a; name=b; distance=c; time=d;
string h,m,s;
// calculate average time
h=d.substr(0,1); m=d.substr(2,2); s=d.substr(5,2);
stringstream _s(s); stringstream _h(h); stringstream _m(m);
int __h=0,__m=0,__s=0; _h>>__h; _m>>__m; _s>>__s;
double t=__h+.6*__m+.36*__s;
avg=c/t; }
// setter function void setBib(int a){ bib=a; }
void setName(string a){ name=a; }
void setDistance(double a){ distance=a; }
void setTime(string a){ time=a; }
// getter function int getBib(){ return(bib); }
string getName(){ return(name); }
double getDistance(){ return(distance); }
string getTime(){ return(time); }
double getAvg(){ // calculate time
string h,m,s;
h=time.substr(0,1); m=time.substr(2,2); s=time.substr(5,2);
stringstream _s(s); stringstream _h(h); stringstream _m(m);
int __h=0,__m=0,__s=0; _h>>__h; _m>>__m; _s>>__s;
// time with point notation double t=__h+__m/60.0+__s/3600.0;
avg=distance/t;
return(avg); } };
// display result
void disp(Racer *r,int n){
cout
for(int i=0;i // sorting uding bib void dispBib(Racer *r,int n){ Racer *tmp=new Racer[n]; for(int i=0;i int i,j; Racer k; for(i=0;i while(j>=0 && tmp[j].getBib()>k.getBib()){ tmp[j+1]=tmp[j]; j--; } tmp[j+1]=k; } // display result disp(tmp,n); } // sorting by distance // if equal then use time void dispDisTime(Racer *r,int n){ Racer *tmp=new Racer[n]; for(int i=0;i int i,j; Racer k; // sort by distance then time for(i=0;i bool b=false; if(tmp[j].getDistance() // if display is equal if(tmp[j].getDistance()==k.getDistance()){ if(tmp[j].getTime()>k.getTime()){ b=true; } } } while(j>=0 && b==true){ tmp[j+1]=tmp[j]; j--; } tmp[j+1]=k; } // display disp(tmp,n); } // search for bib number by name int searchBib(Racer *r,int n,string s){ int ret=-1; int c=0; // BST while(c return(ret); } // search by bib value int searchName(Racer *r,int n,int b){ int ret=-1; int c=0; // BST while(c return(ret); } // menu int menu(){ cout int ret=0; cin>>ret; return(ret); } // main function int main(int argc,char** argv){ Racer *racerList=new Racer[100]; int count=0; ifstream in; in.open(argv[1]); if(!in){ cout // read file while(!in.eof()){ in>>a; in>>b1; in>>b2; in>>c; in>>d; racerList[count].setBib(a); racerList[count].setName(b1+" "+b2); racerList[count].setDistance(c); racerList[count].setTime(d); count++; } } // menu anf display action while(true){ int m=menu(); if(m==1){ dispBib(racerList,count); } if(m==2){ dispDisTime(racerList,count); } if(m==3){ cout if(ret!=-1){ cout if(m==4){ cout>b; int ret=searchName(racerList,count,b); if(ret!=-1){ cout return(0); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started