Question
c++ code A square two-dimensional array is called a Magic Square when the sum of the values in every row, in every column, and in
c++ code
A square two-dimensional array is called a Magic Square when the sum of the values in every row, in every column, and in both diagonals is the same number (the magic number). Write a program that will check an n x n array, and report whether or not it is a magic square. Input: The array values, in row-major order, in an input file.
Processing: A function named checkMagic does the checking. Output: Output, to a file, shows (1) the array itself, as a table of values (2) A statement that it is or is not a Magic Square
If it is a Magic Square, the value of the magic number is shown. Note: The program will handle different values of n by using defined constants for the number of rows and columns. The value of n for a particular run goes in the blank. const int rows = ___; const int columns = ___; int array[rows][columns];
4. (One task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on C-Strings, and the section Arrays of Strings and C-strings, which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10][50]; (allows for 10 courses and up to 49 characters in a course name) each row will be a C-string, and you can use it by writing courseNames[i] as if the array were one-dimensional. Use infile.get(courseNames[i], 50); for reading C-string data row-by-row; the .get function will put in the null character after the input data for you. Note: The .get function reads characters into the array across an input file line, until it encounters a newline character. It does not remove the newline character from the input stream, so in order to read the next line, your program must do that. The textbook suggests declaring char discard; and using infile.get(discard); to read the newline character into the variable discard.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started