How would you create this c++ program in visual studios with no global variables
ID: 3857459 • Letter: H
Question
How would you create this c++ program in visual studios with no global variables ? Follow Program Guidelines! Write a C++ program that has the following functions read gets array input of integers from an input file (no more than 25 elements) printArra sort Array-choose one of the three ascending order sorting functions (Selection, Bubble, Insertion) seqorderedSearch -performs a sequential search on a ordered array, for a value v input by the user. Reports either that the value v was not foundOR that value v was found at index Iin the array. addlnorder enters a new user-designated value v into a sorted array so the array remains sorted. NOTE: It is NOT permitted to enter v at the end of the array and then call a sorting function! The value v must be inserted where it belongs (and other values moved to make room for it). deleteValue removes a designated value from the sorted array Note that the add and delete functions change the number ofelements in the array. The function main calls read Array print/Array sort Array print/Array seqOrderedSearch-called in a sentinel controlled loop so the user can search for several values, until the user enters -999 addlnorder printArray delete Value printArrayExplanation / Answer
Here are the functions for you:
#include <iostream>
#include <fstream>
using namespace std;
int readArray(string fileName, int elements[])
{
//Gets array input of integers from an input file
ifstream fin;
int count = 0;
fin.open(fileName);
while(!fin.eof() && count < 25)
fin>>elements[count++];
return count;
}
void printArray(int elements[], int size)
{
//Prints the elements to string.
for(int i = 0; i < size; i++)
cout << elements[i] << " ";
cout << endl;
}
void sortArray(int elements[], int size)
{
//Sort the elements in the array.
for(int i = 0; i < size-1; i++)
for(int j = 0; j < size-i-1; j++)
if(elements[j] > elements[j+1])
{
int temp = elements[j];
elements[j] = elements[j+1];
elements[j+1] = temp;
}
}
int seqOrderedSearch(int elements[], int size, int value)
{
// Performs sequential search on a ordered array, for a value v input by the user.
// Reports either that the value v was not found or that value v was found at index I
// in the array.
for(int i = 0; i < size && value <= elements[i]; i++)
if(elements[i] == value)
return i;
return -1;
}
void addInOrder(int elements[], int size, int value)
{
//Enters a new user-designated value v into a sorted array so the array remains sorted.
int i;
for(i = 0; i < size; i++)
if(elements[i] > value)
break;
for(int j = size-1; j >= i; j--)
elements[j+1] = elements[j];
elements[i] = value;
}
void deleteValue(int elements[], int size, int value)
{
//Removes a designated value from the sorted array.
int i;
for(i = 0; i < size; i++)
if(elements[i] >= value)
break;
if(elements[i] == value)
{
for(int j = i+1; j < size; j++)
elements[j-1] = elements[j];
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.