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
To be eligible for the leadership training program offered by the office, a student must have at least 2 years of post-secondary
erica [24]

Answer:

The formula for the given problem is:

=IF(OR(D2>=2,G2>"Yes"), "Yes", "No")

Explanation:

Please see attachment for step by step guide

7 0
4 years ago
What is the output of this program ? Assume the user enters 3,6 and 11​
Nostrana [21]

Answer:

C++

Explanation:

C++ Standards

C++ is standardized as ISO/IEC 14882. Currently, there are two versions:

C++98 (ISO/IEC 14882:1998): First standard version of C++.

C++03 (ISO/IEC 14882:2003): minor "bug-fix" to C++98 with no change to the language. Commonly refer to as C++98/C++03 or First C++ standard.

C++11 (ISO/IEC 14882:2011): Second standard version of C++. Informally called C++0x, as it was expected to finalize in 200x but was not released until 2011. It adds some new features to the language; more significantly, it greatly extends the C++ standard library and standard template library (STL).

C++14: Infomally called C++1y, is a small extension to C++11, with bug fixes and small improvement.

C++17: informally called C++1z.

C++2a: the next planned standard in 2020.

C++ Features

C++ is C. C++ supports (almost) all the features of C. Like C, C++ allows programmers to manage the memory directly, so as to develop efficient programs.

C++ is OO. C++ enhances the procedural-oriented C language with the object-oriented extension. The OO extension facilitates design, reuse and maintenance for complex software.

Template C++. C++ introduces generic programming, via the so-called template. You can apply the same algorithm to different data types.

STL. C++ provides a huge set of reusable standard libraries, in particular, the Standard Template Library (STL).

C++ Strength and Pitfall

C++ is a powerful language for high-performance applications, including writing operating systems and their subsystems, games and animation. C++ is also a complex and difficult programming language, which is really not meant for dummies. For example, to effectively use the C++ Standard Template Library (STL), you need to understand these difficult concepts: pointers, references, operator overloading and template, on top of the object-oriented programming concepts such as classes and objects, inheritance and polymorphism; and the traditional constructs such as decision and loop. C++ is performance centric. The C++ compiler does not issue warning/error message for many obvious programming mistakes, undefined and unspecified behaviors, such as array index out of range, using an uninitialized variable, etc, due to the focus on performance and efficiency rather than the ease of use - it assumes that those who choose to program in C++ are not dummies.

6 0
3 years ago
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
lyudmila [28]

I am not able to open the pdf kindly send the jpg form.

4 0
3 years ago
Read 2 more answers
What are three steps to use to research relevant information on the internet? (Site 1)
Mademuasel [1]

Answer:

Step 1: Questioning --- Before going on the Internet, students should structure their questions. Step 2: Planning --- Students should develop a search strategy with a list of sites to investigate. Step 3: Gathering --- Students use the Web to collect and gather information.

Explanation:

there i did it for you can I get brainlyest

5 0
4 years ago
Read 2 more answers
Which of the following menu commands would you select to make a copy of an open file and rename it
Alona [7]
File -> Save As
Or Shortcut Key CTRL+SHIFT+S
5 0
3 years ago
Other questions:
  • What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? Group of answer choices
    10·1 answer
  • What is the most widely used operating system for mobile devices?
    7·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • What is the purpose of the domain name? The domain name is an example of a service provider. The domain name .gov.nz is an examp
    15·2 answers
  • Jenny, a programmer, uses Microsoft Excel 2016 to generate data required for the programs she develops. She uses various functio
    10·1 answer
  • What type of filtering software divides email messages that have been received into two piles, spam and non-spam and then analyz
    13·1 answer
  • 1. Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the
    8·1 answer
  • Hey im b---o---r---e---d dont report cuz if u do ur l a m e :)
    14·1 answer
  • Write a python program to change variable value of your previous result percentage to your current percentage of mid-term
    13·1 answer
  • A ____________________ machine is used to gather or arrange in their proper sequence.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!