Hello, I need this program in C++ . In this program you will be reading in a 6 x
ID: 638683 • Letter: H
Question
Hello, I need this program in C++. In this program you will be reading in a 6 x 6 array of characters. You need to use a 2 dimension array of chars to do this. The constants defining the maximum number of rows and columns can be global variables, but nothing else can be a global variable.
Your program must have three or more functions. You will have the main function, one or more
functions to read in the file, and one or more functions to display the output of the character array.
You will be reading these characters from an input file. The characters need to be read in a character at
a time and can include a space character. You will not be able to use the >> stream operator for this
since the >> operator ignores spaces. You can use the get() function discussed in Chapter 3 of your book
(see section 3.8). The example in the book uses cin.get(), but you can replace cin with your input file
(ifstream) object. Your get() function will also read in newline ( ) characters. You need to ignore the
newline characters.
The input file will contain records as follows (each line below is assumed to end with a newline):
2ndRow
[Row3]
Now 4
Fifth1
6Final
For each row in the 6 x 6 array of characters you will output the row (from index 0 to index == 5) AND
the same row from index 5 to index 0. So the first row (above) will be output as:
>1woR<
The second row will be:
2ndRowwoRnd2
All 6 rows will be:
>1woR<
2ndRowwoRdn2
[Row3]]3woR[
Now 44 woN
Additional requirements:
Your program must be able to handle any number of input files. You will read in the name of the input
file from the application user. If the file can be opened you will format the output as discussed above. If
the file is invalid you need to output an error message saying that the file could not be opened.
After you have displayed the output, or an error message, your program should ask the user if they have
any more files they want to process. If they do, you need to read in the next file name and process it, as
you did for the first file. You will continue to process files until the user tells you they have no more files.
Program output:
Here is some sample output. You output of the text file must match what is shown here for the same
input. The other messages can be different, but you must have all of the needed processing:
Enter the name of an input file: badfile.txt
The input file name "badfile.txt" could not be found
Do you want to try again with a new file?
Enter n or N to quit, any other character to continue): y
Enter the name of an input file: input1.txt
------------------------------------------------------------------------------------------------------------
For the input file processing you need to read in a character at a time. Due to differences in files used by different operating systems a line could end with a ' ', or a ' ', or both a ' ' and a ' '. Your read logic needs to ignore both and characters. These will only should up at then end of a line (row) of input.
You need to have at least 3 functions in your program (including main as one of the three).
Sample Input:
Sample output:
The output for this will be as follows:
(basically there are four quadrants and the top left half is what is given, then it has to print a reflection to the right of it and reflect to the bottom two quadrants)
xx
***x**x***
* x x *
*x ## x*
x # # x
x* # # *x
x* # # *x
x # # x
*x ## x*
* x x *
***x**x***
xx
Here is my program so far:
// Assignment 1 for CS 1337.006
// Programmer: Caitlin Arnspiger
// Printing with 2D arrays
#include <iostream>
#include <string>
#include<fstream>
using namespace std;
const int ROW = 6, COLUMN = 6;
//function prototypes
void readIn(string);
char output(char);
int main()
{
string fileName; //holds name of input file entered by user
//prompts user to enter name of input file
cout << "Enter the name of an input file: ";
cin >> fileName;
readIn(fileName); //reads in characters from the file
system("pause");
return 0;
}
void readIn(string fileName)
{
ifstream infile; //allows for manipulation of input file
char choice; //holds user choice in event of an error, to retry or quit(n or N)
//opens the input file entered in by user
infile.open(fileName);
while (!infile) //if file does not open, shows error message
{
//error message
cout << "The input file name " << fileName << " could not be found. "
<< "Do you want to try again with a new file? "
<< "Enter n or N to quit, any other character to continue: ";
cin >> choice;
if (choice == 'n' || choice == 'N') //if choice is n or N, exits program
{
exit(1);
}
else //any choice besides n or N, tries to open file with another file name entered by user
{
cout << "Enter the name of an input file: ";
cin >> fileName;
infile.open(fileName);
}
}
//input file reads into array below
char originalArray[ROW][COLUMN]; //holds characters entered in from a text file
//gets information from a file and stores it in the 2D array
for (int x = 0; x < ROW; x++) //goes to the next row, when all columns in the previous row have been stored
{
for (int y = 0; y < COLUMN; y++) //goes through the row, array stores character from each column in the same row
{
infile.get(originalArray[x][y]); //array holds the characters from the file
}
infile.ignore(); //ignores the at the end of each row
}
//closes input file
infile.close();
//prints the information from the 2D array
for (int i = 0; i < ROW; i++){//goes to the next row
for (int j = 0; j < COLUMN; j++){//goes to the next column in each row until row is finished
cout << originalArray[i][j]; //prints array to screen
}
//prints to the right of the first array
for (int i = 6; i > 0; i--){
for (int j = 6; j > 0; j--)
{
cout << originalArray[i][j];
}
}
cout << endl; //prints each row on a different line
}
}
/*
char output(char originalArray[ROW][COLUMN])
{
}
*/
Explanation / Answer
check
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.