Question
#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[],
#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; } }
can you please make a flowchart and pseudo code
#include
// 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; } }
can you please make a flowchart and pseudo code
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