Question: I need help with the flowchart and Pseudocode. If possible created on word. #include #include #include #include using namespace std; // function declarations void sort(string

I need help with the flowchart and Pseudocode. If possible created on word.

#include

#include

#include

#include

using namespace std;

// function declarations

void sort(string names[], int count);

void display(string names[], int count);

void saveToFile(ofstream& dataOut, string names[], int count);

int main()

{

// declaring variables

string name;

int count = 0;

// defines an input stream for the data file

ifstream dataIn;

// Defines an output stream for the data file

ofstream dataOut;

// Opening the input file

dataIn.open("namesFile.txt");

// checking whether the file name is valid or not

if (dataIn.fail())

{

cout << "** File Not Found **";

return 1;

}

else

{

while (getline(dataIn, name))

{

count++;

}

dataIn.close();

// Creating array dynamically

string* names = new string[count];

// Opening the input file

dataIn.open("namesFile.txt");

for (int i = 0; i < count; i++)

{

getline(dataIn, name);

names[i] = name;

}

dataIn.close();

cout << "Here are the unsorted names:" << endl;

cout << "----------------------------" << endl;

// calling the functions

display(names, count);

sort(names, count);

cout << "Here are the names as sorted:" << endl;

cout << "-----------------------------" << endl;

display(names, count);

// creating and Opening the output file

dataOut.open("sortedNames.txt");

saveToFile(dataOut, names, count);

// Closing the output file.

dataOut.close();

}

return 0;

}

// This function will sort the String array

void sort(string names[], int count)

{

int start;

string temp;

for (int i = count - 1; i > 0; --i)

{

start = 0;

for (int j = 1; j <= i; ++j)

{

if (names[j].compare(names[start]) > 0)

{

start = j;

}

temp = names[start];

names[start] = names[i];

names[i] = temp;

}

}

}

// This function will display the string array

void display(string names[], int count)

{

for (int i = 0; i < count; i++)

{

cout << names[i] << endl;

}

}

// This function will save the sorted array to outfile

void saveToFile(ofstream& dataOut, string names[], int count)

{

dataOut << "Names in Ascending Order:" << endl;

for (int i = 0; i < count; i++)

{

dataOut << names[i] << endl;

}

}

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!