Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code typed : void CarSimulator::ReadCommandsFromFile(){ ifstream myfile (_inputFileName); if (myfile.is_open()) { string myLine; double vel, angle, timeStamp; Command c; while ( getline (myfile,myLine) )

image text in transcribed

The code typed :

void CarSimulator::ReadCommandsFromFile(){

ifstream myfile (_inputFileName);

if (myfile.is_open())

{

string myLine;

double vel, angle, timeStamp;

Command c;

while ( getline (myfile,myLine) )

{

sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp);

c.SetVelocity(vel);

c.SetTireAngleRate(angle);

c.SetTimeStamp(timeStamp);

if(c.IsValid()){

_commands.push_back(c);

}

else{

// clear command vector

return ;

}

}

myfile.close();

}

}

so im running it on a bash terminal and it appears to be not reading my txt files .

as it can be seen on this pic below:

image text in transcribed

and just one last thing how could i convert this line of code to C ++ :

sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp);

ceause on my assignment everything should be a C ++ syntax.

this is the code i got sofar so please help me getting the files being read correct my code and change the sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp); to a C ++

23 24 25 Populates object_commands data member frominputFileName 26 27 Orequirement if the Command IsValid) returns false for any Command, the input file is invalidated. An output file still needs to be generated 28 Orequirement if a line is not formatted correctly, the file is not invalidated. It is just discarded 29 Orequirement close the file at the end of the function 30 31 void CarSimulator: : ReadCommands FromFile) ifstream myfile (inputFileName); if (myfile.is open()) 35 string myLine; double vel, angle, timeStamp; Command ci while getline (myfile, myLine)) 37 38 sscanf(rmy Line . c-str(), "%1f %1f %1f", &vel, &angle, &timeStamp); 40 41 c.SetVelocity(vel); c.SetTireAngleRate (angle); c.SetTimeStamp (timeStamp); if(c.IsValid)) commands.push_back(c); 47 elset // clear command vector 51 52 return myfile.close) 56 57 58 23 24 25 Populates object_commands data member frominputFileName 26 27 Orequirement if the Command IsValid) returns false for any Command, the input file is invalidated. An output file still needs to be generated 28 Orequirement if a line is not formatted correctly, the file is not invalidated. It is just discarded 29 Orequirement close the file at the end of the function 30 31 void CarSimulator: : ReadCommands FromFile) ifstream myfile (inputFileName); if (myfile.is open()) 35 string myLine; double vel, angle, timeStamp; Command ci while getline (myfile, myLine)) 37 38 sscanf(rmy Line . c-str(), "%1f %1f %1f", &vel, &angle, &timeStamp); 40 41 c.SetVelocity(vel); c.SetTireAngleRate (angle); c.SetTimeStamp (timeStamp); if(c.IsValid)) commands.push_back(c); 47 elset // clear command vector 51 52 return myfile.close) 56 57 58

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

Students also viewed these Databases questions