So i'm done with the homework, except for a piece that will optionally print out to a printer. Now unfortunately, I was late for that lecture. Is the professor literally asking the C++ program to print out, as if from a phyiscal printer? (Printing the output on a piece of paper?) If so, how would I go on to do so? It says exactly "The program will optionally print a printer"
I do have the rest of the homework done, fyi
Code:
#include <iostream>
#include "headertime.h"
#include <fstream>
using namespace std;
int main()
{
char chrAnswer;
MultiplyMatrices clsMatrix;
cout << "The Matrices are setup as follows:" << endl << endl;
cout << " __ __ __ __ " << endl;
cout << "| x1 x2 x3 | | y1 y2 y3 |" << endl;
cout << "| x4 x5 x6 | | y4 y5 y6 |" << endl;
cout << "| x7 x8 x9 | | y7 y8 y9 |" << endl;
cout << " __ __ __ __ " << endl << endl << endl;
do
{
clsMatrix.voidfuncRequestMatrices();
clsMatrix.voidfuncMultiplyMatrices();
clsMatrix.voidfuncOutput();
cout << "If you'd like to use the program again, enter a 'y'";
cin >> chrAnswer;
}
while (chrAnswer == 'y');
system ("PAUSE");
return 0;
}
Code:
#ifndef headertime_H
#define headertime_H
#include <iostream>
using namespace std;
class MultiplyMatrices
{
public:
int intMatrix1[3][3];
int intMatrix2[3][3];
int intMatrix3[3][3];
void voidfuncRequestMatrices();
void voidfuncOutput();
void voidfuncMultiplyMatrices();
};
void MultiplyMatrices::voidfuncRequestMatrices()
{
cout << "Please enter the numbers for x1, x2, x3, and so on, until x9 for the first Matrix: ";
cout << endl;
for (int i = 0; i < 3; i++)
{
for (int y = 0; y < 3; y ++)
{
cin >> intMatrix1[i][y];
}
}
cout << endl;
cout << "Now enter numbers for the second Matrix in the same fashion they were entered for the first Matrix" << endl;
for (int i = 0; i < 3; i++)
{
for (int y = 0; y < 3; y ++)
{
cin >> intMatrix2[i][y];
}
}
cout << endl;
}
void MultiplyMatrices::voidfuncMultiplyMatrices()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
int temp = 0;
for (int k = 0; k < 3; k++)
{
temp += intMatrix1[i][k] * intMatrix2[k][j];
intMatrix3[i][j] = temp;
}
}
}
}
void MultiplyMatrices::voidfuncOutput()
{
cout << "Here is the product of the two matrices:" << endl << endl;
cout << " __ __ " << endl;
cout << "| " << intMatrix3[0][0] << " " << intMatrix3[0][1] << " " << intMatrix3[0][2] << " |" << endl;
cout << "| " << intMatrix3[1][0] << " " << intMatrix3[1][1] << " " << intMatrix3[1][2] << " |" << endl;
cout << "| " << intMatrix3[2][0] << " " << intMatrix3[2][1] << " " << intMatrix3[2][2] << " |" << endl;
cout << " __ __ " << endl << endl << endl;
}
#endif