
int x,*p,*q;
p=new int[4];
q=p;
*p=4;
for (int i=0; i<3; i++)
x=*p;
p++;
*p=x+i;
for (int i=0; i<4; i++)
{cout<<*q;
q++;
}
.. ياريت أحد يشرح لينا الdeep copy , shallow copy .. مادري شسالفتهم 
shallow :^^ لا ما نعرف مخنا مقفل من دخلنا البوينتر.. ياريت أحد يشرح لينا الdeep copy , shallow copy .. مادري شسالفتهم
![]()
int *p,*q;
p=new int;
q=p;
delete p;
int *p,*q;
p=new int;
q=new int;
[LEFT]q=*p*;[/LEFT]
delete p;
هوم وورك عطتنا اياه الدكتوره وقت الي ندرس بوينتر حليته و قلت بخليه ليكم بشوف صح او لا انا![]()
PHP:int x,*p,*q; p=new int[4]; q=p; *p=4; for (int i=0; i<3; i++) x=*p; p++; *p=x+i; for (int i=0; i<4; i++) {cout<<*q; q++; }
بنشوف تعرفون للبوينتر لو ويش![]()
shallow :
بعد ما نحذف " p " تختفي القيمة اللي كان يشير ليها " q "كود:int *p,*q; p=new int; q=p; delete p;
deep :
بعد ما نحذف " p " تبقى القيمة اللي يشير ليها " q "كود:int *p,*q; p=new int; q=new int; q=p; delete p;
الفرق بسيط الأول مستخدمين بوينتر واحد يشير قيمة ..طيب شلون نفرق مابينهم للآوت بوت ؟؟ يعني شكلهم على طول جذي ؟؟

حاضرين ..جزاك الله خيير و سامحنة![]()


-
السلام عليكم
لو سمحتو احد يقدر يشرح لي شنو اللي في جابتر 15
operator overloading
جفت فيدوهات شرح وقريت النوت وجفت سلايدات الدكتور يوسف
بس مآ فهمت شالسآلفه !!!
ياليت احد يوضح لي بس الفكره بششكل عام![]()
في الحقيقة أن يوسف حراث سرق هذه الشرائح و وضع عليها اسمهجفت سلايدات الدكتور يوسف
اووككككي فهمت مشككور ما ققصرتفي البرمجة كائنية التوجه لا يمكن مقارنة كائن بكائن إنما فقط مقارنة خاصية بخاصية فلتفرض أن لدينا مستطيلين يمكننا مقارنة الطول بالطول أو العرض بالعرض لكن لا يمكن مقارنة مستطيل بمستطيل آخر و حتى العمليات الحسابية لا يمكن أن نجمع أطوالهما مثلاً Operator Overloading أو التحميل الزائد للعملية هي ميزة تمكننا من مقارنة كائن بآخر في حالة مثالنا السابق و باستخدام هذه الميزة يمكن أن نجمع أطوالهما و عمل المقارنات بين المستطيلين
#include <iostream>
using namespace std;
template <class T>
bool compareArrays<T>(T arrA[], T arrB[], int sizeA, int sizeB[])
{
if(sizeA == sizeB)
{
for(int i=0; i<sizeA; i++)
if(arrA[i] == arrB[i])
return true;
return false;
}
return false;
}
int main()
{
int arrA;
int arrB;
int sizeA;
int sizeB;
cout<<"enter arrayA size"<<endl;
cin>>sizeA;
cout<<"enter arrayB size"<<endl;
cin>>sizeB;
cout<<"enter arrayA elements"<<endl;
cin>>arrA;
cout<<"enter arrayB elements"<<endl;
cin>>arrB;
}
ممكن أحد يحل لي هالأسئلة
Question1: Function: output_list
You need to create a function called output_list that will create a list of integers based on the 3 parameters: start, end and interval. The function should generate a list of numbers starting with the number start, each successive number should be closer to the number end and the numbers should all be interval apart.
[TABLE="class: MsoNormalTable, width: 6"]
[TR]
[TD="width: 295, bgcolor: transparent"]Example1:
[/TD]
[TD="width: 372, bgcolor: transparent"]Example2:
[/TD]
[/TR]
[TR]
[TD="width: 295, bgcolor: transparent"]Start=3 end=11 interval=2
The output: 3 5 7 9 11
[/TD]
[TD="width: 372, bgcolor: transparent"]Start=1 end=650 interval=100
The output: 1 101 201 301 401 501 601
[/TD]
[/TR]
[/TABLE]
Question2:
Function: sum_list
You need to create a function called sum_list that will return the sum of a list of integers based on the 3 parameters: start, endand interval.
[TABLE="class: MsoNormalTable, width: 6"]
[TR]
[TD="width: 295, bgcolor: transparent"]Example1:
[/TD]
[TD="width: 372, bgcolor: transparent"]Example2:
[/TD]
[/TR]
[TR]
[TD="width: 295, bgcolor: transparent"]Start=3 end=11 interval=2
Resul= 3+ 5 + 7+ 9+ 11
Output=The final resul is 25
[/TD]
[TD="width: 372, bgcolor: transparent"]Start=1 end=650 interval=100
Result: 1+101+ 201+ 301+401+ 501+ 601
Output: 2107
[/TD]
[/TR]
[/TABLE]
Question3:
Function: curveup_list
You need to create a function called curveup_list that will receive an a list of integers, a length and integer interval. The function should increase each element of the array list by interval..
[TABLE="class: MsoNormalTable, width: 6"]
[TR]
[TD="width: 295, bgcolor: transparent"]Example1:
[/TD]
[TD="width: 372, bgcolor: transparent"]Example2:
[/TD]
[/TR]
[TR]
[TD="width: 295, bgcolor: transparent"]List[ ] = 3 7 11 1 0
Length=5 interval=3
Resul:
List[] =6 10 14 4 3
[/TD]
[TD="width: 372, bgcolor: transparent"]List[ ] = 15 24 1 6 9 7 11 1 0 5
Length=10 interval=1
Resul:
List[] =16 24 2 7 9 7 12 2 1 6
[/TD]
[/TR]
[/TABLE]
#include<iostream>
using namespace std;
void output_list(int s,int e ,int i){
for(int j = s ; j <= e ; j+=i)
cout<< j << " " ;
}
int sum_list(int s,int e ,int i){
int sum = 0 ;
for(int j = s ; j <= e ; j+=i)
sum+=j;
return sum;
}
void curveup_list(int List[] , int length , int interval){
for(int j = 0 ; j < length ; j++)
List[j]=List[j]+interval;
}
int main(){
int List[5]={10,20,2,22,8};
output_list(1,650,100);
cout<<endl<<endl;
cout<<"sum = "<<sum_list(1,650,100);
cout<<endl<<endl;
for(int j = 0 ; j < 5 ; j++)
cout<<List[j]<<" ";
cout<<endl<<endl;
curveup_list(List,5,3);
for(int j = 0 ; j < 5 ; j++)
cout<<List[j]<<" ";
cout<<endl<<endl;
system("pause");
return 0;
}