xxx.cppالسلام عليكم ورحمه وبركاته
اخباركم شباب
ياليت احد يساعدني بتحويل البرنامج التالي الى class
مع الشكر
والله يجزاكم الف خير
مع العلم انه فيه ملف مرفق لاني عجزت انزل البرنامج بطريقه صح
//designed by Eng.hamdy
#include <iostream.h>
#include<iomanip.h>
#include<math.h>
void printarray(int items[5][3]);
void arrang(int items[5][3]);
int binarySearch(int a[5][3], int value,int x,int y);
int main()
{
int items[5][3];
int i,j;
for ( i=0;i<5;i++)//ادخال عناصر المصفوفة
{
cout<<"input id ,price and quantity for product no "
<<i+1<<endl;
for( j=0;j<3;j++)
cin>>items[j];
}
arrang(items);
printarray(items);//طباعة المصفوفة
int no_item;
int q;
char ch='y';
while(ch=='y')//تكرار
{
cout<<"Enter code of product: ";
cin>>no_item;
//int p=research(items,no_item);
int x=0;
int y=4;
int p=binarySearch(items,no_item,x,y);
if (p==-1)
{
cout<<"The product is not found"<<endl;
continue;
}
else
{
cout<<"The product is found"<<endl;
cout<<"Enter wanted quantity: ";
cin>>q;
}
if(q<=itemsبسم الله الرحمن الرحيم[2])
{
cout<<"the quantity is available and the opertion done"<<endl;
itemsبسم الله الرحمن الرحيم[2]-=q;// خصم الكمية المباعة من الكمية الموجودة
cout<<"total price is "
<<q*itemsبسم الله الرحمن الرحيم[1]<<endl;//طباعة السعر
printarray(items);//طباعة المصفوفة
}
else
{ cout<<"The quantity is not available"<<endl;
}
cout<<"do you want to do another opertion (y for yes or n for no)?";// للسؤال عن عمليه اخرى
cin>>ch;
}
return 0;
}
void printarray(int items[5][3])//طباعة المصفوفة
{
for (int i=0;i<5;i++)
{
cout<<endl;
for(int j=0;j<3;j++)
cout<<setw(10)<<items[j];
}
cout<<endl;
}
void arrang(int items[5][3]){//arrang ترتيب
int i,j;
int a,b,c;//a ==> id , b ==> price , c ==>quentity
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
if(items[j][0]<items[0])
{
a=items[j][0];
b=items[j][1];
c=items[j][2];
items[j][0]=items[0];
items[j][1]=items[1];
items[j][2]=items[2];
items[0]=a;
items[1]=b;
items[2]=c;
}
}
}
}
int binarySearch(int a[5][3], int value,int x,int y)
{
int mid;
if (y < x)
return -1;//فشل في البحث
mid = floor((x+y)/2);
if (value > a[mid][0])
return binarySearch(a, value, mid+1, y);
else if (value < a[mid][0])
return binarySearch(a, value, x, mid-1);
else
return mid;
}