Skocz do zawartości
_Borys

Program mnozacy matryce

Rekomendowane odpowiedzi

czesc ponizszy program to dopiero kilka funkcji do programu ktory ma utworzyc dwie matryce i pomnozyc pierwsza przez druga. Bylbym bardzo wdzieczny gdyby ktos mogl zucic okiem i napisac czy ponizsze funkcje napisane so poprawnie.

 

#include <iostream>using namespace std;class Matrix{	public:  Matrix ();  bool Input_1st_matrix_dimensions ();  bool Input_values_1st_matrix ( int& Number_of_rows, int &Number_of_columns);  bool Input_values_2nd_matrix ( int& Number_of_columns, int &Number_of_rows);  void Display ();  int Calculate ();      	private:    int Number_of_rows;  int Number_of_columns;  int matrix_1[10] [10];  int matrix_2[10] [10];};int main (){Matrix m;  //if (m.Input_1st_matrix_dimensions () == true )	//	{	//	} 	 }bool Matrix::Input_1st_matrix_dimensions (){	bool rv = true;	int number_of_rows = 0;	int number_of_columns = 0;	cout << " Enter the number of rows for 1st matrix " << endl;  cin  >> number_of_rows;	if (cin.fail () == 0 )   { 	 Number_of_rows = number_of_rows; 	 cout << " Enter the number of columns for 1st matrix " << endl;    cin  >> number_of_columns; 	 if (cin.fail () == 0 )     {   	 Number_of_columns = number_of_columns;    } 	 else     {   	 cerr << " ERROR! could not read the input data " << endl;   	 rv = false;    }  }	else   { 	 cerr << " ERROR! could not read the input data " << endl; 	 rv = false;  }return rv;}	bool Matrix::Input_values_2nd_matrix ( int& Number_of_rows, int &Number_of_columns){	bool rv = true;	const int number_of_rows = Number_of_columns;	const int number_of_columns = number_of_rows;	for ( int i = 0; i < Number_of_rows; i++ )  {	 	 for ( int j = 0; i < number_of_columns; j++ ) 	 {    cout << " Enter the values for the first matrix " << endl;    cin >> matrix_1[i] [j];     	 }  }  return rv;}

aha przy kompilowniu wywala mi ten blad

/tmp/ccGAkwCN.o(.text+0x129): In function `main':: undefined reference to `Matrix::Matrix()'collect2: ld returned 1 exit status

moze wiecie czemu ?? Z gory dziekuje za zainteresownaie pozdrawiam.

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

moze wiecie czemu ?? Z gory dziekuje za zainteresownaie pozdrawiam.

[php:1:6c39076f25]

class Matrix

{

public:

Matrix (); // <--- temu :)

[/php:1:6c39076f25]

 

albo to usun albo dodaj:

 

[php:1:6c39076f25]

Matrix::Matrix()

{

 

}

[/php:1:6c39076f25]

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

Wielkie dzieki pomoglo :!:

Mam jeszcze dwa problemy

1) nie moge napisac funkcji ktora tworzylaby 3a matryce powstala z iloczynu dwuch pierwszych.

2) nie wiem gdzie wszadzic funkcje cin.fail () tak zeby sprawdzala czy wartosci sa zgodne z typem zmiennych int uzywabych w tablicach (macierzach)

 

jak na razie ponizsza czesc programu pozwala na wprowadzenie danych i wyswietlenie tych danych na ekranie

[php:1:e0b9fce109]

#include <iostream>

#include <iomanip>

using namespace std;

 

class Matrix

{

public:

bool Input_matrix_1st_dimensions ();

bool Input_matrix_2nd_dimensions ();

int Get_number_of_rows_m1 ();

int Get_number_of_columns_m1 ();

int Get_number_of_rows_m2 ();

int Get_number_of_columns_m2 ();

bool Input_values_1st_matrix (int &Number_of_rows_m1, int &Number_of_columns_m1);

bool Input_values_2nd_matrix (int &Number_of_rows_m2, int &Number_of_columns_m2);

void Display_1st_martrix ( int &Number_of_rows_m1, int &Number_of_columns_m1 );

void Display_2nd_martrix ( int &Number_of_rows_m2, int &Number_of_columns_m2 );

private:

int Number_of_rows_m1;

int Number_of_columns_m1;

int Number_of_rows_m2;

int Number_of_columns_m2;

int Matrix_1 [22] [22];

int Matrix_2 [22] [22];

int Matrix_3 [22] [22];

};

int main ()

{

Matrix M;

if ( M.Input_matrix_1st_dimensions () == true )

{

if ( M.Input_matrix_2nd_dimensions () == true)

{

int number_of_rows_m1 = 0;

int number_of_columns_m1 = 0;

int number_of_rows_m2 = 0;

int number_of_columns_m2 = 0;

 

number_of_rows_m1 = M.Get_number_of_rows_m1 ();

number_of_columns_m1 = M.Get_number_of_columns_m1 ();

number_of_rows_m2 = M.Get_number_of_rows_m2 ();

number_of_columns_m2 = M.Get_number_of_columns_m2 ();

if ( M.Input_values_1st_matrix ( number_of_rows_m1, number_of_columns_m1) == true )

{

if ( M.Input_values_2nd_matrix (number_of_rows_m2, number_of_columns_m2) == true )

{

M.Display_1st_martrix ( number_of_rows_m1, number_of_columns_m1 );

M.Display_2nd_martrix ( number_of_rows_m2 ,number_of_columns_m2 );

}

}

 

}

}

}

bool Matrix::Input_matrix_1st_dimensions ()

{

bool rv = true;

int number_of_rows = 0;

int number_of_columns = 0;

cout << " Enter the number of rows for the first matrix" << endl;

cin >> number_of_rows;

if (cin.fail () == 0 and number_of_rows >= 1 and number_of_rows <= 22)

{

cout << endl;

cout << " Enter the number of columns for the first matrix " << endl;

cin >> number_of_columns;

if ( cin.fail() ==0 and number_of_columns >= 0 and number_of_columns <= 22)

{

Number_of_rows_m1 = number_of_rows;

Number_of_columns_m1 = number_of_columns;

}

else

{

cerr << " Error!! Could not read the number of rows input " << endl;

cerr << " Remember the number of columns must be an inteager grater or equal 1 and less than 22" << endl;

rv = false;

}

}

else

{

cerr << " Error!! Could not read the number of columns input " << endl;

cerr << " Remember the number of columns must be an inteager grater or equal 1 and less rhan 22 " << endl;

rv = false;

}

return rv;

}

bool Matrix::Input_matrix_2nd_dimensions ()

{

bool rv = true;

int number_of_columns = 0;

cout << " Since it is possible to multiply two matrixes only if the number of columns in the first " << endl;

cout << " matrix is equal to the number of rows in second. you have to type in the number " << endl;

cout << " of columns for the second matrix only " << endl;

cout << " Enter the number of columns for the second matrix " << endl;

cin >> number_of_columns;

if ( cin.fail() ==0 and number_of_columns >= 0 and number_of_columns <= 22)

{

Number_of_rows_m2 = Number_of_columns_m1;

Number_of_columns_m2 = number_of_columns;

}

else

{

cerr << " Error!! Could not read the number of rows input " << endl;

cerr << " Remember the number of columns must be an inteager grater or equal 1 and less than 22" << endl;

rv = false;

}

return rv;

}

 

int Matrix::Get_number_of_rows_m1 ()

{

return Number_of_rows_m1;

}

int Matrix::Get_number_of_columns_m1 ()

{

return Number_of_columns_m1;

}

 

int Matrix::Get_number_of_rows_m2 ()

{

return Number_of_rows_m2;

}

int Matrix::Get_number_of_columns_m2 ()

{

return Number_of_columns_m2;

}

 

bool Matrix::Input_values_1st_matrix (int &Number_of_rows_m1, int &Number_of_columns_m1)

{

bool rv = true;

cout << endl;

cout << endl;

cout << " Enter the values for first Matrix " << endl;

cout << endl;

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

{

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

{

cout << " Enter the value for the cell in row " << i+1 << " column " << j+1 << endl;

cin >> Matrix_1 [j];

}

}

return rv;

}

 

bool Matrix::Input_values_2nd_matrix (int &Number_of_rows_m2, int &Number_of_columns_m2)

{

 

 

bool rv = true;

cout << endl;

cout << endl;

cout << " Enter the values for second Matrix " << endl;

cout << endl;

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

{

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

{

cout << " Enter the value for the cell in row " << i+1 << " column " << j+1 << endl;

cin >> Matrix_2 [j];

}

}

cout << endl;

return rv;

}

void Matrix::Display_1st_martrix ( int &Number_of_rows_m1, int &Number_of_columns_m1 )

{

cout << " 1 st Matrix: " << endl;

cout << endl;

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

{

cout << " | ";

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

{

cout << setw (5) << Matrix_1 [j] << " | ";

}

cout << endl;

}

cout << endl;

}

 

void Matrix::Display_2nd_martrix ( int &Number_of_rows_m2, int &Number_of_columns_m2 )

{

 

cout << " Second Matrix : " << endl;

cout << endl;

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

{

cout << " | ";

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

{

cout << setw (5) << Matrix_2 [j] << " | ";

}

cout << endl;

}

 

cout << endl;

}

[/php:1:e0b9fce109]

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

Dołącz do dyskusji

Możesz dodać zawartość już teraz a zarejestrować się później. Jeśli posiadasz już konto, zaloguj się aby dodać zawartość za jego pomocą.

Gość
Dodaj odpowiedź do tematu...

×   Wklejono zawartość z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Odnośnik został automatycznie osadzony.   Przywróć wyświetlanie jako odnośnik

×   Przywrócono poprzednią zawartość.   Wyczyść edytor

×   Nie możesz bezpośrednio wkleić grafiki. Dodaj lub załącz grafiki z adresu URL.

Ładowanie


×
×
  • Dodaj nową pozycję...