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

I need some help in modifying this code. I want to use the print function and in

ID: 3658880 • Letter: I

Question

I need some help in modifying this code.

I want to use the print function and invoke the print function to print the array

Declare array and load the following numbersfromafile:

4, 33, 25, 68, 50, 30, 63, 47, 54, 86, 82, 71

Note :Be sure to keep count of how many elements are being loaded into

the array

/* This is a program that will output the numbers

entered into the program based on the size of the list.

It's also used to add any number to the list by specifying it's

position as to where the number will be inserted at.

*/


#include <cstdlib>

#include <iostream>

#include <fstream>


using namespace std;


// Function Prototype

int insertAt (int list[], int size, int ele, int index);


int main(int argc, char *argv[])

{ // start main

ifstream infile;

infile.open("Project11.txt");

int list[20];

if(!infile)

{

cout << "unable to open input file. "<< endl;

return 1;

}

infile >> list[20];

while ( !infile.eof())

{

infile >> list [20];

}

infile.close();

int ele, n = 20, index;

cout << "Enter element to be inserted: "; // Enter the number to be inserted into the list

cin >> ele;

cout << "Enter index of element to be inserted at: "; // Enter the position as to where the number will be inserted at

cin >> index;

n = insertAt (list, n, ele, index); // Calling the Function

cout << "Elements are: ";

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

cout << list[i] << endl;

system("PAUSE");

return EXIT_SUCCESS;

} // End Main


// Function definition

int insertAt (int list[], int size, int element, int index)

{ // start insertAt function

int i;

if (index >= size || index < 0)

cout << "Index out of range. Therefore, the element can't be inserted" << endl;

else

{

size++;

for (i = size; i > index; i--)

list[i] = list[i - 1];

list[index] = element;

}

return size;

} // End insertAt function

Explanation / Answer

#include #include #include using namespace std; int insertAt (int list[], int size, int ele, int index); int main(int argc, char *argv[]) { int counter=0; ifstream infile; infile.open("Project11.txt"); int list[20]; if(!infile) { cout > list [counter]; } infile.close(); int ele, n = counter+1, index; cout > ele; cout > index; n = insertAt (list, n, ele, index); cout