هذا البرنامج على ال calssesو ال arraysو هوة عبارة عن 4 arrayاول واحد a[][] تملأ بارقام عشوائة
ثم بعد ذلك المستخدم يدخل عدة ارقام لو الرقم موجود فى a[][]يوضع فى ال b[][]و لو مش موجود يوضع فى ال c[][] و لو واحد من b[][] او c[][]اتملت او ملا الاثنين بندأ بجمع التلات مصفوفات و وضعهم فى sum[][]
على للمبتدئين قراية الكود او تنزيلة و على ما اعتقد سوف يعمل على جميع الكومبيلرز و اللى عندة VS.NET
من الافضل تنزيل المرفق
على الاساتذة المحترفين تقيم الكود و تصحيحة و ذكر نقاط الضعف فية
وشكرا لكم
ملحوظة انا رفقت الكود بردة كتبتة علشان محدش يبقى لة حجة :P
#include<iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
class Array
{
private :
int a[3][3];//for the random
int atemp[3][3];//for when he search in search for one time about the number
int b[3][3];//for the found number that the user enter
int c[3][3];//for the unfound number
int sum[3][3];//to add all in it
public :
Array()
{
srand(time(NULL) );
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[j]=rand()%10; // to fill a[][] with randam numbers
atemp[j]=a[j]; // the a[][] temp to search in
b[j]=0; // to fill b[][] with 0
c[j]=0; // to fill c[][] with 0
}
}
}
void nesba(int bb,int cc)
{
float b_calc,c_calc;
b_calc=bb*100/9;
c_calc=cc*100/9;
cout <<"You find "<<b_calc<<" % of b[][] and "<<c_calc<<" % of c[][]"<<endl<<endl;
}
void compar()
{
int temp=0;
int x=0;// for close the while when he entered 18 valus (by fill the two [][]
int bb=0,cc=0;//for check if one of them fill so close
int b1=0,b2=0; // to put in the right postion on the on b[][]
int c1=0,c2=0;// to put in the right postion on the on c[][]
while(x!=18)
{
bool m=0;// to know if it found or not
cout <<"Enter your number : ";
cin >>temp;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(temp==atemp[j])
{
m=1;
atemp[j]=-1;//to make it ==-1 beacaus i dont need to search for it again
i=3;j=3;// to break if find
}
}
}
if(m==1)
{
b[b1][b2]=temp;
b2++;
if (b2==3)//to fill the[][]
{
b2=0;
b1++;
}
bb++;
if(bb==9)
{
cout<<"\nYou fill the b[][]"<<endl;
x=17;
}
}
else if(m==0)
{
c[c1][c2]=temp;
c2++;
if (c2==3)//to fill the[][]
{
c2=0;
c1++;
}
cc++;
if(cc==9)
{
cout<<"\nYou fill the c[][]"<<endl;
x=17;
}
}
x++;// the counter
}
nesba(bb,cc);
system("pause");
}
void Show_A()
{
cout<<"\nThe A[][] is :"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<" "<<a[j];
}
cout<<endl;
}
}
void Show_b_c()
{
cout<<"\nThe B[][] is :"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<" "<<b[j];
}
cout<<endl;
}
cout<<"\nThe C[][] is :"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<" "<<c[j];
}
cout<<endl;
}
}
void Sum()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
sum[j]=a[j]+b[j]+c[j];
}
}
}
void Show_sum()
{
cout<<"\nThe Sum of the 3 arrays is :"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<" "<<sum[j];
}
cout<<endl;
}
}
};
main()
{
Array user;
user.compar();
system("cls");
user.Show_A();
user.Show_b_c();
user.Sum();
user.Show_sum();
}و السلام عليكم و رحمة الله و براكاتة
