Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 block

Explanation / 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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote