Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am currently working in Visual Studios 2019 C++. These are the instructions that follow: Create an array variable to store string values. Make this

I am currently working in Visual Studios 2019 C++. These are the instructions that follow:

Create an array variable to store string values. Make this array variable so it can store up to 50 values in it. When declaring that array variable, use a constant int to allocate the size.

Create an input file variable to read in the class name data. Create an output file variable to store output

Use a loop of your choice to read in an unknown number of values from your input file and store that data into the array variable you created in step 1 (unknown number values: this means the number of data items stored in the file size is not static. It can change each time the program executes)

Use getline to read in string values from your input file so you may capture values with spaces in them

After reading in the class names from the input file and storing them into your array variable, output them to both the screen and an output file in the original order and again in reverse order

Use functions to do the following:

Check to see if the file was found

Read in the class names

Output the class names to the screen in the original order

Output the class names in reverse order

Close the files

This is my following code:

#include #include #include

using namespace std;

int main() {

ifstream iFile;

iFile.open("input.txt");

if (!iFile.is_open()) { cout << "Input file not found" << endl; exit(1);

}

string name[50]; int pageNum = 0;

while (!iFile.eof()) { getline(iFile, name[pageNum]);

pageNum++; }

for (int a = 0; a < pageNum; a++) { cout << "Student Name: " << name[a] << endl; }

cout << endl << endl;

for (int a = pageNum-1; a >=0; a--) { cout << "Student Name: " << name[a] << endl; }

iFile.close();

}

I was wondering how to implement these into functions without using global variables.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions

Question

5 Explain Complexity, Autonomy and Novelty.

Answered: 1 week ago

Question

here) and other areas you consider relevant.

Answered: 1 week ago