matrix multiplication with menu

/***** The prompt i have is : use a class with 3 member functions named InputMatrix, Calculate, and OutMatrix. The program will prompt the user to (e)enter the matrix data, (c) to calculate the matrix multiplication, (d) to display the input and output matrices, and (q) to quit. no exit() or abort() commands are to be used. no global variables allowed.

I have created the Menu for users to enter either e, c, d or q...I have also created the correct functions for input, output and calculation. i am having trouble with how to put all the functions in the menu so the program works like it says in the prompt. thank you for the help.

//header file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef matrix_H
#define matrix_H


#include <iostream>
using namespace std;
const short SIZE = 3;
void menu( char & choice ); 
void CalculateMatrix(double [SIZE][SIZE] , double [SIZE][SIZE], double [SIZE][SIZE]);
void InputMatrix(double localmatrix [SIZE][SIZE]);
void OutMatrix(double [SIZE][SIZE]);
void initializematrix(double [SIZE][SIZE] );

void initializematrix(double localmatrix[SIZE][SIZE] )
{
	int p,q;
	for(p=0; p<SIZE; p++)
	{
		for (q=0; q<SIZE; q++)
		{
			localmatrix [p][q] = 0;
		}
	}
}

#endif 


//cpp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

# include "matrix.h"

	int main ()
	{
	//	int choice;  changed it to char choice
	//	char choice;
		char choice;

		for (;;)
		{
			menu(choice);
			if(choice == 'e' || choice == 'E')
			{
				double Matrix1 [SIZE][SIZE] , Matrix2 [SIZE][SIZE] , Matrix3 [SIZE][SIZE] ;
				cout << " \nplese enter first 3x3 matrix " <<endl;				// ask user to enter first matrix
			    InputMatrix(Matrix1);											// get the input from user for first matrix
			    cout << " \nYou have entered the following Matrix " << endl;
			    OutMatrix(Matrix1);												// output the matrix they have entered

				cout << " \nplese enter second 3x3 matrix " <<endl;				// ask user to enter second matrix
				InputMatrix(Matrix2);											// get the input from user for second matrix
				cout << "\nYou have entered the following Matrix2 " << endl;
			    OutMatrix(Matrix2);
				
			}
			else if (choice == 'c' || choice == 'C')
			{
				CalculateMatrix();
				
			}
			else if (choice == 'd' || choice == 'D')
			{
				OutMatrix();
				
			}
			else if (choice == 'q' || choice == 'Q')
			{
				cout << "Thank you for using the program." << end;
			break;
			}
			else
			{
				cout << "Please enter a valid character: " << endl;
			}
		}
	
	}
	void menu( char & choice ) // menu for the user to choose m, e or q
	{
		cout << endl;
		cout << "        Welcmoe to the matrix conversion program." << endl;
		cout << " Press E to enter the matrix data. " << endl;
		cout << " Press C to calculate the matrix multiplication. " << endl;
		cout << " Press D to display the input and output matrices. " << endl;
		cout << " Press Q to quit the program. "
		cin.get(choice); 
		cin.ignore();
	}

void InputMatrix(double localmatrix [SIZE][SIZE])
{
	int p,q;
	for(p=0; p<SIZE; p++)
	{
		for (q=0; q<SIZE; q++)
		{
		cin >> localmatrix [p][q];
		}
	}
}

void OutMatrix(double localmatrix [SIZE][SIZE])
{
	int p,q;
	for( p=0; p<SIZE; p++)
	{
		cout << endl;
		for ( q=0; q<SIZE; q++)
		{
			cout << localmatrix [p][q] << "\t";
		}
	}
}

void CalculateMatrix(double multmat1[SIZE][SIZE] , double multmat2[SIZE][SIZE] , double multmat3 [SIZE][SIZE])
{
	int p,q,r;
	for(p=0; p<SIZE; p++)
	{
		for (q=0; q<SIZE; q++)
		{
			for (r=0; r<SIZE; r++)
			{
				multmat3 [p][q] =+ multmat3 [p][q] + (multmat1 [p][r] * multmat2 [r][q]);
 
		    }
		}
	}
 
}



Topic archived. No new replies allowed.