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

Need help with number 1, mainly about setting up an array with the numbers from

ID: 3871601 • Letter: N

Question

Need help with number 1, mainly about setting up an array with the numbers from an input file.

In C++ specifically

This is an example of an input file, the first number is the size of the array and the others are the values to be put into the array. I need to set this up so it could fit any type of size a user could choose for the array so not just this example specifically.

D Ctest1.txt - Microsoft Visual Studio Express 2012 for Windows Desktop FILE EDIT VIEW PROJECT DEBUG TEAM TOOLS TEST WINDOW HELP Quick Launch (Ctrl+Q) CI test1.tt Solution Explorer Search Solution Explorer (Ctrl+, 4 Solution "Solution 110 projects) 18 12 Solution..Team Exp.... Class View 100 % Output Show output from: Call Hierarchy Error List Output Find Results Find Symbol Results Ln 1 Col 1 Ch 1 INS 10-27 AM 9/28/2017

Explanation / Answer

Please find below code to create an array dynamically from a file.:

#include <iostream>

#include <fstream>

using namespace std;

Void main(){

int size;

int *array; //creating array as pointer.

int i;

ifstream input (“cl_test.txt”); // Replace file name with desired file name

input >> size; // First value is treated as size of an array

for (i = 0; i < size; i++) {

input >> array[I]; // taking input from file one by one and storing the same in array

}

   input.close();

cout << “Array is:”<<endl;

for (I = 0; I < size; i++) {

cout << array [i] << 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