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

مساعده مستعجله في ال Array

بدأه M A R W A في 5 يناير 2010 · 11 رد · 976 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

.

.

.

مساء الخير..

مطلوب منا هاد البرنامج مشروع :blink:

write a c++ programing to perform the matrix manipulation as showing in the main menu below:

1-youre program should have a function for each process.

2-youre program should returned to the main menu after showing the needed process output.

3-Matrix A and B could have any size from 1*1 to10*10.

4-use comment in your program to clarify ambiguous statements.

<1> Fill A&B

<2> Sum of A&B

<3> Product of A&B

<4> Transpost of A

<5> Is A symmetric

<6> Det (A)

<7> Inv (A)

<8> To Exite

هلا انا بلشت في وحليتو

بس المطلوب السادس ((المحددات))والمطلوب السابع ((المعكوس))هدول ولا اشي عارفه فيهم :unsure: ..

بليز ساعدوني وما تقصرو معي محتاجيتو ضروري..

الليله اخر موعد معي..وانا هلا بامتحانات الفانل فما في معي وقت اضيعوو اكتر من اللي ضاع بدون فايده :sad: ...

علما اني مبتداه بالبرمجه..وشكلي مش رح استمر : :S

الله يوفقكم ويسعدكم ما تقصرو معي ..:sad: :sad:

وجزاكو الله خير :)

هي البرنامج ..

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>


int A[10][10],B[10][10],result[10][10];
void sum(int A[][10],int B[][10],int size)
{
  for(int i=0;i<size;i++)
   {
     for(int j=0;j<size;j++)
        result[j]=A[j]+B[j];
    }
}

//-----------------

void  Enter(int A[][10],int B[][10],int size)
{
	int i,j;
   for( i=0;i<size;i++)
      for( j=0;j<size;j++)
         {
	         cout<<"A["<<i<<"]["<<j<<"] = ";
            cin>>A[j];
         }
    for( i=0;i<size;i++)
       for( j=0;j<size;j++)
         {
           cout<<"B["<<i<<"]["<<j<<"] = ";
           cin>>B[j];
         }
}

//-----------------

void show(int A[][10],int size)
{
	for (int i=0;i<size;i++)
	{
		for (int j=0;j<size;j++)
		{
			cout<<A[j]<<"  ";
		}
		cout<<endl;
	}
}

//-----------------

//// multiplication/////

void product(int A[][10],int B[][10],int size)
{
	int i,j,k;
	int s=0;
	for (i=0;i<size;i++)
	{
		for (j=0;j<size;j++)
		{
			for (k=0;k<size;k++)
			{
				s+=A[k]*B[k][j];
			}
			result[j]=s;
              s=0;
		}
	}
}


//====================

void TranspostA(int A[][10],int B[][10],int size)
{
    if(A==NULL)
    {
        cout<<"Arrays Are Empty";
        return;
    }
    else
    {
        int i,j;
        for(i=0 ; i<size ; i++)
        {
            for(j=0 ; j<size ; j++)
            {
                cout<<A[j]<<" ";
            }
            cout<<endl;
        }
    }
}

//====================

bool IsA_Symmetric(int A[][10],int B[][10],int size)
{
    if(A==NULL)
    {
        cout<<"Arrays Are Empty";
        return false;
    }
    else
    {
        int i,j;
        for(i=0 ; i<size ; i++)
        {
            for(j=0 ; j<size ; j++)
            {
                if(A[j]!=A[j])
                    return false;
            }
        }
    }
    return true;
}

//====================

void Det(int A[][10],int B[][10],int size)
   {




   }
//====================

void Inv(int A[][10],int B[][10],int size)

   {


  }

//===========================

void menu()
{
system("CLS");
cout<<"\n\n";
cout<<" ============================================="<<endl;
cout<<" *             ^_^ Main Menu ^_^             *"<<endl;
cout<<" ============================================="<<endl;
cout<<" * <1> Fill A&B                              *"<<endl;
cout<<" * <2> Sum of A&B                            *"<<endl;
cout<<" * <3> Product of A&B                        *"<<endl;
cout<<" * <4> Transpose of A                        *"<<endl;
cout<<" * <5> Is A symmetric                        *"<<endl;
cout<<" * <6> Det (A)                               *"<<endl;
cout<<" * <7> Inv (A)                               *"<<endl;
cout<<" * <8> To Exite                              *"<<endl;
cout<<" ============================================="<<endl;
cout<<" Please enter your choice : "<<endl;

}


//******************************************************************************


int main()
 {
   int size;
   cout<<"enter the size of matrex :"<<endl;
   cin>>size;
   menu();
   int h;
   cin>>h;

   while(h!=8)
       {
         switch(h)
              {
                case 1:
                     {
                       Enter(A,B,size);
                       getch();
                       menu();
                       cin>>h;
                      }
                break;

//------------------------

                case 2:
                    {
                      sum(A,B,size);
                      show(A,size);
                      cout<<"+"<<endl;
                      show(B,size);
                      cout<<"\n------------------------------\n";
                      show(result,size);
                      getch();
                      menu();
                      cin>>h;
                     }
                 break;

//------------------------

                 case 3:
                     {
                     	product(A,B,size);
                     	show(A,size);
                     	cout<<"X"<<endl;
                     	show(B,size);
                        cout<<"\n------------------------------\n";
                      	show(result,size);
                        getch();
                        menu();
                        cin>>h;
                      }
                 break;

//------------------------

                case 4:
                    {
                      TranspostA(A,B,size);
                      getch();
                      menu();
                      cin>>h;
                    }
                break;

//------------------------

               case 5:
                   {
                     if(IsA_Symmetric(A,B,size))
		            		cout<<"A is Symmetric";
		            	else
			            	cout<<"A is Asymmetric";
                    getch();
                    menu();
                    cin>>h;
                  }
           break;

//------------------------

          case 6:
              {



                 getch();
                 menu();
                 cin>>h;
              }
        break;

//------------------------

        case 7:
           {



            getch();
            menu();
            cin>>h;
           }
       break;

//------------------------

}//end switch

}//end while

return 0;

}

تم تعديل هذه المشاركة بواسطة M A R W A في 5 يناير 2010 في 12:47

#2

http://en.wikipedia.org/wiki/Determinant

http://www.mathwords.com/i/inverse_of_a_matrix.htm

الInverse صعب و رخم علي الورق في مصفوفة 3*3 ... مجربتش حال 10*10 هيكون عامل ازاي :wacko:

BEng , Electronics and communications.

Embedded systems engineer.

Graphics Programmer

عالم الكومبيوتر هو من لديه المعرفة في علوم الكومبيوتر ، الرياضيات ، هندسة الالكترونيات -احمد صالح

#3
احمد صالح كتب:

http://en.wikipedia.org/wiki/Determinant

http://www.mathwords.com/i/inverse_of_a_matrix.htm

الInverse صعب و رخم علي الورق في مصفوفة 3*3 ... مجربتش حال 10*10 هيكون عامل ازاي :wacko:

مشكور خيي عاللينكات

اطلعت عليهم قبل هيك

بس انا بدي اياهم برمجيا ما عرفت كيف بنعملو ..

يعطيك العافيه غلبناك..

/

لقيت هدا بس ما فهمت شي من الاكواد ..

http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/determinant

تم تعديل هذه المشاركة بواسطة M A R W A في 5 يناير 2010 في 13:43

#4

بالله ساعدوني يا جماعه

اذا مو زابط 10*10 بنحول البرنامج لـ 3*3

نخسر 5 علامات ولا نخسر البرنامج كلو .. :unsure: :unsure:

#5

السلام عليكم .

هذه الداله التي توجد لك المحدد:

float Determinant(float  a[10][10],int n)
{
int i,j,j1,j2;
float det = 0;
float m[10][10];

if (n < 1) { 

} else if (n == 1) {
det = a[0][0];
} else if (n == 2) {
det = a[0][0] * a[1][1] - a[1][0] * a[0][1];
} else {
det = 0;
for (j1=0;j1<n;j1++) {
for (i=0;i<n-1;i++)
for (i=1;i<n;i++) {
j2 = 0;
for (j=0;j<n;j++) {
if (j == j1) continue;
m[i-1][j2] = a[j];
j2++;
}
}
det += pow(-1.0,1.0+j1+1.0) * a[0][j1] * Determinant(m,n-1);

}
}
tvquran_6.gif

#6
فهدالشلوي كتب:

السلام عليكم .

هذه الداله التي توجد لك المحدد:

float Determinant(float  a[10][10],int n)
{
int i,j,j1,j2;
float det = 0;
float m[10][10];

if (n < 1) { 

} else if (n == 1) {
det = a[0][0];
} else if (n == 2) {
det = a[0][0] * a[1][1] - a[1][0] * a[0][1];
} else {
det = 0;
for (j1=0;j1<n;j1++) {
for (i=0;i<n-1;i++)
for (i=1;i<n;i++) {
j2 = 0;
for (j=0;j<n;j++) {
if (j == j1) continue;
m[i-1][j2] = a[j];
j2++;
}
}
det += pow(-1.0,1.0+j1+1.0) * a[0][j1] * Determinant(m,n-1);

}
}

مشكور خيي فهد ..

بس ضفت الفنكشن على برنامجي وعدلت الاسماء على اساس يمشي مع اللي عملتو ..

بس مابيتنفذ بحكيلي انو : call of nonfunction

!!!

مش عارفه ليش

هي البرنامج ..اغلبك نفذو عندك وشوف شو الخطأاذا بتقدر تساعدني ..وبكون شاكره الك..

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>


int A[10][10],B[10][10],result[10][10];
void sum(int A[][10],int B[][10],int size)
{
  for(int i=0;i<size;i++)
   {
     for(int j=0;j<size;j++)
        result[j]=A[j]+B[j];
    }
}

//-----------------

void  Enter(int A[][10],int B[][10],int size)
{
        int i,j;
   for( i=0;i<size;i++)
      for( j=0;j<size;j++)
         {
                 cout<<"A["<<i<<"]["<<j<<"] = ";
            cin>>A[j];
         }
    for( i=0;i<size;i++)
       for( j=0;j<size;j++)
         {
           cout<<"B["<<i<<"]["<<j<<"] = ";
           cin>>B[j];
         }
}

//-----------------

void show(int A[][10],int size)
{
        for (int i=0;i<size;i++)
        {
                for (int j=0;j<size;j++)
                {
                        cout<<A[j]<<"  ";
                }
                cout<<endl;
        }
}

//-----------------

//// multiplication/////

void product(int A[][10],int B[][10],int size)
{
        int i,j,k;
        int s=0;
        for (i=0;i<size;i++)
        {
                for (j=0;j<size;j++)
                {
                        for (k=0;k<size;k++)
                        {
                                s+=A[k]*B[k][j];
                        }
                        result[j]=s;
              s=0;
                }
        }
}


//====================

void TranspostA(int A[][10],int B[][10],int size)
{
    if(A==NULL)
    {
        cout<<"Arrays Are Empty";
        return;
    }
    else
    {
        int i,j;
        for(i=0 ; i<size ; i++)
        {
            for(j=0 ; j<size ; j++)
            {
                cout<<A[j]<<" ";
            }
            cout<<endl;
        }
    }
}

//====================

bool IsA_Symmetric(int A[][10],int B[][10],int size)
{
    if(A==NULL)
    {
        cout<<"Arrays Are Empty";
        return false;
    }
    else
    {
        int i,j;
        for(i=0 ; i<size ; i++)
        {
            for(j=0 ; j<size ; j++)
            {
                if(A[j]!=A[j])
                    return false;
            }
        }
    }
    return true;
}

//====================

float Det(int A[][10],int size)

{
int i,j,j1,j2;
float Det = 0;
float m[10][10];

if (size< 1) {

}
else if (size == 1)
{
Det = A[0][0];
}
 else if (size == 2)
  {
Det = A[0][0] * A[1][1] - A[1][0] * A[0][1];
}
 else
  {
Det = 0;
for (j1=0;j1<size;j1++)
 {
for (i=0;i<size-1;i++)
for (i=1;i<size;i++)
 {
j2 = 0;
for (j=0;j<size;j++)
 {
if (j == j1)
 continue;
m[i-1][j2] = A[j];
j2++;
}
}
Det += pow(-1.0,1.0+j1+1.0) *A[0][j1] * Det(m,size-1);

}
}

}


//====================

void Inv(int A[][10],int size)

   {


  }

//===========================

void menu()
{
system("CLS");
cout<<"\n\n";
cout<<" ============================================="<<endl;
cout<<" *             ^_^ Main Menu ^_^             *"<<endl;
cout<<" ============================================="<<endl;
cout<<" * <1> Fill A&B                              *"<<endl;
cout<<" * <2> Sum of A&B                            *"<<endl;
cout<<" * <3> Product of A&B                        *"<<endl;
cout<<" * <4> Transpose of A                        *"<<endl;
cout<<" * <5> Is A symmetric                        *"<<endl;
cout<<" * <6> Det (A)                               *"<<endl;
cout<<" * <7> Inv (A)                               *"<<endl;
cout<<" * <8> To Exite                              *"<<endl;
cout<<" ============================================="<<endl;
cout<<" Please enter your choice : "<<endl;

}


//******************************************************************************


int main()
 {
   int size;
   cout<<"enter the size of matrex :"<<endl;
   cin>>size;
   menu();
   int h;
   cin>>h;

   while(h!=8)
       {
         switch(h)
              {
                case 1:
                     {
                       Enter(A,B,size);
                       getch();
                       menu();
                       cin>>h;
                      }
                break;

//------------------------

                case 2:
                    {
                      sum(A,B,size);
                      show(A,size);
                      cout<<"+"<<endl;
                      show(B,size);
                      cout<<"\n------------------------------\n";
                      show(result,size);
                      getch();
                      menu();
                      cin>>h;
                     }
                 break;

//------------------------

                 case 3:
                     {
                        product(A,B,size);
                        show(A,size);
                        cout<<"X"<<endl;
                        show(B,size);
                        cout<<"\n------------------------------\n";
                        show(result,size);
                        getch();
                        menu();
                        cin>>h;
                      }
                 break;

//------------------------

                case 4:
                    {
                      TranspostA(A,B,size);
                      getch();
                      menu();
                      cin>>h;
                    }
                break;

//------------------------

               case 5:
                   {
                     if(IsA_Symmetric(A,B,size))
                                        cout<<"A is Symmetric";
                                else
                                        cout<<"A is Asymmetric";
                    getch();
                    menu();
                    cin>>h;
                  }
           break;

//------------------------

          case 6:
              {



                 getch();
                 menu();
                 cin>>h;
              }
        break;

//------------------------

        case 7:
           {



            getch();
            menu();
            cin>>h;
           }
       break;

//------------------------

}//end switch

}//end while

return 0;

}
#7

أعتقد انك استخدمت الاسم det كداله وكمتغير غير أحدهما.

tvquran_6.gif

#8

هي عملتو

void Det(int A[][10],int size)

{
int i,j,j1,j2;
int det = 0;
int m[10][10];

if (size< 1) {

}
else if (size == 1)
{
det = A[0][0];
}
 else if (size == 2)
  {
det = A[0][0] * A[1][1] - A[1][0] * A[0][1];
}
 else
  {
det = 0;
for (j1=0;j1<size;j1++)
 {
for (i=0;i<size-1;i++)
for (i=1;i<size;i++)
 {
j2 = 0;
for (j=0;j<size;j++)
 {
if (j == j1)
 continue;
m[i-1][j2] = A[j];
j2++;
}
}
det += pow(-1.0,1.0+j1+1.0) *A[0][j1] * Det(m,size-1);

}
}

}

بس في ايرور بحكيلي : not an allowed type

#9

لماذا جعلت الدالة void .

tvquran_6.gif

#10

خلص رجعتو فلوت وتنفذ ...

مشكووور كتير كتير وجزاك الله الف خير ..

ربي يسعدك ويفتحها بوجهك ^_^

بس في المين كيف بنستدعيه

يعني المحدد هاد برجع قيمه وحده ولا مصفوفه ؟؟

اغلبك معي استحملني .. :blush:

#11

المحدده رقم حقيقي وليس مصفوفة وله عدد من الاستخدامات فهو يستخدم لإيجاد المعكوس و يستخدم في حل المعادلات الخطيه .

tvquran_6.gif

#12

اوك ..مشكور كتير عالمعلومه ^_^

عملت عادي واستدعيتو

هلا عبيت المصفوفه ولما طلبت ال Det الها طلعلي رقم غريب انو 0X0004566

مش عارفه هاد هو هيك بكون ولا في مشكله ..؟!

سؤال اخير استحملنا :blush:

هلا هاد قانون ال Inv

Inv=1/Det * TranspostA

هو اللي بنستعملو هون ولا لأ..

اذا هو اللي بنستعملو فانا جربت هاد الفنكشن:

void Inv(int A[][10],int size)

   {
   Inv=1/Det * TranspostA;

  }

بس هون ما بعتبرلي الـ * انها ضرب ..بعتبرها بويتربطلعلي ايرور عليها وبحكيلي : illegal use of pointer

تم تعديل هذه المشاركة بواسطة M A R W A في 6 يناير 2010 في 00:20

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