Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C++ program as follows: 1. Ask the user for the name of a file, reading the name of the file from standard input.

Create a C++ program as follows:

1. Ask the user for the name of a file, reading the name of the file from standard input. The first two values in the file contains the number of rows and columns in a matrix. The remainder of the file is expected to contain the numbers in a matrix. Simple examples are provided below. For this project, no valid input file shall have more than 20 rows or 20 columns.

2. Read the contents of the file and determine if the matrix of numbers exhibits horizontal additive symmetry. The definition of this term is provided below.

3. If the matrix of numbers in the file exhibits horizontal additive symmetry, output horizontal additive symmetry to standard output. Otherwise, output no horizontal additive symmetry to standard output.

4. Print each row of the matrix, with the values of that row in descending order, one row per line of output. Format the output in an organized table using right-justified columns, as seen below.

5. Ask the user if they wish to process another file. If so, go back to step #1, above. Otherwise, terminate the program. Your program should use defensive programming techniques. This means your program should check input provided by the user for errors and deal with unexpected values without crashing. Ideally, the program should recover from any errors and continue processing.

Sample Run #1

3 2 56 12 98

25 34.5

45

Definition of horizontal additive symmetry:

A matrix of numbers is defined to exhibit horizontal additive symmetry if the sum of the numbers in the rows of the matrix exhibits horizontal symmetry. For this input file, the sums of the rows are:

68

123

79.5

Because this list is not symmetrical, this input file does not exhibit horizontal additive symmetry. (Remember, in a list with an odd number of values, the middle value is considered symmetric with itself.)

Here is the sample output of the program run with this input file:

Enter the filename: notsymmetric2.txt no horizontal additive symmetry 
 56 12 98 25 45 34.5 
Would you like to process another file? Enter Y or y to process another file: n 

Sample Run #2

4 3 1.4 4.6 1

1.6 6.65 1

7.8 1.45 0

7 -2 2

The rows of this matrix yield the following sums:

7 9.25 9.25 7

This list of sums exhibits symmetry thus the matrix exhibits horizontal additive symmetry.

Here is the sample output of the program run with this input file:

Enter the filename: symmetric2.txt horizontal additive symmetry 
 4.6 1.4 1 6.65 1.6 1 7.8 1.45 0 7 2 -2 
Would you like to process another file? Enter Y or y to process another file: n 

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions