Question: Detailed Algorithm Define struct Dining containing the following 3 fields and 2 functions: -name of dining location (string) -coordinate x (double) -coordinate y (double) o

Detailed Algorithm

Define struct Dining containing the following 3 fields and 2 functions:

-name of dining location (string)

-coordinate x (double)

-coordinate y (double) o default constructor Dining()

-constructor with parameters - Dining(const string& diningName, double x, double y)

Define readData() function that reads 3 fields from an input file to an instance of Dining

Define printData() function that prints 3 fields of an Dining instance to an output file

Define a vector of Dining elements

Read and process the first part of the input file

-read data to an instance of Dining

-push it to the vector

-repeat until you read line end 0 0

Read and process the second part of the input file

-read location name to search into a string

-find all occurrences of this string in the vector

-for all found locations, print the location name and its coordinates to the output file and to the console (cout)

-repeat until you reach end of the input file

Code below: (replace // ToDo comments with an actual code).

#include

#include

#include

using namespace std;

namespace {

struct Dining

{

string name;

// TODO coordinate_x;

// TODO coordinate_y;

Dining() // TODO

Dining(const string& diningName, double x, double y) // TODO

};

void readData (istream& is, Dining& dining) // TODO

void printData (ostream& os, const Dining& dining) // TODO

}

int main()

{

ifstream fin;

ofstream fout;

string fileNameI,fileNameO;

const string endOfData="end";

cout<<"enter input and output fileNames: ";

cin>>fileNameI>>fileNameO;

fin.open(fileNameI.c_str());

fout.open(fileNameO.c_str());

Dining d;

vector v;

while ( ??? ) {

// TODO read first part, use readData, push to the vector

}

string strSpecificDining;

while ( fin >> strSpecificDining )

{

// TODO process the second part

// TODO find the strSpecificDining locations and print them

}

fin.close();

fout.close();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!