موقع طلبة جامعة البحرين

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

تسجيل دخول
  • قسم المكتبة الجامعية مغلق مؤقتا بعد الاستهداف التي تعرضت له بعض خدمات أمازون في البحرين، جاري استرجاع الملفات ونقلها إلى سيرفرات جديدة وسيتم بعدها اعادة افتتاح المكتبة

ITCS112 - ITCS104 - ITCS102 للفصل الصيفي 2014 - 2015

اهو المقرر بشكل عام تتركز صعوبتة في pointer و recursion فاذا يا جماعة ما عليكم امر تحطون لينا شرح عن هالجبترين نكون شاكرين ليكم :smile:
 
Write a recursive function named Rightdigit. The prototype of the function is:

int Rightdigit(int n, int k);

This function returns the
kth digit of the positive integer n.

For example, if
n is the integer 29815:

The call
Rightdigit (n,0 ) would return the digit 5

The call
Rightdigit (n,2)would return the digit 8.

Note that the digits are numbered from right to left beginning with the
“zeroth digit.”


طلبتكم في فكرة هالسوال ؟
 
[IMGL]
#include


<iostream>


using


namespace std;


void


printReverse(int n);


int


main()


{




int num;



cout<<

"Enter a number: ";


cin>>num;


cout<<

"The number in reverse order is: ";


printReverse(num);


cout<<endl;



system(

"pause");




return 0;


}


void


printReverse(int n){




if(n==0)




return,




elseif(n<0)




return;




else;


{


coue<<n%10;


printReverse(n);





}
[/IMGL]


بطبعه بالعكس ؟؟ احد يقول لي شو الايرور


Write a recursive function named reverseInput that does not take any parameter and does not


return any value. The function asks the user to enter a positive integer number each time it is


called, until zero or a negative number is input. The function then outputs the numbers entered in


reverse order. The prototype of the function is:

void reverseInput();


Example of the function Run is:


Enter positive number, (use 0 or negative to stop) :30


Enter positive number, (use 0 or negative to stop) :20


Enter positive number, (use 0 or negative to stop) :50


Enter positive number, (use 0 or negative to stop) :10


Enter positive number, (use 0 or negative to stop) :0


10


50


20


30
السؤال طلب نطبع الأرقام اللي حطاها اليوزر بالعكس
يعني أول شي بما أن الفنكشن ما تاخذ parameter
نعرف متغير من نوع integer ونطلب من اليوزر يحط الرقم
إذا اليوزر حط 0 أو رقم أقل، هنيه تنتهي وظيفة الفنكشن، ما نسوي لها call مرة ثانية
فالـbase case بتكون إذا الرقم أكبر من 0، نسوي كول للفنكشن وبعدها نطبع الرقم (أي شي يكون تحت الكول، راح يتطبق آخر شي، لما اليوزر يحط 0 أو أقل)
هذا الحل

PHP:
void reverseInput(){
	int num;
	cout<<"Enter positive number, (use 0 or negative to stop): ";
	cin>>num;
	if(num>0)
	{
		reverseInput();
		cout<<num<<endl;
	}
}
 
ممكن شو المطلوب من الدروس واي جباتر بالفاينيل ITCS104 واي جبتر اركز عليه ؟؟ وشكراً

كل اللي خذيناه مطلوب معانا
Chapter 8, 10, 11, 12, 14, 15, 17
بالنسبة لجبتر 15 مطلوب بس الـOverloading
 
السلام عليكم شعب ..

بس بغيت واحد يرح ليي 2 Dynamic Array

حتى لو موجود عندكم نوتات حقه ما في مشكلة​

شنو بالضبط مو فاهم فيهم؟
مثلاً عشان تعرف 2D dynamic array
الـSyntax يكون بهذي الطريقة
Type **2D-ArrayName;
مثلاً
PHP:
int **Array;

وإذا تبي تحدد عدد الـrows
PHP:
Array=new int *[size];
عشان تحدد عدد الـcolumns
PHP:
Array[IndexNumber]= new int [C-Size];

مثلاً لو عندنا جدول من 3 صفوف وكل صف فيه عمودين نحتاج نستخدم for loop
PHP:
int **Table;
Table=new int *[3];

for(int i=0; i<3; i++)
Table[i]=new int [2];

في هذا الرد، طريقة الحذف
https://www.uob-bh.com/forum/showthread.php?t=29349&p=665379&viewfull=1#post665379
 
اهو المقرر بشكل عام تتركز صعوبتة في pointer و recursion فاذا يا جماعة ما عليكم امر تحطون لينا شرح عن هالجبترين نكون شاكرين ليكم :smile:
راح احاول انزل شرح لـrecusion بعد كم ساعة إن شاء الله.

Write a recursive function named Rightdigit. The prototype of the function is:

int Rightdigit(int n, int k);

This function returns the
kth digit of the positive integer n.

For example, if
n is the integer 29815:

The call
Rightdigit (n,0 ) would return the digit 5

The call
Rightdigit (n,2)would return the digit 8.

Note that the digits are numbered from right to left beginning with the
“zeroth digit.”


طلبتكم في فكرة هالسوال ؟
السؤال فكرته أنه يطلع الرقم الموجود في ترتيب معين (الترتيب يبدء من 0، من اليمين لليسار)
مثلاً لو كان الرقم 29815
وانت بغيت تطلع الرقم الموجود في الترتيب 0، يعني أول رقم ع اليمين، الجواب راح يكون 5
لو مثلاً بغيب الرقم الموجود في الترتيب 4، الجواب يكون 2
 
التعديل الأخير:
Write the definition of the constructor function Employee(string first, string
last); which dynamically allocates memory for firstName and lastName and copies first
and last to them. The function should increment empCount by 1. Use deep copy.

emploee::emploee(string F,string last)
{
p=new first;
q=new last;
p=q;
}

صحيح الحل؟؟
 
Recursion Function
عادةً نسوي call لأي فنكشن من خلال فنكشن ثانية
مثلاً من خلال الـman function نسوي call لفنكشن لها وظيفة معينة
لكن الـRecursion عبارة عن فنكشن تسوي call لنفسها


منطقياً، اي فنكشن تسوي call لنفسها مستحيل توقف.. لأن راح يتكرر نفس الشي على طول
لكن احنا راح نخلي الفنكشن تسوي call لنفسها مع تغيير قيم المتغيرات اللي راح تكون عندنا.


أي Recursion Function لازم يكون لها Base Case
الـBase Case عبارة عن النقطة اللي تكون فيها الفنكشن وصلت للنهاية، المفترض انت تستنجها من خلال السؤال
لو مثلاً سؤال طلب كتابة Recursion Function لحساب الـFactorials
مثلاً، Factorial 4 عبارة عن 4*3*2*1 والناتج راح يكون 24
نقدر نستنتج أنه الفنكشن المفترض توقف تسوي كول لنفسها إذا الرقم وصل 0، لأن إذا الرقم وصل 0 وصار كول للفنكشن مرة ثانية
الناتج دائماً بيكون 0 مهما كان الرقم.


ايضاً، من خلال حساب الـFactorial نلاحظ أن الرقم كل مرة يكون أقل بـ1
فهذا اللي راح يصير إذا الفنكشن تسوي كول لنفسها


أول شي هذا الكود الخاص بحساب الـFactorials
PHP:
int Factorial(int num){
	if(num==0)
		return 1;
	else
		return num * Factorial(num-1);
}

لو مثلاً عندنا الرقم 4،، هذي الصورة توضح شاللي قاعد يصير بالضبط
ip9s36.jpg
 
  • Like
التفاعلات: Memm
Consider the following class
class ArrClass
{
private:
double arr[20];
int length;
public:
ArrClass (int L=0);
void print() const;
};
Overload the operator == (equal to) as member function of the class ArrClass, so that:
A1==A2 will return true if A1 and A2 have the same length and the elements of A1 equal to
the corresponding elements of A2.
Otherwise, it returns false.


سؤال عن ال member function.. ادا هو يستقبل باراميتر واحد ويقارنه باللي موجود ..كيف في هدا السؤال يستقبل 2 باراميتر A1&A2
ويقارنهم ؟؟
 
Recursion Function
عادةً نسوي call لأي فنكشن من خلال فنكشن ثانية
مثلاً من خلال الـman function نسوي call لفنكشن لها وظيفة معينة
لكن الـRecursion عبارة عن فنكشن تسوي call لنفسها


منطقياً، اي فنكشن تسوي call لنفسها مستحيل توقف.. لأن راح يتكرر نفس الشي على طول
لكن احنا راح نخلي الفنكشن تسوي call لنفسها مع تغيير قيم المتغيرات اللي راح تكون عندنا.


أي Recursion Function لازم يكون لها Base Case
الـBase Case عبارة عن النقطة اللي تكون فيها الفنكشن وصلت للنهاية، المفترض انت تستنجها من خلال السؤال
لو مثلاً سؤال طلب كتابة Recursion Function لحساب الـFactorials
مثلاً، Factorial 4 عبارة عن 4*3*2*1 والناتج راح يكون 24
نقدر نستنتج أنه الفنكشن المفترض توقف تسوي كول لنفسها إذا الرقم وصل 0، لأن إذا الرقم وصل 0 وصار كول للفنكشن مرة ثانية
الناتج دائماً بيكون 0 مهما كان الرقم.


ايضاً، من خلال حساب الـFactorial نلاحظ أن الرقم كل مرة يكون أقل بـ1
فهذا اللي راح يصير إذا الفنكشن تسوي كول لنفسها


أول شي هذا الكود الخاص بحساب الـFactorials
PHP:
int Factorial(int num){
	if(num==0)
		return 1;
	else
		return num * Factorial(num-1);
}

لو مثلاً عندنا الرقم 4،، هذي الصورة توضح شاللي قاعد يصير بالضبط
ip9s36.jpg


ما تقصر يالغالي يعطيك العافية :)

بس شلون لو جابوا لينا recursion والفنكشن نفسها فيها pointer ؟
 
ابي حل النوتات اذا ممكن واذا ماعليكم امر اغلبيت الاسأله في الفاينيل من اي جبتر وشكراً
 
الله يخليكم اللي يعرف يحل هذي الريسيرسف ضروري :99:
Write a recursive function named computeSum that takes two integer parameters: x and y, where x < y. The function should return the summation of the numbers between x and y (including x and y). The prototype of the function is:
int computeSum(int x, int y);
Example (1): if x = 3 and y = 5, the function should return 12, i.e. 3+ 4+ 5.
Example (2): if x = 0 and y = 3, the function should return 6 , i.e. 0+ 1+ 2+ 3.
​

 
الله يخليكم اللي يعرف يحل هذي الريسيرسف ضروري :99:
Write a recursive function named computeSum that takes two integer parameters: x and y, where x < y. The function should return the summation of the numbers between x and y (including x and y). The prototype of the function is:
int computeSum(int x, int y);
Example (1): if x = 3 and y = 5, the function should return 12, i.e. 3+ 4+ 5.
Example (2): if x = 0 and y = 3, the function should return 6 , i.e. 0+ 1+ 2+ 3.
​



int computeSum(int x, int y);
if(x==y)
return x;
else;
return x+compute(x+1,y )
 
شباب ممكن سؤال
ويش الفرق بين
int*ptr= new int[size]
و
int *ptr[size]
 
int computeSum(int x, int y);
if(x==y)
return x;
else;
return x+compute(x+1,y )
شكرا على الرد:smile:

إذا تقدر حل لي هذي:rolleyes2:
Write a​
[FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]recursive [/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]function to implement the [FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Sequential (linear) Search [/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]Algorithm. The fnction should take as paramaters: an array of integers ([FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Array)[/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT], an integer value ([FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Key[/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]), and two integers ([FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]First [/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]and [FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Last[/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]) representing the first index and the last index of the array. The function should sequentially search and return the position of the first occurrence of [FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Key [/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]in the array. If [FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]Key [/FONT][/FONT][FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]does not exist in the array, the function should return -1. The function protoype is:
[FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]​
int LinearSearch(int Array[ ], int Key, int First, int Last);
[/FONT]
[/FONT]
[FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman][/FONT][/FONT]
 
nt computeSum(int x, int y);
if(x==y)
return x;
else;
return x+compute(x+1,y )

فيها اخطاء بسيطه Syntax
التعديل
PHP:
int computeSum(int x, int y){
if(x==y)
return x;
else;
return x+compute(x+1,y ) ;

}
 
شباب متأكدين كلشئ داخل ؟ حتي مال test1 !!

اعتقد مو كومبرهنسف .. بس 3 جباتر إلي اعرفه بس لاتزهقونا ويش هست .. ويش الحين كلشئ داخل ولا شلون ؟
 
شباب متأكدين كلشئ داخل ؟ حتي مال test1 !!

اعتقد مو كومبرهنسف .. بس 3 جباتر إلي اعرفه بس لاتزهقونا ويش هست .. ويش الحين كلشئ داخل ولا شلون ؟

كل شي داخل من جبتر 9 الى الركيجن اخر شي
 
شباب ممكن سؤال
ويش الفرق بين
int*ptr= new int[size]
و
int *ptr[size]

PHP:
int*ptr= new int[size]

معناته بوينتر يؤشر على array وبتكون Dynamic بـ عدد معين من size

الثانيه
معناته array بعدد معين وكل اندكس من هالarray هو بيونتر
 
recursive function to implement the Sequential (linear) Search Algorithm. The fnction should take as paramaters: an array of integers (Array), an integer value (Key), and two integers (First and Last) representing the first index and the last index of the array. The function should sequentially search and return the position of the first occurrence of Key in the array. If Key does not exist in the array, the function should return -1. The function protoype is:
​
int LinearSearch(int Array[ ], int Key, int First, int Last


الحل
PHP:
int  LinearSearch(int array[],int key,int first,int last){
if (first>last)
return -1;
else {
if(array[first]==key)
return first;
return  LinearSearch(array,key,first+1,last);
}
}

نسألكم الدعاء
 
عودة
أعلى أسفل