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
The ________ of a cpu dictates how many instructions the cpu can process each second.
makkiz [27]
Gigahertz is the correct answer I believe.
My processor is a i5-6600k with 3.5ghz so assuming GHz is the speed I believe it would be gigahertz
3 0
3 years ago
Most jobs in computer disciplines require which minimum level of education?
nlexa [21]

Answer:

B. Bachelor's Degree

Explanation:

Most computer and information systems managers work full time. Some work more than 40 hours per week. Typically, candidates need a bachelor's degree in computer or information science and related work experience. Many computer and information systems managers also have a graduate degree.

5 0
2 years ago
Read 2 more answers
To distinguish advertising, which typically is conveyed via print, TV, radio, the Internet, etc., from person-to-person forms of
neonofarm [45]

Answer: Mediated

Explanation:

 Mediated communication is the type of communication in which the information are carried out so that it can be used in various types of communication technology.

It is also known as mediated interaction and it can be used as face to face communication.

The mediated communication are typically used to distinguish the various form of communication. The mediated communication are not only computerized but also we can communication by using pen and paper.  

3 0
3 years ago
Read 2 more answers
To ensure proper seating of the valve, the valve seat must be
Marta_Voda [28]
The vaule must be set true not false
5 0
3 years ago
PLEASE HELP
gayaneshka [121]
Girl this happened to me too but all I did was try to look up info on things or examples to know how to do the work and stuff
7 0
3 years ago
Read 2 more answers
Other questions:
  • Assure that major, minor, sub1 and sub2 each contain four digit numbersIf less than four digits are entered in major OR minor OR
    5·1 answer
  • Can anybody answer this for me
    13·2 answers
  • Assuming that each of the resistors in the circuit shown in the figure above has a resistance value of 100 k ohms, what will be
    11·2 answers
  • [20 pts] Write the function rectangle(perimeter, area), which takes two positive integers, perimeter and area. It returns an int
    11·1 answer
  • Why was Apple the best company of 2019??
    15·2 answers
  • List some of the ways that healthcare information technology is making healthcare more of a self-service industry?
    11·1 answer
  • If a clean install is performed on a hard drive with a previous install of windows and the drive is not re-formatted during the
    9·1 answer
  • What variation pairs a new employee with an employee who has been with the company for 20 years?
    6·2 answers
  • 2. Why do old video games have large pixels and images with jagged edges?
    6·1 answer
  • Please select the word from the list that best fits the definition<br><br> Plagiarism
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!