الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ايجاد الاخطاء في كلاس يضم العمليات على ال

بدأه DONNA في 3 مايو 2012 · 7 رد · 403 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

انا بدأت في عمل مشروع والمشروع عباره عن كلاس يضم عدد من العمليات ع المصفوفات والـ main فقط مناداة لما في داخل الكلاس

لكن الاخطاء تلازمني حاولت فيها كثيرا لكن لم اجد حل

فـ ياليت تساعدوني في ايجاد الاخطاء وتنبيهي عليها

وهذه هي تجربتي

#include <iostream>
#include<vector>
 using namespace std;
  class myarray{

  public:
	  vector<int> diffrentsize;{
	int x;
	int y;
	int z;
	int w;
	cout<<"enter 4 size of array"<<endl;
  cin>>x;
  cin>>y;
  cin>>z;
  cin>>w;
  int *p[4];
  p[0]=new int[x];
  p[1]=new int[y];
  p[2]=new int[z];
  p[3]=new int[w];
	  }
         vector<void>check {
          if(p2.length()>x){
          cout<<"the length of array is bigger than size"<<endl;
          }
		  else 
		  {cout<<"the length of array is fit the size"<<endl;}
		  }
          vector<void> length {

 int y=0;
for(int i=0;i<x;i++){
       cin>>p;}
while(p2[0]!='\0')
{y+=1;
	p2++;}
cout<<y;
  }
  vector<void> det{
  cout<<endl<<"TO FIND DETERMINANT"<<endl;
	int n = 0,val;
	cout<<"enter no. of columns/rows of square matrix"<<endl;
	cin>>n;
	int **p;
	p = new int*[n]; //make an array of ints, p points to them
	for (int i = 0; i< n; i++) 
	{
		p = new int[n]; //each pointer now points to 'n' amount of ints

	}
	int a  = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			p[j] = a++; //assign some values
		}
	}
	cout<<"enter the values of matrix row-wise"<<endl;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin>>p[j];
			if (n==1)
				val=p[j];
		}
	}
        //using the formulae
	if (n==2)
	{val=p[0][0]*p[1][1]-p[0][1]*p[1][0];}
	if (n==3)
		{val=(p[0][0]*((p[1][1]*p[2][2])-(p[1][2]*p[2][1])))-
		    (p[0][1]*((p[1][0]*p[2][2])-(p[1][2]*p[2][0])))+
			(p[0][2]*((p[1][0]*p[2][1])-(p[1][1]*p[2][0])));}
        for (int i = 0; i < m; i++)
	{
		delete((int*)p);//free up the array of pointers, must delete each one otherwise memory will leak

	}
	delete [] p;
	cout<<"determinant value is:";
	cout<<val<<endl;

}
vector<void> transpose{
	int n = 0,m=0;
	cout<<"TO FIND TRANSPOSE"<<endl;
	cout<<"enter no. of rows and columns of matrix"<<endl;
	cin>>m>>n;
	int **p;
	p = new int*[m];
	for (int i = 0; i< m; i++)
	{
		p = new int[n];
	}
	int a  = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			p[j] = a++;
		}
	}
	cout<<"enter the numbers of matrix row-wise"<<endl;
	for (int i = 0; i < m; i++) //input values
	{
		for (int j = 0; j < n; j++)
		{
			cin>>p[j];
		}
	}
	cout<<"matrix you have entered is"<<endl;
	for (int i = 0; i < m; i++) //output matrix entered
	{
		for (int j = 0; j < n; j++)
		{
			cout << p[j] << "\t";
		}
		cout << "\n";
	}
	int **q;
	q = new int*[m];
	cout<<endl;
	for (int i = 0; i< m; i++) //create the matrix(to be transpose)
	{
		q = new int[n];
	}
	a  = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			q[j] = a++;
		}
	}
	for (int i = 0; i < n; i++)//assigning corresponding values to make a transpose
	{
		for (int j = 0; j < m; j++)
		{
			q[j] = p[j];
		}
	}
	cout<<"transpose is"<<endl;
	for (int i = 0; i < n; i++) //output transpose
	{
		for (int j = 0; j < m; j++)
		{
			cout << q[j] << "\t";
		}
		cout << "\n";
	}
	for (int i = 0; i < m; i++)
	{
		delete((int*)q);
	}
	delete [] q;

}
vector<void> add{
	int n = 0,m=0;
	cout<<"TO FIND THE SUM"<<endl;
	cout<<"enter no. of rows and columns of matrix"<<endl;
	cin>>m>>n;
	int **t,**q;
	t = new int*[m];
	for (int i = 0; i< m; i++)
	{
		t = new int[n];
	}
	int a  = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			t[j] = 0;
		}
	}
	char chk='y'; //any number of matrices can be added
	while (chk=='y'||chk=='Y'){
		q = new int*[m];
		for (int i = 0; i< m; i++)
		{
			q = new int[n];
		}
		a  = 0;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				q[j] = a++;
			}
		}
		cout<<"enter the numbers of matrix to be added"<<endl;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin>>q[j];
			}
		}
		cout<<"matrix you have entered"<<endl;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cout << q[j] << "\t";
			}
			cout << "\n";
		}
		for (int i = 0; i < m; i++) //addition
		{
			for (int j = 0; j < n; j++)
			{
				t[j] = t[j]+q[j];
			}
		}
		for (int i = 0; i < m; i++)
		{
			delete((int*)q);
		}
		delete [] q;
		cout<<"wish to add another matrix to this? y/n"<<endl;
		cin>>chk;
	}
	cout<<"sum is "<<endl;
	for (int i = 0; i < m; i++) //output sum
	{
		for (int j = 0; j < n; j++)
		{
			cout << t[j] << "\t";
		}
		cout << "\n";
	}
	for (int i = 0; i < m; i++)
	{
		delete((int*)t);
	}
	delete [] t;

}
vector<void> subtract{
	cout<<"TO SUBTRACT"<<endl;
	int n = 0,m=0;
	cout<<"enter no. of rows and columns of matrix"<<endl;
	cin>>m>>n;
	int **t,**q;
	char chk;
	t = new int*[m];
	for (int i = 0; i< m; i++)
	{
		t = new int[n];
	}
	int a  = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			t[j] = 0;
		}
	}
	cout<<"enter the numbers of matrix"<<endl;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin>>t[j];
		}
	}
	cout<<"matrix you have entered"<<endl;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << t[j] << "\t";
		}
		cout << "\n";
	}
	chk='y';
	while (chk=='y'||chk=='Y'){
		q = new int*[n];
		for (int i = 0; i< m; i++)
		{
			q = new int[n];
		}
		a  = 0;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				q[j] = a++;
			}
		}
		cout<<"enter the numbers of matrix to be subtracted"<<endl;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin>>q[j];
			}
		}
		cout<<"matrix you have entered"<<endl;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cout << q[j] << "\t";
			}
			cout << "\n";
		}
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				t[j] = t[j]-q[j];
			}
		}
		for (int i = 0; i < m; i++)
		{
			delete((int*)q);
		}
		delete [] q;
		cout<<"wish to subtract another matrix from the result? y/n"<<endl;
		cin>>chk;
	}
	cout<<"difference is "<<endl;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << t[j] << "\t";
		}
		cout << "\n";
	}
	for (int i = 0; i < n; i++)
	{
		delete((int*)t);
	}
	delete [] t;

}
vector<void> multiply{
	int n = 0,m=0,l=0;
	cout<<"TO FIND THE PRODUCT"<<endl;
	cout<<"enter no. of rows and columns of matrix"<<endl;
	cin>>m>>n;
	int **t,**q;
	t = new int*[m];
	for (int i = 0; i< m; i++)
	{
		t = new int[n];
	}
	int a  = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			t[j] = 0;
		}
	}
	cout<<"enter the numbers of matrix "<<endl;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin>>t[j];
		}
	}
	cout<<"matrix you have entered"<<endl;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << t[j] << "\t";
		}
		cout << "\n";
	}
	cout<<"enter no. of columns of 2nd matrix"<<endl;//no.of rows of 2nd column=no.of columns of 1st matrix(rule)
	cin>>l;
	q = new int*[n];
	for (int i = 0; i< n; i++)
	{
		q = new int[l];
	}
	a  = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			q[j] = a++;
		}
	}
	cout<<"enter the numbers of matrix to be multiplied"<<endl;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cin>>q[j];
		}
	}
	cout<<"matrix you have entered"<<endl;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cout << q[j] << "\t";
		}
		cout << "\n";
	}
	cout<<"product is"<<endl;
	int k=0;
	for (int i=0;i<m;i++)
	{
		for (int j=0;j<l;j++)
		{
			for (int r=1;r<=n;r++)
			{
				k=k+(t[r-1]*q[r-1][j]);
			}
			cout<<k<<"\t";
			k=0;
		}
		cout<<endl;
	}

}
vector<void> inverse3{ //inverse for 3x3 matrix
	int  p[3][3];// the matrix that is entered by user
	int q[3][3];//the transpose of a matrix p
	int C[3][3];//the adjunct matrix of transpose of a matrix p not adjunct of p
	double X[3][3];//the inverse
	int i,j;
	float x,n=0;
	cout<<"enter matrix"<<endl;
	for (i=0;i<3;i++)
	{
		for (j=0;j<3;j++)
		{
			cin>>p[j];
			q[j]=0;
			C[j]=0;
		}
	}
	for (i=0,j=0;j<3;j++)
	{
		if (j==2)
			n+=p[j]*p[i+1][0]*p[i+2][1];
		else if (j==1)
			n+=p[j]*p[i+1][j+1]*p[i+2][0];
		else
			n+=p[j]*p[i+1][j+1]*p[i+2][j+2];
	}
	for (i=2,j=0;j<3;j++)
	{
		if (j==2)
			n-=p[j]*p[i-1][0]*p[i-2][1];
		else if (j==1)
			n-=p[j]*p[i-1][j+1]*p[i-2][0];
		else
			n-=p[j]*p[i-1][j+1]*p[i-2][j+2];
	}
	cout<<"matrix is"<<endl;
	for (i=0;i<3;i++)
	{
		cout<<"\n";
		for (j=0;j<3;j++)
		{
			cout<<p[j]<<"\t";
		}
	}
	if (n!=0) x=1.0/n;
	else
	{
		cout<<"Division by 0!\n";

	}
	for (i=0;i<3;i++)
	{
		for (j=0;j<3;j++)
		{
			q[j]=p[j];
		}
	}
	C[0][0]=q[1][1]*q[2][2]-(q[2][1]*q[1][2]);
	C[0][1]=(-1)*(q[1][0]*q[2][2]-(q[2][0]*q[1][2]));
	C[0][2]=q[1][0]*q[2][1]-(q[2][0]*q[1][1]);
	C[1][0]=(-1)*(q[0][1]*q[2][2]-q[2][1]*q[0][2]);
	C[1][1]=q[0][0]*q[2][2]-q[2][0]*q[0][2];
	C[1][2]=(-1)*(q[0][0]*q[2][1]-q[2][0]*q[0][1]);
	C[2][0]=q[0][1]*q[1][2]-q[1][1]*q[0][2];
	C[2][1]=(-1)*(q[0][0]*q[1][2]-q[1][0]*q[0][2]);
	C[2][2]=q[0][0]*q[1][1]-q[1][0]*q[0][1];
	for (i=0;i<3;i++)
	{
		for (j=0;j<3;j++)
		{
			X[j]=C[j]*x;
		}
	}
	cout<<endl;
	cout<<" The inverse matrix of the matrix \n";
	for (i=0;i<3;i++)
	{
		for (j=0;j<3;j++)
		{
			cout<<X[j]<<"\t";
		}
		cout<<endl;
	}
	cout<<"\n\n";

}
vector<void> inverse2{ //inverse for 2x2 matrix
	int p[2][2];
	float q[2][2];
	int d,k;
	cout<<"enter the matrix"<<endl;
	for (int i=0;i<2;i++)
	{
		for (int j=0;j<2;j++)
		{
			cin>>p[j];
		}
	}
	cout<<"matrix is"<<endl;
	for(int i=0;i<2;i++)
	{
	   for(int j=0;j<2;j++)
	   {
	      cout<<p[j]<<"\t";
	   }
	   cout<<endl;
	}
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			q[j] = p[j];
		}
	}
	k=q[0][0];
	q[0][0]=q[1][1];
	q[1][1]=k;
	k=q[0][1];
	q[0][1]=q[1][0];
	q[1][0]=k;
	q[0][1]=(-1)*q[0][1];
	q[1][0]=(-1)*q[1][0];
	d=q[0][0]*q[1][1]-q[1][0]*q[0][1];
	cout<<"inverse of matrix is"<<endl;
	for (int i=0;i<2;i++)
	{
		for (int j=0;j<2;j++)
		{
			  q[j]=q[j]/d;
			  cout<<q[j]<<"\t"; 
		}
		cout<<endl;
	}

}
};


int main()
{
	int x;
	cin>>x;
  vector<int> p[][4];
 vector< int> p2[100];
myarray n1;
n1.diffrentsize;
n1.check;
n1.length;
n1.det;
if(x==4){
n1.add;
n1.subtract;
n1.multiply;
if(x==2&&y==2){
	n1.inverse2;}
if(x==3&&y==3){
	n1.inverse3;}
n1.transpose;}

	return 0;
}

وشكرا لكم

#2

كبداية اين اقواس الدوال() ؟ لست متاكدا من وجود نوع <vector<void

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#3

يا الله ما اطول هذا أخى عذرا مشكلتك أكيد له حل:

  • قسم الكود الى مجموعة من الوحدات المنفصلة
  • ابنى الكود كتلة بعد اﻻخرى وتححق من التشغيل
  • راجع مفهوم الــ vector ثم راجع cout التى بقسم public ثم الفئة
  • استخدم دوال getter و setter فى الفئة بدﻻ من cout فى public

وفقنى واياك الله

1

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#4

جزاكم الله خيرا ووفقكم دنيا واخره

AudaNix كتب:

يا الله ما اطول هذا أخى عذرا مشكلتك أكيد له حل:

  • قسم الكود الى مجموعة من الوحدات المنفصلة
  • ابنى الكود كتلة بعد اﻻخرى وتححق من التشغيل
  • راجع مفهوم الــ vector ثم راجع cout التى بقسم public ثم الفئة
  • استخدم دوال getter و setter فى الفئة بدﻻ من cout فى public

وفقنى واياك الله

حسناً جميعها فهمتها الا النقطه الاولى كيف اقسم الكود الى مجموعه من الوحدات ؟؟!!

<~ المعذرة اذا ثقلت عليكم لكن انا مبتدئه في لغه السي بلس

جل احترامي وتقديري لكم

#5
DONNA كتب:

جزاكم الله خيرا ووفقكم دنيا واخره

حسناً جميعها فهمتها الا النقطه الاولى كيف اقسم الكود الى مجموعه من الوحدات ؟؟!!

<~ المعذرة اذا ثقلت عليكم لكن انا مبتدئه في لغه السي بلس

جل احترامي وتقديري لكم

على الرحب والسعة

قسم الكود الى مجموعة من كتل الكود الصغيرة كل واحدة له وظيفة محددة وذلك عن طريق الدوال او الدوال الاعضاء بالفئة

راجع نوع وسائط الداول بحيث ومرر لها المتغيرات المتوافقة معها

ونصيحة اخرى استخدم بيئة تطوير نت بيز netbeans فأن بها محرر تدقيق كود فورى

وبالنهاية وفقنى واياك الله

1

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#6

بارك الله فيك وفي جهودة الجباره

لاحرمك الله الاجر والثواب

اللان انا عدلت على المشروع لما اعمل له تشغيل مازال هناك خطا لا اعلم ماهو تصحيحه

ياليت تصححه لي ..

هذا الكود بعد التعديل ..

#include <iostream>
#include <vector>
#include <string>

using namespace std;


class myarray{


private:


int p[3][3];


int p2[100];


public:


void diffrentsize(){


int x;
int y;
int z;
int w;
cout<<"enter 4 size of array"<<endl;
cin>>x;
cin>>y;
cin>>z;
cin>>w;

int *p4[4];
p4[0]=new int[x];
p4[1]=new int[y];
p4[2]=new int[z];
p4[3]=new int[w];

}


void setarray(vector<int> p[3][3],vector<int> p2[100])
{
p[3][3]=p[3][3];
p2[100]=p2[100];
}


int getp()
{
return p[3][3];
}


int getp2()
{
return p2[100];
}

void check(vector<int> p2[100]) 
{

if(p2.length()>100)
{
cout<<"the length of array is bigger than size of array"<<endl;
}

else 
{
cout<<"the length of array is fit the size of array"<<endl;}
}


void length(vector<int> *s)
{
int y=0;
for(int i=0;i<100;i++){
cin>>p2;}
while(p2[0]!='\0')
{y+=1;
s++;}
cout<<y;
}


void det(vector<int> p[3][3],int x){
cout<<endl<<"TO FIND DETERMINANT"<<endl;


int n = 0,val;
cout<<"enter no. of columns/rows of square matrix"<<endl;
cin>>n;


int **p3;
p3= new int*[n]; //make an array of ints, p points to them


for (int i = 0; i< n; i++) 
{
p3 = 

new int[n]; //each pointer now points to 'n' amount of ints
}


int a = 0;


for (int i = 0; i < n; i++)
{


for (int j = 0; j < n; j++)
{
p3[j] = a++; 

//assign some values
}
}
cout<<

"enter the values of matrix row-wise"<<endl;


for (int i = 0; i < n; i++)
{


for (int j = 0; j < n; j++)
{
cin>>p3[j];


if (n==1)
val=p3[j];
}
}


//using the formulae


if (n==2)
{val=p3[0][0]*p3[1][1]-p[0][1]*p3[1][0];}


if (n==3)
{val=(p3[0][0]*((p3[1][1]*p3[2][2])-(p3[1][2]*p3[2][1])))-
(p[0][1]*((p3[1][0]*p3[2][2])-(p[1][2]*p3[2][0])))+
(p[0][2]*((p3[1][0]*p3[2][1])-(p[1][1]*p3[2][0])));}


for (int i = 0; i < x; i++)
{


delete((int*)p3);//free up the array of pointers, must delete each one otherwise memory will leak
}


delete [] p3;
cout<<"determinant value is:";
cout<<val<<endl;

}
void transpose(vector<int> p[3][3],int x){


int n = 0,m=0;
cout<<"TO FIND TRANSPOSE"<<endl;
cout<<"enter no. of rows and columns of matrix"<<endl;
cin>>m>>n;


int **p3;
p3 = new int*[m];


for (int i = 0; i< m; i++)
{
p3 = new int[n];
}


int a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
p3[j] = a++;
}
}
cout<<"enter the numbers of matrix row-wise"<<endl;


for (int i = 0; i < m; i++) //input values
{


for (int j = 0; j < n; j++)
{
cin>>p3[j];
}
}
cout<<"matrix you have entered is"<<endl;


for (int i = 0; i < m; i++) //output matrix entered
{


for (int j = 0; j < n; j++)
{
cout << p3[j] << "\t";
}
cout << "\n";
}


int **q;
q = new int*[m];
cout<<endl;
for (int i = 0; i< m; i++) //create the matrix(to be transpose)
{
q = new int[n];
}
a = 0;

for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
q[j] = a++;
}
}


for (int i = 0; i < n; i++)//assigning corresponding values to make a transpose
{


for (int j = 0; j < m; j++)
{
q[j] = p3[j];
}
}
cout<<"transpose is"<<endl;


for (int i = 0; i < n; i++) //output transpose
{


for (int j = 0; j < m; j++)
{
cout << q[j] << "\t";
}
cout << "\n";
}


for (int i = 0; i < m; i++)
{


delete((int*)q);
}


delete [] q;

}
void


add(vector<int> p[3][3],int x){


int n = 0,m=0;
cout<<"TO FIND THE SUM"<<endl;
cout<<"enter no. of rows and columns of matrix"<<endl;
cin>>m>>n;


int **t,**q;
t = new int*[m];


for (int i = 0; i< m; i++)
{
t = new int[n];
}


int a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
t[j] = 0;
}
}


char chk='y'; //any number of matrices can be added


while (chk=='y'||chk=='Y'){
q = new int*[m];


for (int i = 0; i< m; i++)
{
q =new int[n];
}
a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
q[j] = a++;
}
}
cout<<"enter the numbers of matrix to be added"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cin>>q[j];
}
}
cout<<"matrix you have entered"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cout << q[j] << "\t";
}
cout << "\n";
}


for (int i = 0; i < m; i++) //addition
{


for (int j = 0; j < n; j++)
{
t[j] = t[j]+q[j];
}
}


for (int i = 0; i < m; i++)
{


delete((int*)q);
}


delete [] q;
cout<<"wish to add another matrix to this? y/n"<<endl;
cin>>chk;
}
cout<<"sum is "<<endl;


for (int i = 0; i < m; i++) //output sum
{


for (int j = 0; j < n; j++)
{
cout << t[j] << "\t";
}
cout << "\n";
}


for (int i = 0; i < m; i++)
{


delete((int*)t);
}


delete [] t;

}
void subtract(vector <int> p[3][3],int x){
cout<<"TO SUBTRACT"<<endl;


int n = 0,m=0;
cout<<"enter no. of rows and columns of matrix"<<endl;
cin>>m>>n;


int **t,**q;


char chk;
t = new int*[m];


for (int i = 0; i< m; i++)
{
t = new int[n];
}


int a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
t[j] = 0;
}
}
cout<<"enter the numbers of matrix"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cin>>t[j];
}
}
cout<<"matrix you have entered"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cout << t[j] << "\t";
}
cout << "\n";
}
chk='y';


while (chk=='y'||chk=='Y'){
q = new int*[n];


for (int i = 0; i< m; i++)
{
q = new int[n];
}
a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
q[j] = a++;
}
}
cout<<"enter the numbers of matrix to be subtracted"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cin>>q[j];
}
}
cout<<"matrix you have entered"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cout << q[j] << "\t";
}
cout << "\n";
}


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
t[j] = t[j]-q[j];
}
}


for (int i = 0; i < m; i++)
{


delete((int*)q);
}


delete [] q;
cout<<"wish to subtract another matrix from the result? y/n"<<endl;
cin>>chk;
}
cout<<"difference is "<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cout << t[j] << "\t";
}
cout << "\n";
}


for (int i = 0; i < n; i++)
{


delete((int*)t);
}


delete [] t;

}
void multiply(vector<int> p[3][3],int x){


int n = 0,m=0,l=0;
cout<<"TO FIND THE PRODUCT"<<endl;
cout<<"enter no. of rows and columns of matrix"<<endl;
cin>>m>>n;


int **t,**q;
t = new int*[m];


for (int i = 0; i< m; i++)
{
t = new int[n];
}


int a = 0;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
t[j] = 0;
}
}
cout<<"enter the numbers of matrix "<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cin>>t[j];
}
}
cout<<"matrix you have entered"<<endl;


for (int i = 0; i < m; i++)
{


for (int j = 0; j < n; j++)
{
cout << t[j] << "\t";
}
cout << "\n";
}
cout<<"enter no. of columns of 2nd matrix"<<endl;//no.of rows of 2nd column=no.of columns of 1st matrix(rule)
cin>>l;
q = new int*[n];


for (int i = 0; i< n; i++)
{
q = new int[l];
}
a = 0;


for (int i = 0; i < n; i++)
{


for (int j = 0; j < l; j++)
{
q[j] = a++;
}
}
cout<<"enter the numbers of matrix to be multiplied"<<endl;


for (int i = 0; i < n; i++)
{


for (int j = 0; j < l; j++)
{
cin>>q[j];
}
}
cout<<"matrix you have entered"<<endl;


for (int i = 0; i < n; i++)
{


for (int j = 0; j < l; j++)
{
cout << q[j] << "\t";
}
cout << "\n";
}
cout<<"product is"<<endl;


int k=0;


for (int i=0;i<m;i++)
{


for (int j=0;j<l;j++)
{


for (int r=1;r<=n;r++)
{
k=k+(t[r-1]*q[r-1][j]);
}
cout<<k<<"\t";
k=0;
}
cout<<endl;
}

}
void inverse3(vector<int> p[3][3] ,int x) { //inverse for 3x3 matrix


int p3[3][3];// the matrix that is entered by user


int q[3][3];//the transpose of a matrix p


int C[3][3];//the adjunct matrix of transpose of a matrix p not adjunct of p


double X[3][3];//the inverse


int i,j;


float x,n=0;
cout<<

"enter matrix"<<endl;


for (i=0;i<3;i++)
{


for (j=0;j<3;j++)
{
cin>>p3[j];
q[j]=0;
C[j]=0;
}
}


for (i=0,j=0;j<3;j++)
{


if (j==2)
n+=p3[j]*p3[i+1][0]*p3[i+2][1];


else if (j==1)
n+=p3[j]*p3[i+1][j+1]*p3[i+2][0];


else
n+=p3[j]*p3[i+1][j+1]*p3[i+2][j+2];
}


for (i=2,j=0;j<3;j++)
{


if (j==2)
n-=p3[j]*p3[i-1][0]*p3[i-2][1];


else if (j==1)
n-=p3[j]*p3[i-1][j+1]*p3[i-2][0];


else
n-=p3[j]*p3[i-1][j+1]*p3[i-2][j+2];
}
cout<<"matrix is"<<endl;


for (i=0;i<3;i++)
{
cout<<"\n";


for (j=0;j<3;j++)
{
cout<<p3[j]<<"\t";
}
}


if (n!=0) x=1.0/n;


else
{
cout<<"Division by 0!\n";

}


for (i=0;i<3;i++)
{


for (j=0;j<3;j++)
{
q[j]=p3[j];
}
}
C[0][0]=q[1][1]*q[2][2]-(q[2][1]*q[1][2]);
C[0][1]=(-1)*(q[1][0]*q[2][2]-(q[2][0]*q[1][2]));
C[0][2]=q[1][0]*q[2][1]-(q[2][0]*q[1][1]);
C[1][0]=(-1)*(q[0][1]*q[2][2]-q[2][1]*q[0][2]);
C[1][1]=q[0][0]*q[2][2]-q[2][0]*q[0][2];
C[1][2]=(-1)*(q[0][0]*q[2][1]-q[2][0]*q[0][1]);
C[2][0]=q[0][1]*q[1][2]-q[1][1]*q[0][2];
C[2][1]=(-1)*(q[0][0]*q[1][2]-q[1][0]*q[0][2]);
C[2][2]=q[0][0]*q[1][1]-q[1][0]*q[0][1];


for (i=0;i<3;i++)
{


for (j=0;j<3;j++)
{
X[j]=C[j]*x;
}
}
cout<<endl;
cout<<" The inverse matrix of the matrix \n";


for (i=0;i<3;i++)
{


for (j=0;j<3;j++)
{
cout<<X[j]<<"\t";
}
cout<<endl;
}
cout<<"\n\n";

}

};

int main()
{
vector<int>p[3][3];
vector<int>p2[100];
int x;
myarray n1;

cout<<"enter 1 to resize array or 0 don't"<<endl;
cin>>x;

n1.diffrentsize();
n1.setarray( p , p2 );
n1.getp();
n1.getp2();
n1.check(p2);



n1.length(p2);
n1.det(p,x);
if


(x==3){
n1.add(p,x);
n1.subtract(p,x);
n1.multiply(p,x);
n1.inverse3(p,x);
n1.transpose(p,x);
}


return 0;
}
#7

الخطأ الاول

المتغير x معرف كبارامتر للداله وفي نفس الوقت كمتغير

void inverse3(vector<int> p[3][3] ,int x) { //inverse for 3x3 matrix

float x,n=0;

الخطأ الثاني

استدعاء داله على p2 في حين انها مصفوفه

if(p2.length()>100)

بينما p2 معرفه كــ

void check(vector<int> p2[100])

ربما الاصح القول p.length()

ولكن لا اعقتد بان هناك داله اسمها length في vector انا غير متاكد لي زمان من الSTL

الخطأ الثالث

عمليات رياضيه بين متغيرات من انواع لا يوجد تعريف لمعنى العمليات الرياضيه بينها

{val=p3[0][0]*p3[1][1]-p[0][1] * p3[1][0];}

(p[0][1]*((p3[1][0]*p3[2][2])-(p[1][2]*p3[2][0])))+
(p[0][2]*((p3[1][0]*p3[2][1])-(p[1][1]*p3[2][0])));}

لاحظي الفرق بين نوع p3 و p

صراحة انا في الفتره الاخيره كسول و ليس عندي حافز لاقوم بنسخ الكود داخل فيجوال ستوديو او غيره

ربما عندما اشاهد موضوع مثل هذا اتجنبه ، في البداية كلنا نريد ان نساعد ولكن بعد فتره عندما يتكرر مثل هذا النمط من المواضيع يبدأ الشخص بالشعور بالملل

لذا حتى لا ينفر الاعضاء من المساعده رجاء خالص دائما دائما وابدا قومي بارفاق كود الخطأ

2

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#8

+1 مجهود عظيم اخى mental-driller جزاك الله خيرا ،،،

نحن نقدر لك هذا التعب

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…