#include "matrix.h" using namespace std; /** * @brief display menu * */ void displayMenu(void) { string stars(34, '*'); cout 3) { XXXXXXXXXXcerr > size; XXXXXXXXXXif ((size 10)) { XXXXXXXXXXcout > op;...

1 answer below »
More details in the PDF file attached.In this assignment you will learn to use operator overloading both as member and non-member
functions, friend functions, this pointer, copy constructor. This assignment is based on matrixoperations like addition, subtraction, multiplication, increment (pre-, post-), decrement (pre-, post-),assignment operation, copy constructor, transpose matrix.


#include "matrix.h" using namespace std; /** * @brief display menu * */ void displayMenu(void) { string stars(34, '*'); cout < endl;="" cout="">< stars="">< endl;="" cout="">< "|="" menu="" |"="">< endl;="" cout="">< "|0.="" quit="" |"="">< endl;="" cout="">< "|1.="" add(+)="" matrix="" |"="">< endl;="" cout="">< "|2.="" sub(-)="" matrix="" |"="">< endl;="" cout="">< "|3.="" mul(*)="" matrix="" |"="">< endl;="" cout="">< "|4.="" (++)pre-increment="" matrix="" |"="">< endl;="" cout="">< "|5.="" post-increment(++)="" matrix="" |"="">< endl;="" cout="">< "|6.="" (--)pre-decrement="" matrix="" |"="">< endl;="" cout="">< "|7.="" post-decrement(--)="" matrix="" |"="">< endl;="" cout="">< "|8.="" assignment(=")" operation="" |"="">< endl;="" cout="">< "|9.="" copy="" constructor="" |"="">< endl;="" cout="">< "|10.="" transpose(!)="" matrix="" |"="">< endl;="" cout="">< stars="">< endl;="" cout="">< "provide="" the="" input="" "="">< endl;="" cout="">< endl;="" }="" **="" *="" @brief="" mail="" function="" *="" *="" @param="" argc="" *="" @param="" argv="" *="" @return="" int="" */="" int="" main(int="" argc,="" char="" **argv)="" {="" ifstream="" input_file;="" ifstream="" input_file2;="" int="" readmatrix1[rows][cols];="" int="" readmatrix2[rows][cols];="" string="" stars(34,="" '*');="" int="" op="100;" int="" size;="" if="" (argc="=" 1)="" {="" cerr="">< "usage:="" ./main="" matrix_1.txt="" matrix_2.txt="" "="">< endl;="" return="" -1;="" }="" else="" if="" (argc=""> 3) { cerr < "error:="" too="" many="" command="" line="" arguments="" "="">< endl;="" return="" -1;="" }="" else="" if="" (argc="=" 3)="" {="" if="" (strcmp(argv[1],="" "matrix_1.txt"))="" {="" cerr="">< "error:="" invalid="" file="" extension="" "="">< endl;="" return="" -1;="" }="" cout="">< "file1="" name=" << argv[1] << endl; if (strcmp(argv[2], " matrix_2.txt"))="" {="" cerr="">< "error:="" invalid="" file="" extension="" "="">< endl;="" return="" -1;="" }="" cout="">< "file2="" name=" << argv[2] << endl; } if (fileOpen(input_file, argv[1]) == -1) { cerr << " \n="" file="" open:="" input="" file"="">< endl;="" return="" -1;="" }="" if="" (fileopen(input_file2,="" argv[2])="=" -1)="" {="" cerr="">< "\n="" file="" open:="" input="" file"="">< endl;="" return="" -1;="" }="" fileread(input_file,="" readmatrix1);="" input_file.close();="" fileread(input_file2,="" readmatrix2);="" input_file2.close();="" while="" (1)="" {="" cout="">< "enter="" squre="" matrix="" size="" min="" :="" 1="" and="" max:="" 10="" "="">< endl;="" cin="">> size; if ((size <= 0)="" ||="" (size=""> 10)) { cout < "error="" :-="" wrong="" size="" "="">< endl;="" cout="">< "please="" provide="" valid="" input="" "="">< endl;="" }="" else="" {="" cout="">< "matrix="" size="" "="">< size="">< "="" x="" "="">< size="">< endl;="" break;="" }="" }="" cout="">< endl;="" matrix="" mat1(size);="" matrix="" mat2(size);="" matrix="" mat3(size);="" print_matrix(readmatrix1,="" rows,="" cols);="" cout="">< "create="" matrix="" 1="" form="" matrix_1.txt"="">< endl;="" mat1.creatematrix(readmatrix1);="" mat1.display();="" print_matrix(readmatrix2,="" rows,="" cols);="" cout="">< "create="" matrix="" 2="" from="" matrix_2.txt"="">< endl;="" mat2.creatematrix(readmatrix2);="" mat2.display();="" while="" (op="" !="0)" {="" displaymenu();="" cin="">> op; switch (op) { case 0: cout < "quit="" "="">< endl;="" break;="" case="" 1:="" cout="">< stars="">< endl;="" cout="">< "addition="" of="" two="" given="" matrices="" is="" :="" "="">< endl;="" mat1="" +="" mat2;="" cout="">< stars="">< endl;="" break;="" case="" 2:="" cout="">< stars="">< endl;="" cout="">< "subtraction="" of="" two="" given="" matrices="" is="" :="" "="">< endl;="" mat1="" -="" mat2;="" cout="">< stars="">< endl;="" break;="" case="" 3:="" cout="">< stars="">< endl;="" cout="">< "multiplication="" of="" two="" given="" matrices="" is="" :="" "="">< endl;="" mat1="" *mat2;="" cout="">< stars="">< endl;="" break;="" case="" 4:="" cout="">< stars="">< endl;="" cout="">< "(++)pre-increment="" of="" matrix1="" :="" "="">< endl;="" ++mat1;="" cout="">< mat1;="" cout="">< "(++)pre-increment="" of="" matrix2="" :="" "="">< endl;="" ++mat2;="" cout="">< mat2;="" cout="">< stars="">< endl;="" break;="" case="" 5:="" cout="">< stars="">< endl;="" cout="">< "post-increment(++)="" of="" matrix1="" :="" "="">< endl;="" mat1++;="" cout="">< mat1;="" cout="">< "post-increment(++)="" of="" matrix2="" :="" "="">< endl;="" mat2++;="" cout="">< mat2;="" cout="">< stars="">< endl;="" break;="" case="" 6:="" cout="">< stars="">< endl;="" cout="">< "(--)pre-decrement="" of="" matrix1="" :="" "="">< endl;="" --mat1;="" cout="">< mat1;="" cout="">< "(--)dec-increment="" of="" matrix2="" :="" "="">< endl;="" --mat2;="" cout="">< mat2;="" cout="">< stars="">< endl;="" break;="" case="" 7:="" cout="">< stars>
Answered 4 days AfterOct 22, 2021

Answer To: #include "matrix.h" using namespace std; /** * @brief display menu * */ void displayMenu(void) {...

Darshan answered on Oct 26 2021
113 Votes
main.cpp
#include "matrix.h"
using namespace std;
/**
* @brief display menu
*
*/
void displayMenu(void)
{
string stars(34, '*');
cout << endl;
cout << stars << endl;
cout << "| Menu |" << endl;
cout << "|0. quit |" << endl;
cout << "|1. Add(+) matrix |" << endl;
cout << "|2. Sub(-) matrix
|" << endl;
cout << "|3. Mul(*) matrix |" << endl;
cout << "|4. (++)pre-increment matrix |" << endl;
cout << "|5. post-increment(++) matrix |" << endl;
cout << "|6. (--)pre-decrement matrix |" << endl;
cout << "|7. post-decrement(--) matrix |" << endl;
cout << "|8. Assignment(=) operation |" << endl;
cout << "|9. Copy constructor |" << endl;
cout << "|10. transpose(!) matrix |" << endl;
cout << stars << endl;
cout << "Provide the input " << endl;
cout << endl;
}
/**
* @brief mail function
*
* @param argc
* @param argv
* @return int
*/
int main(int argc, char **argv)
{
ifstream input_file;
ifstream input_file2;
int readMatrix1[rows][cols];
int readMatrix2[rows][cols];
string stars(34, '*');
int op = 100;
int size;
if (argc == 1)
{
cerr << "Usage: ./main matrix_1.txt matrix_2.txt " << endl;
return -1;
}
else if (argc > 3)
{
cerr << "Error: Too many command line arguments " << endl;
return -1;
}
else if (argc == 3)
{
if (strcmp(argv[1], "matrix_1.txt"))
{
cerr << "Error: Invalid file extension " << endl;
return -1;
}
cout << "file1 name = " << argv[1] << endl;
if (strcmp(argv[2], "matrix_2.txt"))
{
cerr << "Error: Invalid file extension " << endl;
return -1;
}
cout << "file2 name = " << argv[2] << endl;
}
if (fileOpen(input_file, argv[1]) == -1)
{
cerr << "\n file open: input file" << endl;
return -1;
}
if (fileOpen(input_file2, argv[2]) == -1)
{
cerr << "\n file open: input file" << endl;
return -1;
}
fileRead(input_file, readMatrix1);
input_file.close();
fileRead(input_file2, readMatrix2);
input_file2.close();
while (1)
{
cout << "Enter squre matrix size min : 1 and max: 10 " << endl;
cin >> size;
if ((size <= 0) || (size > 10))
{
cout << "Error :- wrong size " << endl;
cout << "Please provide valid input " << endl;
}
else
{
cout << "Matrix Size " << size << " X " << size << endl;
break;
}
}
cout << endl;
Matrix mat1(size);
Matrix mat2(size);
Matrix mat3(size);
print_matrix(readMatrix1, rows, cols);
cout << "Create Matrix 1 from matrix_1.txt" << endl;
mat1.createMatrix(readMatrix1);
mat1.display();
print_matrix(readMatrix2, rows, cols);
cout << "Create Matrix 2 from matrix_2.txt" << endl;
mat2.createMatrix(readMatrix2);
mat2.display();
while (op != 0)
{
displayMenu();
cin >> op;
switch (op)
{
case 0:
cout << "quit " << endl;
break;
case 1:
cout << stars << endl;
cout << "Addition of two given Matrices is : " << endl;
mat1 + mat2;
cout << stars << endl;
break;
case 2:
cout << stars << endl;
cout << "Subtraction of two given Matrices is : " << endl;
mat1 - mat2;
cout << stars << endl;
break;
case 3:
cout << stars << endl;
cout << "Multiplication of two given Matrices is : " << endl;
mat1 *mat2;
cout << stars << endl;
break;
case 4:
cout << stars << endl;
cout << "(++)pre-increment of...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here