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
What is microsoft certification?
BabaBlast [244]
Microsoft certification is a series of programs that provide certification of competence in Microsoft products.
6 0
3 years ago
Write a Java class called BankAccount (Parts of the code is given below), which has two private fields: name (String) and balanc
NemiM [27]

Answer:

Here is the Bank Account class:

public class Bank Account {   //class definition

   private String name;  //private String type field to hold name

   private double balance;    // private double type field to hold balance

    public Bank Account(String name, double balance) {  // parameter constructor that takes

//this keyword is used to refer to the data members name and balance and to avoid confusion between name, balance private member fields and constructor arguments name, balance

 this.name = name;  

 this.balance = balance;  }    

   public void deposit(double amount) {   //method to deposit amount

               balance = balance + amount;     }    // adds the amount to the account causing the current balance to increase

   public void withdraw(double amount) {  //method to withdraw amount

 balance = balance - amount;   }   //subtracts the amount causing the current balance to decrease

    public String toString() {  // to display the name and current balance

              return name + " , $" + balance; }  } //returns the name and the current balance separated by a comma and dollar

Explanation:

The explanation is provided in the attached document due to some errors in uploading the answer.

3 0
3 years ago
Input 3 positive integers from the terminal, determine if tlrey are valid sides of a triangle. If the sides do form a valid tria
butalik [34]

Answer:

In Python:

side1 = float(input("Side 1: "))

side2 = float(input("Side 2: "))

side3 = float(input("Side 3: "))

if side1>0 and side2>0 and side3>0:

   if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

       if side1 == side2 == side3:

           print("Equilateral Triangle")

       elif side1 == side2 or side1 == side3 or side2 == side3:

           print("Isosceles Triangle")

       else:

           print("Scalene Triangle")

   else:

       print("Invalid Triangle")

else:

   print("Invalid Triangle")

Explanation:

The next three lines get the input of the sides of the triangle

<em>side1 = float(input("Side 1: ")) </em>

<em>side2 = float(input("Side 2: ")) </em>

<em>side3 = float(input("Side 3: ")) </em>

If all sides are positive

if side1>0 and side2>0 and side3>0:

Check if the sides are valid using the following condition

   if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

Check if the triangle is equilateral

<em>        if side1 == side2 == side3: </em>

<em>            print("Equilateral Triangle") </em>

Check if the triangle is isosceles

<em>        elif side1 == side2 or side1 == side3 or side2 == side3: </em>

<em>            print("Isosceles Triangle") </em>

Otherwise, it is scalene

<em>        else: </em>

<em>            print("Scalene Triangle") </em>

Print invalid, if the sides do not make a valid triangle

<em>    else: </em>

<em>        print("Invalid Triangle") </em>

Print invalid, if the any of the sides are negative

<em>else: </em>

<em>    print("Invalid Triangle")</em>

4 0
2 years ago
Levi wants to run 5 commands sequentially, but does not want to create a shell script. He knows that each command is going to ta
sergeinik [125]

Answer:

um

Explanation:

what subject is this again?

3 0
2 years ago
How/when should you use student loans?
mote1985 [20]

Answer:

Things you should use your student loan to pay for: Books and supplies; Room and board (meal plans) Off-campus housing; Transportation (gas, bus pass, etc.) Computers; Any equipment you need for classes; Sheets and towels and Things you should not use your student loan to pay for: Pizza and beer for your roomies; Spring break travel; Taking your family out to dinner; Buying a new Mercedes; An outfit for a friend’s wedding; Cleaning services; Entertainment

Explanation:

3 0
2 years ago
Other questions:
  • Regulatory control limits the activities of an organization in compliance with the organization's policies. True False
    14·2 answers
  • Examine the evolution of the World Wide Web (WWW) in terms of the need for a general-purpose markup language. Provide your persp
    5·1 answer
  • What is cyber stalking and how does it work?
    7·2 answers
  • SUMMING THE TRIPLES OF THE EVEN INTEGERS FROM 2 THROUGH 10) Starting with a list containing 1 through 10, use filter, map and su
    7·1 answer
  • L00000000000000000000000000000000000000000000000000000000l they b00ty tickled
    6·2 answers
  • when files on storage are scattered throughout different disks or different parts of a disk, what is it called
    10·1 answer
  • The welcome screen of the program 123D consists of ___
    15·1 answer
  • Why is the song Twinkle Twinkle Little Star an example of ternary form?
    10·1 answer
  • Recommend how could you integrate positive aspects of digital literacy into your own
    13·1 answer
  • You are the system administrator for Precision Accounting Services, which employs 20 accountants and 25 accounting assistants. T
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!