Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What's shown below is what I'm given. I also need this to be written in C++. -------------------------------------------------------------------------- Lab5Functions.cpp = #include Lab5Header.h #include bool openFile(string fileName,

image text in transcribed

What's shown below is what I'm given. I also need this to be written in C++.

--------------------------------------------------------------------------

Lab5Functions.cpp =

#include "Lab5Header.h" #include bool openFile(string fileName, ifstream &inFile) { //get the size of the string representing file name int n = fileName.length(); // declaring character array char char_array[n + 1]; // copying the contents of the // string to char array strcpy(char_array, fileName.c_str()); //check if you can open the file inFile.open(char_array); if (inFile.fail()) return false; else return true; } void displayError(string message){ std::cerr

string readFile(ifstream &inputFile){ string line; getline(inputFile,line); cout

}

Lab5Header.h =

#include #include #include #include using std::cout; using std::string; using std::ifstream;

bool openFile(string fileName, ifstream &inputFile); string readFile(ifstream &inputFile); void extractAndDisplay(string line); void displayError(string message);

main.cpp =

#include "Lab5Header.h"

int main() { ifstream inputFile; string fileName="data.txt"; string line; if (openFile(fileName,inputFile)) { while (!inputFile.eof()){ line =readFile(inputFile); extractAndDisplay(line); } } else displayError("File Open Error"); }

data.txt =

This is Line 1 Followed by Line 2 Next comes Line 3

You need to write a program that reads lines from a file and extracts the tokens in each line. You need to declare and initialize and instringstream object with each line that is read from the file and use the stream extraction operator

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

More Books

Students also viewed these Databases questions

Question

=+ c. a company president deciding whether to open a new factory

Answered: 1 week ago