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

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

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

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

الحين نحط بوينتر اولا؟؟

لانه حلته ويانا الدكتورة هالسؤال بدون بوينتر بس الاول ؟؟
 
السؤال حلته ويانه دكتوره مياده فيصل
في السكشن
 
الحين نحط بوينتر اولا؟؟

لانه حلته ويانا الدكتورة هالسؤال بدون بوينتر بس الاول ؟؟

اذا ماعليش امر حطي لنا الحل ..

لان اني حليته غيـــــر ابغي اتاكد :blushing:
​
 
مثل الحل اللي حطيته

بس الفور عقب الفورلوب الاولية قبل السايز مانحط بوينتر؟
 
نرجع نحل بقية الأسئلة
Question 4 (24 Points)
Consider the class TList given below:
class TList
{
private:
int * dynamicArr; //Pointer to a dynamic Array
int MaxSize; // Maximum Size of the dynamic array
int arrSize; // Actual Size of the dynamic array
public:
TList (int MaximumSize = 30);
void insertLast(int item) // Inserts item as the last
element in dynamicArr and increments arrSize
~ TList ();
}; // end class TList
(Part A) [6 Points]
Rewrite the above class as a template class so that it becomes a List of any type T (not just of
integers).
(

الحل
PHP:
template<class t>
class TList
{
private:
t * dynamicArr; 
int MaxSize; 
int arrSize; 
public:
TList (int MaximumSize = 30);
void insertLast(t item);
~ TList ();
};

Write the implementation of the constructor function that initializes MaxSize to the value of
the parameter MaximumSize, initializes ArrSize to 0 and creates the
dynamic array dynamicArr of the given MaxSize.

PHP:
template<class t>
Tlist<t>::Tlist(int MaximumSize)
{ MaxSize=MaximumSize;
arrSize=0;
dynamicArr=new t[MaxSize];
}

Write the implementation of the destructor function

PHP:
template<class t>
Tlist<t>::~ Tlist()
{ delete[]dynamicArr;
dynamicArr=NULL;
}

Write the implementation of the insertLast function that receives an item of any type and
inserts it as the last element of the array dynamicArr and increments the
actual size of the array. The function should check first to
make sure that the actual size of the array will not exceed
the maximum size allowed.

PHP:
template<class t>
void Tlist<t>::insertLast(t item)
{ 
	if(arrSize<MaxSize)
      { dynamicArr[arrSize]=item;
        arrSize++;
      }
}
 
non-member

ممكن تعطوني سؤال عنه مع الحل ؟

لانه ماحضرت هالدرس
 
^^
الحين بحل سؤال فيه عن member و non member
 
ماث لوفر..

الشرح مال اول سؤال الاوت بوت ياريت تكبرينه
او بشنو عوضنا ب n
 
اي سوري بس لانه من التيلفون مصورتنه فصايره الصورة صغيرة كبرتها بس بعد تطلع صغيرة

مشكورة أختي تعبتش معاي بس تقدرين تشرحين ليي شلون انسوي
هالطريقة ans= Recoutput(n, k-1) - n[k-1]; وبس ما يبين الخط لانه
 
Consider the class TDate given below:
class TDate
{
private:
int Day; // 1-30 only
int Month; // 1-12 only
int Year;
public:
TDate(int D = 1, int M = 1, int Y = 1900);
Print(); //Prints the date in dd/mm/yyyy format;
……
}; // end class TDate
(Part A)
Overload the operator < (less than) as a member function of the class TDate, so that :
D1 < D2 will return true if the if the Date D1 is before the date D2.
Note that D1 is before D2 if the year of D1 is less then year of D2 or
If years are the same but the month of D1 is less then month of D2
Or if the months and years are the same but Day of D1 is less then Day
of D2
Otherwise, it returns false.

الحل
PHP:
bool TDate::operator<(const TDate& obj)const
{
	if(year<obj.year)
		return true;
	else if (year==obj.year && month<obj.month)
		return true;
	else if (year==obj.year && month==obj.month && day<obj.day)
		return true;
	else
		return false;
}

(Part B)
Overload the = operator (equal) as a non-member function of the class TDate, so that :
L1 == L2 will return true if the Dates D1 and D2 are the same.
Otherwise, it returns false.

PHP:
bool operator==(const TDate& obj1,const TDate& obj2)
{
	return(obj1.year==obj2.year && obj1.month==obj2.month && obj1.day==obj2.day)
}

Question (5) Continue
(Part C)
Write a main function that declares two dates: (Example D1 as12/12//1998 and D2 as
25/1/1999) And prints one of the following messages as appropriate:
D1 = dd/mm/yyyy is before D2 = dd/mm/yyyy
D1 = dd/mm/yyyy is the same as D2 = dd/mm/yyyy
D1 = dd/mm/yyyy is after D2 = dd/mm/yyyy

PHP:
int main()
{
	TDate D1(12,12,1998);
	TDate D2(25,1,1999);

	if(D1<D2)
		cout<<"D1="<<D1.print()<<"is before D2="<<D2.print();
	else if (D1==D2)
		cout<<"D1="<<D1.print()<<"is the same as D2="<<D2.print();
	else
		cout<<"D1="<<D1.print()<<"is after D2="<<D2.print();
}
 
هذي الصورة من جديد
387740834.jpg
 
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.”

الحل
PHP:
int Rightdigit(int n, int k)
{
	if(k==0)
		return (n%10);
	else
	{
		n=(n/10);
		return Rightdigit(n,k-1);
	}
}
 
^^
العفو
حاضرين
 
شوفوا آخر سؤال حليته عن الركيرجن بعد
 
Consider the class TDate given below:
class TDate
{
private:
int Day; // 1-30 only
int Month; // 1-12 only
int Year;
public:
TDate(int D = 1, int M = 1, int Y = 1900);
Print(); //Prints the date in dd/mm/yyyy format;
……
}; // end class TDate
(Part A)
Overload the operator < (less than) as a member function of the class TDate, so that :
D1 < D2 will return true if the if the Date D1 is before the date D2.
Note that D1 is before D2 if the year of D1 is less then year of D2 or
If years are the same but the month of D1 is less then month of D2
Or if the months and years are the same but Day of D1 is less then Day
of D2
Otherwise, it returns false.

الحل
PHP:
bool TDate::operator<(const TDate& obj)const
{
	if(year<obj.year)
		return true;
	else if (year==obj.year && month<obj.month)
		return true;
	else if (year==obj.year && month==obj.month && day<obj.day)
		return true;
	else
		return false;
}

(Part B)
Overload the = operator (equal) as a non-member function of the class TDate, so that :
L1 == L2 will return true if the Dates D1 and D2 are the same.
Otherwise, it returns false.

PHP:
bool operator==(const TDate& obj1,const TDate& obj2)
{
	return(obj1.year==obj2.year && obj1.month==obj2.month && obj1.day==obj2.day)
}

Question (5) Continue
(Part C)
Write a main function that declares two dates: (Example D1 as12/12//1998 and D2 as
25/1/1999) And prints one of the following messages as appropriate:
D1 = dd/mm/yyyy is before D2 = dd/mm/yyyy
D1 = dd/mm/yyyy is the same as D2 = dd/mm/yyyy
D1 = dd/mm/yyyy is after D2 = dd/mm/yyyy

PHP:
int main()
{
	TDate D1(12,12,1998);
	TDate D2(25,1,1999);

	if(D1<D2)
		cout<<"D1="<<D1.print()<<"is before D2="<<D2.print();
	else if (D1==D2)
		cout<<"D1="<<D1.print()<<"is the same as D2="<<D2.print();
	else
		cout<<"D1="<<D1.print()<<"is after D2="<<D2.print();
}

سؤال ليش حاطه bool في الفنكشن
 
لان الفنكشن وظيفتها تقارن وتطلع لينا ترو اور فولس
 
عودة
أعلى أسفل