1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Korolek [52]
3 years ago
5

Obtain a file name from the user, which will contain data pertaining to a 2D array Create a file for each of the following: aver

ages.txt : contains the overall average of the entire array, then the average of each row reverse.txt : contains the original values but each row is reversed flipped.txt : contains the original values but is flipped top to bottom (first row is now the last row etc.) If the dimensions of array are symmetric (NxN), create a diagonal.txt: contains the array mirrored on the diagonal
Computers and Technology
1 answer:
cricket20 [7]3 years ago
7 0

Answer:

see explaination

Explanation:

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

int main()

{

string filename, file1, file2, file3, file4;

cout << "Enter the filename : ";

getline(cin, filename);

int row, col;

ifstream ifile;

ifile.open(filename.c_str());

if(!ifile)

{

cout << "File does not exist." << endl;

}

else

{

ifile >> row >> col;

float mat[row][col], diag[row][col];

for(int i=0; i<row; i++)

{

for(int j=0; j<col; j++)

ifile >> mat[i][j];

}

cout << "Enter the filename to save averages : ";

getline(cin, file1);

ofstream avgFile(file1.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

float t_avg = 0, avg = 0;

for(int i=0; i<row; i++)

{

avg = 0;

for(int j=0; j<col; j++)

{

avg += mat[i][j];

}

t_avg += avg;

avg = avg/col;

avgFile << std::fixed << std::setprecision(1) << "Row " << i+1 << " average: " << avg << endl;

}

t_avg = t_avg / (row*col);

avgFile << std::fixed << std::setprecision(1) << "Total average: " << t_avg << endl;

cout << "Enter the filename to store reverse matrix : ";

getline(cin, file2);

ofstream revFile(file2.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

for(int i=0; i<row; i++)

{

for(int j=col-1; j>=0; j--)

{

revFile << std::fixed << std::setprecision(1) << mat[i][j] << " ";

}

revFile << endl;

}

cout << "Enter the filename to store flipped matrix : ";

getline(cin, file3);

ofstream flipFile(file3.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

for(int i=row-1; i>=0; i--)

{

for(int j=0; j<col; j++)

{

flipFile << std::fixed << std::setprecision(1) << mat[i][j] << " ";

}

flipFile << endl;

}

cout << "Enter the filename to store diagonal matrix : ";

getline(cin, file4);

ofstream diagFile(file4.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

for(int i=0; i<row; i++)

{

for(int j=0; j<col; j++)

{

diag[j][i] = mat[i][j];

}

}

for(int i=0; i<col; i++)

{

for(int j=0; j<row; j++)

{

diagFile << std::fixed << std::setprecision(1) << diag[i][j] << " ";

}

diagFile << endl;

}

}

return 0;

}

You might be interested in
1. The trucks hauling asphalt have a maximum capacity of 5 US tons (10,000 lbs) 2. The standard road lane is 12 feet wide. 3. As
ivolga24 [154]

Answer:

please write in a better way, and make it easy for us to read.

5 0
4 years ago
g How safe is to have a LinkedIn account where you have published all the important information about yourself
irina [24]

Answer:

LinkedIn is very safe

Explanation:

LinkedIn is very safe, that being said you should never post private information about yourself anywhere that you do not want others to see/know. LinkedIn is a job recruiting and networking site, meaning that all the information that you have or will be publishing there should be related to your career. There is no reason for you to publish private information such as document numbers, social security number, address, bank account info, etc.

5 0
3 years ago
Read 2 more answers
You've formatted the first paragraph of a document. What button can you use to apply the formatting from the first paragraph to
ch4aika [34]
C. Copy which you can access by Ctrl C then paste with Ctrl V
3 0
4 years ago
Read 2 more answers
Computer operates nearly 100% accurately but why is the phrase'garbage in garbage out'(GIGO) associated with their use?Describe
k0ka [10]

Answer:

A program gives inaccurate results due to inaccurate data provided because a computer will always attempt to process data given to it. Said another way, the output quality of a system usually can't be any better than than the quality of inputs.

Explanation:

Techopedia Explains Garbage In, Garbage Out (GIGO)

<h3>Mark me a brainlist</h3>
8 0
3 years ago
In the Create Sparkline dialog, the _______ box refers to the cell range where you want the Sparklines to appear.
kifflom [539]

Considering Microsoft Excel analysis, in the Create Sparkline dialog, the <u>first</u> box refers to the cell range where you want the Sparkline to appear.

When creating Sparkline in Microsoft Excel, the first thing is to create the data range for the sparkline.

Following the creation of the data range, the <u>first box</u> is already filled based on the data range created.

Hence, in this case, it is concluded that the correct answer is "<u>First box."</u>

Learn more about <u>Sparkline</u> here: brainly.com/question/24291191

7 0
2 years ago
Other questions:
  • A simple algorithm for handling requests works like this:________ a) all requests users make are stored. b) The elevator priorit
    15·2 answers
  • An internal _____ refers to a specific representation of an internal model, using the database constructs supported by the chose
    8·1 answer
  • Based on a customer's requirements, the CPQ Admin has created multiple configuration attributes and assigned them to a single fe
    10·1 answer
  • What was the first e-commerce service
    13·1 answer
  • If two classes combine some private data members and provides public member functions to access and manipulate those data member
    14·1 answer
  • Discuss how does a Modulus Operator function
    7·1 answer
  • Which of the following components helps to limit the front-to-back movement of the crankshaft? 
    9·2 answers
  • What will happen if you delete system32?
    7·1 answer
  • HELP PLSSSSS!!! I WILL MARK BRAINLIEST FOR THE FIRST AND CORRECT ANSWER!!!
    14·2 answers
  • The enhanced for loop _____ Group of answer choices reduces the number of iterations necessary to visit all elements of an array
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!