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
When a security professional is presented with a contract drawn up by a company's legal department, which allows them to "hack"
kumpel [21]

<em>The answer is : He must consult with a lawyer. </em>

<em>Hacking is considered illegal and in other countries, it is punishable by law. Hacking is gaining unauthorized access to a network. Even when someone is giving you permission to do it, it is still wrong and illegal. Therefore, you must know of your rights and make all the party involved to signed an agreement to save yourself.</em>

8 0
3 years ago
If you are weak or lacking in an area or skillset, what kinds of things can you do to compensate or improve?
Ilya [14]
Put some more of your time to help improve that skill.try to learn to get better.
6 0
3 years ago
Do laws ever change to help enforce cyber hacking crimes
prisoha [69]
No I don’t think so personally
5 0
2 years ago
Read 2 more answers
This speaker could be an instructor, a politician on the television, or even a radio or television commercial. What barriers wer
Shkiper50 [21]

Answer:

Electromagnetic interference and noise from the transmitting or receiving device.

Explanation:

Communication involves four processes, they are; encoding, sending, decoding, and feedback. A message, during this process of communication, can be altered, this is known as noise.

Telecommunication is simply communication between long distances. The effect of noise is more pronounced and can be noticed by listeners. These noises are produced by the transmitter and electromagnetic signals or waves of other transmitting devices.

6 0
3 years ago
Calculate the voltage between two points of the circuit of an iron through which a current of 4 amps passes and presents a resis
Varvara68 [4.7K]

def voltage_calculation (i, r):

return i*r

3 0
2 years ago
Other questions:
  • What is a nonlinear presentation
    9·2 answers
  • What is the body of scientific knowledge based on?
    7·2 answers
  • manufacturers are making an effort to build energy-efficient computers and use recyclable cases and packaging true or false
    10·1 answer
  • The very first thing I should type when creating a formula in excel is:
    15·2 answers
  • Natural selection is a. how systems of rewards increase desired behaviors. b. the idea that the observable environment affects b
    6·1 answer
  • Which technology can be used to protect the privacy rights of individuals and simultaneously allow organizations to analyze data
    13·1 answer
  • After compiling source code, which command still needs to be run in order to copy the newly compiled binaries into a directory l
    5·1 answer
  • ¿Qué aspectos de impacto medioambiental e impacto social tienen relación con la poca disminución de los residuos? Es para hoy.
    13·1 answer
  • Even though jdoe and jrock have the same password (i.e., hacker), their password hashes in the /etc/shadow file are different. W
    15·1 answer
  • If your computer is frozen what is something you would do to troubleshoot the problem ​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!