Question

PLEASE help! There should be three files a (.h file), a (main.cpp file), and a (test.cpp...

PLEASE help! There should be three files a (.h file), a (main.cpp file), and a (test.cpp file) please do not miss any of the questions!! I'm going to try this myself too

thanks for any and all help

Write a class called array2x2 which includes the following members: Private members: o A two dimensional array to store the data: double data[2][2];

Public members: o A default constructor which initializes data to having entries all 0. [i.e., data[i][j]=0.0 for all i and j: data=0 0 0 0]

o A function that displays the data in the following format: If data=23 −4 6 7, then display {{23, -4}; {6,7}}

o A function that given a 2x2 array A, sets the entries of data to that of A.

o A function that given a double x and indexes i and j, sets the element i,j of data to x ( data[i][j]=x). Make sure that i, j are within index bounds. [E.g. setElement(1,1, -10) will result in , data=0 0 0 −10. setElement(1,2,45) will do nothing.]

o A function that given the indexes i and j returns the value data[i] [j]. If the indexes are out of bounds, reduce/increase them to the closest legal index bound. [for example, if i=-2 and j=2 convert them to i=0 and j=1 and return data[0][1].]

o A function that returns the maximum value of the data.

o A function that searches for a value in data. If value is found, return 1 (true) and the indexes of the position found. If it is not found, return 0 (false) and -1, -1 for the indexes. (Hint: pass indexes as reference parameters)

Write a class called matrix2x2 derived from array2x2 via public inheritance. In addition, this news class should have the following member functions:

Public members: o A constructor with one default parameter set to 0. If the value of the parameter is b, then data should be initialized to: data= 0 0 [i.e., data[0][0]=b, data[1][1]=b, the other entries 0].

o A function display (overwriting the display function of array2x2), that displays the data as

o A function that returns the determinant.

, then the determinant is defined as the number (a*b-

[ If data=

c*d).]

o A function that multiplies the matrix by a number x.

, then the function returns a matrix2x2 with data= ∗

[If data=

∗ ∗ ∗ .]

o A function that sums two matrices. I.e. matrix2x2 sumMatrix(matrix2x2 M) [If data= and M.data=

+ℎ.]

+ + +

In the main function (outside the class), create a function that subtracts two matrices. Hint: use the last two public functions implemented inside the class For all the above write a main program that tests all the functions. When a function makes changes to the array/matrix, display before and after effects by printing the array/matrix using display function implemented.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: main.cpp: #include <iostream> #include matrix . h using namespace std; int main (void) matrix2x2 matrix (35.0); couTest.cpp: #include array2x2. h array2x2: :array2x2(void) for (int i0;i<2;i++) for (int j 0;]<2 ; j ++) = data[1] [j] 0; = /// Set element individually void array2x2:13etDataElement (int a, int b, double i) data[a] [b] 1; = // Get the data value indreturn greater: // Search for a value int array2x2::searchDataElement (double value) int found0: for (int i 0;i<2:i+ +) for (array2XZ.n: #include <iostream> using namespace std; class array2X2 rivate: double data[2] [2]; ublic: // Constructor array2xmatrix.h: #include <iostream> #include array2 x2.h class matrix2x2: public array2x2 ublic: double matArray [2] [2] matrix2xvoid muliplicatMatrix(int x) for ant i 0i<2 i++) for (int j 0 j<2j++) double dal array2x2: :getDataElement (i, / Missing commOutput CAUsers 1203483 Documents Visual Studio 20151Projects Project831DebuglProject83.exe Initial Matrix: Deterninant: 1225copyable code:

main.cpp:

#include <iostream>

#include "matrix.h"

using namespace std;

int main(void)

{

     matrix2x2 matrix(35.0);

     cout << endl << " Initial Matrix: " << endl;

     matrix.display();

cout << endl << " Determinant: " << matrix.datadeterminent() << endl;

     matrix.display();

     cout << endl << " After Multiplication: " << endl;

     matrix.muliplicatMatrix(3);

     matrix.display();

     cout << endl << " After Summation: " << endl;

     matrix2x2 mat2(20.9);

     matrix.sumofMatrix(mat2);

     matrix.display();

     system("pause");

     return 0;

}

Test.cpp:

#include"array2x2.h"

array2x2::array2x2(void)

{

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

     {

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

          {

              data[i][j] = 0;

          }

     }

}

//Display Method

void array2x2::display()

{

cout << endl << "{{" << data[0][0] << "," << data[0][1] << "};{" << data[1][0] << "," << data[1][1] << "}}" << endl;

}

// Set Values

void array2x2::setDataEntries(double arr[2][2])

{

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

     {

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

          {

              data[i][j] = arr[i][j];

          }

     }

}

// Set element individually

void array2x2::setDataElement(int a, int b, double i)

{

     if (a<2 && b<2)

     {

          data[a][b] = i;

     }

}

// Get the data value individually

double array2x2::getDataElement(int a, int b)

{

     double value;

         

     if (((a<2) && (a >= 0)) && ((b<2) && (b >= 0)))

     {

          value = data[a][b];

     }

     else

          value = -1;

          return value;

}

// Get the max value

double array2x2::getmaximum()

{

     double greater = data[0][0];

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

     {

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

          {

              if (data[i][j]>greater)

              {

                   greater = data[i][j];

              }

          }

     }

     return greater;

}

// Search for a value

int array2x2::searchDataElement(double value)

{

     int found = 0;

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

     {

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

          {

              if (data[i][j] == value)

              {

                   found = 1;

cout << "The index is: " << i << ", " << j << endl;

                   break;

              }

          }

     }

     if (found == 0)

     {

          cout << "The index is: -1, -1" << endl;

     }

     return found;

}

array2x2.h:

#include <iostream>

using namespace std;

class array2x2

{

private:

     double data[2][2];

public:

     // Constructor

     array2x2(void);

     //Display Method

     void display();

     // Set Values

     void setDataEntries(double array[2][2]);

     // Set element individually

     void setDataElement(int a, int b, double i);

             

     // Get the data value individually

     double getDataElement(int a, int b);

         

     // Get the max value

     double getmaximum();

     // Search for a value

     int searchDataElement(double value);

};

matrix.h:

#include<iostream>

#include "array2x2.h"

class matrix2x2 : public array2x2

{

public:

    

     double matArray[2][2];

    

     matrix2x2(double b = 0)

     {

          array2x2::setDataElement(0, 0, b);

          array2x2::setDataElement (1, 1, b);

     }

     void display()

     {

         

          array2x2::display();

     }

     double datadeterminent()

     {

          /* Determinant of a matrix is ad - bc */

double deter = (array2x2::getDataElement(0, 0) * array2x2::getDataElement(1, 1)) - (array2x2::getDataElement(0, 1) * array2x2::getDataElement(1, 0));

          return deter;

     }

     void muliplicatMatrix(int x)

     {

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

          {

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

              {

double dval = array2x2::getDataElement(i, j);

                   /* Missing comma after j */

                   array2x2::setDataElement(i, j, dval*x);

              }

          }

     }

     void sumofMatrix(matrix2x2 M)

     {

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

          {

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

              {

double dval = array2x2::getDataElement(i, j);

array2x2::setDataElement(i, j, (dval + M.getDataElement(i, j)));

              }

          }

     }

};

Add a comment
Know the answer?
Add Answer to:
PLEASE help! There should be three files a (.h file), a (main.cpp file), and a (test.cpp...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file...

    So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file created and open in Dev C++. However, every time I try to compile I get a series of undefined reference to errors. Any advice is much appreciated!!! (45 pts) Work Programming Exercise 9.2 (class Fan) in the textbook on page 367. Additional specifications: • Use separate header and implementation files. • The main program (not the functions) should display the values of Speed, On,...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • You are to write three functions for this lab: mean, remove, display. Download the main.cpp file...

    You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...

  • C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that...

    C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the...

    Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...

  • I only need the "functions" NOT the header file nor the main implementation file JUST the impleme...

    I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT