Computer Science [C++] Write a complete C++ program that will: Read a series of
ID: 3758831 • Letter: C
Question
Computer Science [C++]
Write a complete C++ program that will: Read a series of integer values in from a text file (ask the user for the file name) Present the user with a menu that will allow them to choose to: Output all of the values to the screen Add a new data value Remove a data value Sort the data (small to large) Quit Have the program perform the chosen menu option and then repeat the menu until the user chooses to quit. Perform all operations (input, output, sort, add, remove) on two different data structures: a dynamically allocated array, and a vector. All of the major tasks should be done in functions. Comments: Write a comment before each function definition stating that function?s purpOse. Name blockExplanation / Answer
#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#define ANYSIZE_ARRAY 5
int main()
{
const char* filename = "test.txt";
std::ifstream inputFile(filename);
int numbers[ANYSIZE_ARRAY];
int i, key;
// Make sure the file exists
if(!inputFile)
{
cout << endl << "The File is corrupt or does not exist. " << filename;
return 1;
}
int n = 0;
i = 0;
while(!inputFile.eof())
{
inputFile >> n;
cout << std::setw(10) << n;
numbers[i++] = n;
}
sort(numbers, numbers + ANYSIZE_ARRAY);
//Display sorted array
cout<<endl<<"Sorted Array ";
for(i=0; i<ANYSIZE_ARRAY; i++)
cout<<numbers[i]<<" ";
cout<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.