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

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

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

ITCS215 للفصل الدراسي الأول 2015 - 2016

السلام عليكم و رحمة الله و بركاته

تم فتح هذا الموضوع لمناقشة مقرر ITCS215

قسم المقرر في المكتبة الجامعية
https://www.uob-bh.com/forum/downloads.php?do=cat&id=5

لأي استفسارات أو مساعدة تتعلق بالمقرر الرجاء طرحها هنا

بالتوفيق للجميع :smile2:
 
السلام عليكم
يا جماعة شلون ادرس لجبتر 3 و5 احسة كله حفظ ؟
 
السلام عليكم
يا جماعة شلون ادرس لجبتر 3 و5 احسة كله حفظ ؟
عليكم السلام
لا مو حفظ فهم :smile2: أخوي حل أسئلة التيتوريلات الي عندك تقريباً الافكار بين تيتوريل اللنكد لست و الاري باسد لست مثل الشي الفرق شلون تحل بهذا و شلون تحل بهذا و ركز في الاسئلة على سالفة ان الفنكشن member function أو non-member function لان ناس واجد يغلطون في هالسالفة و تروح من عندهم درجات مع انهم يعرفون الجواب اذا ما عندك التيتوريلات تقدر تنزلهم من الرابط الي تحت و اذا عندك اي اسئلة أو إستفسار بخصوص اسئلة التيتوريل او المقرر نفسه تقدر تكتبه في الموضوع و إن شاء الله نقدر نساعدك و جرب تستخدم الفنكشن في الكومبايلر عشان تعرف وين أغلاطك بيفيدك هذا الشي في الإمتحان واجد .
رابط التيتوريلات :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5369
رابط ADT Data Structures في حال حبيت تجرب الفنكشنات بحيث انك ما تكتبه مجرد تكتب الفنكشن و تجربها :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5008
الرابط السابق لل ADT ينقصه ال Array Based List تقدر تحمله من أهني :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5372
 
عليكم السلام
لا مو حفظ فهم :smile2: أخوي حل أسئلة التيتوريلات الي عندك تقريباً الافكار بين تيتوريل اللنكد لست و الاري باسد لست مثل الشي الفرق شلون تحل بهذا و شلون تحل بهذا و ركز في الاسئلة على سالفة ان الفنكشن member function أو non-member function لان ناس واجد يغلطون في هالسالفة و تروح من عندهم درجات مع انهم يعرفون الجواب اذا ما عندك التيتوريلات تقدر تنزلهم من الرابط الي تحت و اذا عندك اي اسئلة أو إستفسار بخصوص اسئلة التيتوريل او المقرر نفسه تقدر تكتبه في الموضوع و إن شاء الله نقدر نساعدك و جرب تستخدم الفنكشن في الكومبايلر عشان تعرف وين أغلاطك بيفيدك هذا الشي في الإمتحان واجد .
رابط التيتوريلات :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5369
رابط ADT Data Structures في حال حبيت تجرب الفنكشنات بحيث انك ما تكتبه مجرد تكتب الفنكشن و تجربها :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5008
الرابط السابق لل ADT ينقصه ال Array Based List تقدر تحمله من أهني :
https://www.uob-bh.com/forum/downloads.php?do=file&id=5372


اخوي ممكن توضح لي الفرق بين member function أو non-member function
 
اخوي ممكن توضح لي الفرق بين member function أو non-member function
الفرق بين ال member function و ال non-member function ، الممبير فنكشن هي وحدة من فنكشنات لكلاس نفسه على سبيل المثال في ال array based list ال insert end هي member function بينما لو سوينا فنكشن احد البرميتر مالها نوع array based list فهاذي non-member فنكشن لانها مو فنكشن من لكلاسس مال ال array based list فقط احد البراميترات الموجودة في الفنكشن نوعه array based list ، إضافة الى هذا الشي ال member function نقدر نستخدمها داخل فنكشن ممبر ثانية ما نكرر الكود مالها مجرد نكتب لبروتوتايب مالها بدون اضافة اسمبرميت و دوت للفنكشن بينما ال non-member function ما نقدر نسوي فيها هذا الشي على سبيل المثال شوف فنكشن الميرج لس و الدليت فاليوس الي بعدها هدلين نون ممبر في التيتوريل :
https://drive.google.com/file/d/0By6IydPqj2WASktCaGVqSktJWXc/view?usp=sharing
عذراً على الشرح المختصر إنشاء الله بكره بوضح الموضوع أكثر بأمثلة للممبر فنكشن و النون ممبر فنكشن
 
مشكور اخوي ما قصرت
العفو و عذراً على التأخير
مثال لل member function
كود:
template<class elemType>
void arrayListType<elemType>::removeAll(const elemType& removeItem)
{       
    int loc;
    if(length == 0)
        cout<<"Cannot remove from an empty list"<<endl;
    else
    {
        loc = seqSearch(removeItem);
        if(loc == -1)
            cout<<"The item to be deleted is not in the list."<<endl;
        while(loc != -1)
        {
            removeAt(loc);        
            loc = seqSearch(removeItem);
        }
    }
}
مثال لل non-member function
كود:
void oddEven(const arrayListType<Type>&list1 , arrayListType<Type>&list2 , arrayListType<Type>&list3 ){
     if ( list1.isEmpty() ) 
     cerr << " The main List is Empty " << endl ; 
     else { 
          list2.clearList(); 
          list3.clearList();
          int item ; 
          for ( int i = 0 ; i < list1.listSize() ; i ){
              item=list1.retrieveAt(i,15);
              if ( item%2==0){
              list2.insertEnd(item);
              }
              else{
              list3.insertEnd(item);
                   }
              }
          }
          list1.print();
          list2.print();
          list3.print();
          }
ملاحظة : هاذي الفنكشن فيها خطاأ مو صحيحة 100% فقط لتوضيح الفكرة
لاحظ لبروتوتايب لكل فنكشن منهم بتشوف ان ال member function قبل اسم الفنكشن مكتوب
كود:
arraylIstType<Type>::
بروتاتايب ال member function :
كود:
void arrayListType<elemType>::removeAll(const elemType& removeItem);
بينما في ال non-member function هذا الشي مو موجود ووجده يعتبر خطأ
بالإضافة الى هذا طالع محتوى الفنكشنين
ال member function
كود:
    int loc;
    if(length == 0)
        cout<<"Cannot remove from an empty list"<<endl;
    else
    {
        loc = seqSearch(removeItem);
        if(loc == -1)
            cout<<"The item to be deleted is not in the list."<<endl;
        while(loc != -1)
        {
            [COLOR=#ff0000]removeAt(loc);        [/COLOR]
            loc = seqSearch(removeItem);
        }
    }
لاحظ ان أحنا ما ربطنا الفنكشن remove at بأوبجت
بينما في ال non-member فنكشن
كود:
void oddEven(const arrayListType<Type>&list1 , arrayListType<Type>&list2 , arrayListType<Type>&list3 ){
     if ( list1.isEmpty() ) 
     cerr << " The main List is Empty " << endl ; 
     else { 
[COLOR=#ff0000]          list2.clearList(); [/COLOR]
[COLOR=#ff0000]          list3.clearList();[/COLOR]
          int item ; 
          for ( int i = 0 ; i < [COLOR=#ff0000]list1.listSize()[/COLOR] ; i ){
[COLOR=#000000]item[/COLOR][COLOR=#ff0000][/COLOR]=[COLOR=#ff0000]list1.retrieveAt(i,15);[/COLOR]
              if ( item%2==0){
[COLOR=#ff0000]              list2.insertEnd(item);[/COLOR]
              }
              else{
[COLOR=#ff0000]              list3.insertEnd(item);[/COLOR]
                   }
              }
          }
          list1.print();
          list2.print();
          list3.print();
          }
بينما في ال non-member function نشوف ان احنا ما نقدر نستخدمها مثل ال member function الا اذا ربطنها بأوبجت من نوع ال data structure نفسها سواءاً كانت arrayListType أو linkedList أو باقي ال data structures .

كملاحظة أخيرة للإمتحان أقرأ السؤال بصورة صحيحة و بدون إستعجال ، لانه أحيانا يطلب member function بس في نفس الوقت يكون حاط ملاحظة في السؤال ان الفنكشن ما تقدر تستخدم فيها فنكشنات الداتا ستركجر بشكل مباشر فلازم تكتب الفنكشن بمعرفتك بطريقة عمل أكود الفنكشنات على سبيل المثال هذا السؤال من إمتحان سابق شوف صفحة 5 من الملف السؤال الثالث اللنكد لست بتشوف انه حاط ملاحظة بهذا الشي في حال ترك لك حرية الاختيار الافضل تستخدمهم عشان تتجنب تضييع الوقت في كتابة الكود و في نفس الوقت تتجنب بعض الأخطاء الي ممكن تصير اثناء كتابة الكود:
https://www.uob-bh.com/forum/downloads.php?do=file&id=4371
 
التعديل الأخير:
cs 215

ممكن مساعده في هذا السؤال

Write a function that will accept an integer in base 10 (decimal) as a parameter the function should print the binary equivalent of this number.


  • Write a main program that will test the above mentioned function.
  • Use a stack to solve the question.
  • Don’t use recursion.


template<class Type>
void stackType<Type>::printbinary(int x )
{
stackType<Type> *s;
if(x > 0)
{
while( x%2 ==0 || x %2 == 1)
x=x/2 ;
s.push(x);
s.pop(x);


}


}




وويش نكتب فالمين :mellow:
 
التعديل الأخير:
ممكن مساعده في هذا السؤال

Write a function that will accept an integer in base 10 (decimal) as a parameter the function should print the binary equivalent of this number.


  • Write a main program that will test the above mentioned function.
  • Use a stack to solve the question.
  • Don’t use recursion.


template<class Type>
void stackType<Type>::printbinary(int x )
{
stackType<Type> *s;
if(x > 0)
{
while( x%2 ==0 || x %2 == 1)
x=x/2 ;
s.push(x);
s.pop(x);


}


}




وويش نكتب فالمين :mellow:
السلام عليكم أختي في بعض الأخطاء في الفنكشن :

الخطأ الأول :
كود:
[RIGHT][COLOR=#333333]stackType<Type> *s;[/COLOR][/RIGHT]
انتين تتعاملين مع member function للستاك فما تحتاجين تعرفين برميتر ثاني من نوع ستاك تايب ، بالإضافة الى هذا الشي كتابة المتغير s كأنش تتعاملين مع لنكد لست ستاك و هذا غلط ، المفروض ينكتب جدي ( كمعلومة فقط ) :
كود:
[RIGHT][COLOR=#333333]stackType<Type> s;[/COLOR][/RIGHT]

الخطأ الثاني :
كود:
[RIGHT][COLOR=#333333]while( x%2 ==0 || x %2 == 1)[/COLOR][/RIGHT]
شرط الوايل لوب انه اذا ريمندر الأكس موديلس 2 يساوي 1 أو 0 ما يوقف اللوب ، في البداية بيكون الريمندر متنوع 0 أو 1 حسب قيمة ال x المدخلة بس بعدين بكون على طول 0 فاللوب ما راح يوقف ( انفنت لوب ) ، فلازم نستخدم النمبرنق سستم ماله 103 فلو حولنا من ديسمل الى باينري بكون اخر رقم هو 1 لل x فلنحلي شرط الوايل لوب انه اذا صارت قيمة الأكس واحد يوقف اللوب بهاذي الطريقة :
كود:
while(x!=1);

الخطأ الثالث :
العملية داخل الوايل لوب خاطئة لعدة اسباب :
كود:
x=x/2 ;
s.push(x);
s.pop(x);
في هاذي الخطوات احنا نقسم ال x على 2 و بعدها ننقلها لستاك داخل اللوب نفرض ان ال x تساوي 12 ، 2/12= 6 ؟؟؟ هل من ضمن دجت الباينري في 6 ؟ فقط 0 و 1 ، فالإجابة بتطلع غلط الرقم الي بيطلع مو باينري ، بالإضافة الى هذا الشي فنكشن البوب pop ما فيها اي برميتر و المفروض ما تعرفين متغير نوع ستاك تايب داخل الفنكشن لانها ممبر فنكشن الطريقة :
كود:
pop();
و ما نحتاجها في هاذي الخطوة داخل هذا اللوب ، نحتاج نعرف متغير انتجر جديد في بداية لستاك بحيث نخزن فيه ريمندر الأكس و نسوي له بوش ( push ) داخل لستاك :
كود:
while(x!=1){
		item = x % 2 ; 
		x = x / 2 ;
		push(item);
	}
ما خلصنا بعد في خطأ ، أحنا وقفنا الوايل لوب لما ال x صارت 1 ، فأخر جزء من رقم الباينري بكون مفقود الحل ببساطة نرجع نسوي بوش للأكس داخل لستاك :
كود:
push(x);
حسب طبيعة لستاك في البوش و البوب فحالياً الرقم بالباينري صاير بالمقلوب الحل ببساطة أن احنا نسوي وايل لوب ثاني يعكس لستاك و يعطينا النتيجة النهائية للرقم بالباينري بهاذي الطريقة :
كود:
while(!isEmptyStack()){
	 x = top();
	 cout << x ;
	 pop();
	}
بحيث ان ال x بتساوي اخر رقم في لستاك الي هو ال top و بنطبعها بعدها بنحذفها و بتصير قيمة ال x الرقم الي بعده و هكذا لين يصير لستاك امت فبنحصل على الرقم بالباينري

نجي للمين :
المين ببساط بتعرفين برميتر من نوع ستاك تايب ، و بتطلعين رسالة في الشاشة للمستخدم بحيث انه يدخل رقم ما بالأنتجر ، بعد خذا الشي بتسوين كول للفنكشن بهاذي الطريقة :
كود:
stackType<int> list ; 
	int x ;
	cout << " Enter the Decimal Number to convert it to binary : " ; 
	cin >> x ;
	list.printBinary(x);

في النهاية الفنكشن بتكون بهاذي الطريقة :
كود:
template<class Type>
void stackType<Type>::printBinary(int x){
	stackType<Type> s1 ;
	int item;
	if(x>0){
	destroyStack();
	while(x!=1){
		item = x % 2 ; 
		x = x / 2 ;
		push(item);
	}
	push(x);
	while(!isEmptyStack()){
	 x = s1.top();
	 cout << x ;
	 s1.pop();
	}
	}
	else{
		cout << 0 << endl ; 
	}


}
و المين بهاذي الطريقة :
كود:
void main(){ 
	stackType<int> list ; 
	int x ;
	cout << " Enter the Decimal Number to convert it to binary : " ; 
	cin >> x ;
	list.printBinary(x);
	
}
و اذا في اي سؤال تقدرين تسألين :smile2:
 
السلام عليكم أختي في بعض الأخطاء في الفنكشن :

الخطأ الأول :
كود:
[RIGHT][COLOR=#333333]stackType<Type> *s;[/COLOR][/RIGHT]
انتين تتعاملين مع member function للستاك فما تحتاجين تعرفين برميتر ثاني من نوع ستاك تايب ، بالإضافة الى هذا الشي كتابة المتغير s كأنش تتعاملين مع لنكد لست ستاك و هذا غلط ، المفروض ينكتب جدي ( كمعلومة فقط ) :
كود:
[RIGHT][COLOR=#333333]stackType<Type> s;[/COLOR][/RIGHT]

الخطأ الثاني :
كود:
[RIGHT][COLOR=#333333]while( x%2 ==0 || x %2 == 1)[/COLOR][/RIGHT]
شرط الوايل لوب انه اذا ريمندر الأكس موديلس 2 يساوي 1 أو 0 ما يوقف اللوب ، في البداية بيكون الريمندر متنوع 0 أو 1 حسب قيمة ال x المدخلة بس بعدين بكون على طول 0 فاللوب ما راح يوقف ( انفنت لوب ) ، فلازم نستخدم النمبرنق سستم ماله 103 فلو حولنا من ديسمل الى باينري بكون اخر رقم هو 1 لل x فلنحلي شرط الوايل لوب انه اذا صارت قيمة الأكس واحد يوقف اللوب بهاذي الطريقة :
كود:
while(x!=1);

الخطأ الثالث :
العملية داخل الوايل لوب خاطئة لعدة اسباب :
كود:
x=x/2 ;
s.push(x);
s.pop(x);
في هاذي الخطوات احنا نقسم ال x على 2 و بعدها ننقلها لستاك داخل اللوب نفرض ان ال x تساوي 12 ، 2/12= 6 ؟؟؟ هل من ضمن دجت الباينري في 6 ؟ فقط 0 و 1 ، فالإجابة بتطلع غلط الرقم الي بيطلع مو باينري ، بالإضافة الى هذا الشي فنكشن البوب pop ما فيها اي برميتر و المفروض ما تعرفين متغير نوع ستاك تايب داخل الفنكشن لانها ممبر فنكشن الطريقة :
كود:
pop();
و ما نحتاجها في هاذي الخطوة داخل هذا اللوب ، نحتاج نعرف متغير انتجر جديد في بداية لستاك بحيث نخزن فيه ريمندر الأكس و نسوي له بوش ( push ) داخل لستاك :
كود:
while(x!=1){
        item = x % 2 ; 
        x = x / 2 ;
        push(item);
    }
ما خلصنا بعد في خطأ ، أحنا وقفنا الوايل لوب لما ال x صارت 1 ، فأخر جزء من رقم الباينري بكون مفقود الحل ببساطة نرجع نسوي بوش للأكس داخل لستاك :
كود:
push(x);
حسب طبيعة لستاك في البوش و البوب فحالياً الرقم بالباينري صاير بالمقلوب الحل ببساطة أن احنا نسوي وايل لوب ثاني يعكس لستاك و يعطينا النتيجة النهائية للرقم بالباينري بهاذي الطريقة :
كود:
while(!isEmptyStack()){
     x = top();
     cout << x ;
     pop();
    }
بحيث ان ال x بتساوي اخر رقم في لستاك الي هو ال top و بنطبعها بعدها بنحذفها و بتصير قيمة ال x الرقم الي بعده و هكذا لين يصير لستاك امت فبنحصل على الرقم بالباينري

نجي للمين :
المين ببساط بتعرفين برميتر من نوع ستاك تايب ، و بتطلعين رسالة في الشاشة للمستخدم بحيث انه يدخل رقم ما بالأنتجر ، بعد خذا الشي بتسوين كول للفنكشن بهاذي الطريقة :
كود:
stackType<int> list ; 
    int x ;
    cout << " Enter the Decimal Number to convert it to binary : " ; 
    cin >> x ;
    list.printBinary(x);

في النهاية الفنكشن بتكون بهاذي الطريقة :
كود:
template<class Type>
void stackType<Type>::printBinary(int x){
    stackType<Type> s1 ;
    int item;
    if(x>0){
    destroyStack();
    while(x!=1){
        item = x % 2 ; 
        x = x / 2 ;
        push(item);
    }
    push(x);
    while(!isEmptyStack()){
     x = s1.top();
     cout << x ;
     s1.pop();
    }
    }
    else{
        cout << 0 << endl ; 
    }


}
و المين بهاذي الطريقة :
كود:
void main(){ 
    stackType<int> list ; 
    int x ;
    cout << " Enter the Decimal Number to convert it to binary : " ; 
    cin >> x ;
    list.printBinary(x);
    
}
و اذا في اي سؤال تقدرين تسألين :smile2:



ششكرا جزيلا :RpS_love::RpS_love::RpS_love:

جربت البرنامج يطلع ليي ايرور في( if(x>0

سويت جدي اتوقع لازم نستخدم التوب له ؟


int item,x;
stackType<Type> s;
while(top()!= 0)
{ item = top() % 2 ;
x = top() / 2 ;
s.push(item);
push(x);
}
 
ششكرا جزيلا :RpS_love::RpS_love::RpS_love:

جربت البرنامج يطلع ليي ايرور في( if(x>0

سويت جدي اتوقع لازم نستخدم التوب له ؟


int item,x;
stackType<Type> s;
while(top()!= 0)
{ item = top() % 2 ;
x = top() / 2 ;
s.push(item);
push(x);
}
عفواً :smile2:
لا أختي الجواب مثل ما كتبته أنا بالإضافة الى هذا الشي الفنكشن فيها شي ماله داعي كتبته و نسيت امسحه الي هو :
كود:
stackType<Type> s1 ;
وجوده ماله معنى مجرد خطأ بسبب السرعة في الكتابة :nosweat: بالإضافة الفنكشن ممبر فنكشن فما نحتاج نعرف برميتر من نوع ستاك تايب ، الفنكشن شغالة شخصياً جربتها و تشتغل صح حتى بوجود الجزء الي ماله داعي الي ذكرته ، أتوقع في سنتكس ايرور من ناحية سميكولن أو بركت في مكان ما من الكود الي عندش :smile2: هذا تجربتي للكود اثناء وجود الجزء المذكور :
https://drive.google.com/file/d/0By6IydPqj2WAZFZ3UWNCdjlqdmc/view?usp=sharing
و هذا بعد الحذف :
https://drive.google.com/file/d/0By6IydPqj2WAb0JTVzdlQUQtUk0/view?usp=sharing
الكود المستخدم :
كود:
#include<iostream>
#include<cassert>
using namespace std; 


template<class Type>
class stackType
{
public:
const stackType<Type>& operator=(const stackType<Type>&); 
//Overload the assignment operator.
void initializeStack();
//Function to initialize the stack to an empty state.
//Postcondition: stackTop = 0
bool isEmptyStack();
//Function to determine whether the stack is empty.
//Postcondition: Returns true if the stack is empty;
// otherwise, returns false.
bool isFullStack();
//Function to determine whether the stack is full.
//Postcondition: Returns true if the stack is full;
// otherwise, returns false.
void destroyStack();
//Function to remove all the elements from the stack.
//Postcondition: stackTop = 0




void push(const Type& newItem);
//Function to add newItem to the stack.
//Precondition: The stack exists and is not full.
//Postcondition: The stack is changed and newItem 
// is added to the top of stack.
Type top();
//Function to return the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: If the stack is empty, the program 
// terminates; otherwise, the top element 
// of the stack is returned.
void pop();
//Function to remove the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: The stack is changed and the top 
// element is removed from the stack.




stackType(int stackSize = 100); 
//constructor
//Creates an array of the size stackSize to hold the 
//stack elements. The default stack size is 100.
//Postcondition: The variable list contains the base
// address of the array, stackTop = 0, and 
// maxStackSize = stackSize.
stackType(const stackType<Type>& otherStack); 
//copy constructor
~stackType(); 
//destructor
//Removes all the elements from the stack.
//Postcondition: The array (list) holding the stack 
// elements is deleted.
void integerNumber(int x);


void printBinary(int x); 


private:
int maxStackSize; //variable to store the maximum stack size
int stackTop;	 //variable to point to the top of the stack
Type *list; //pointer to the array that holds the
//stack elements




void copyStack(const stackType<Type>& otherStack); 
//Function to make a copy of otherStack.
//Postcondition: A copy of otherStack is created and
// assigned to this stack.
};








template<class Type>
void stackType<Type>::initializeStack()
{
stackTop = 0;
}//end initializeStack




template<class Type>
void stackType<Type>::destroyStack()
{
stackTop = 0;
}//end destroyStack




template<class Type>
bool stackType<Type>::isEmptyStack()
{
return(stackTop == 0);
}//end isEmptyStack




template<class Type>
bool stackType<Type>::isFullStack()
{
return(stackTop == maxStackSize);
} //end isFullStack




template<class Type>
void stackType<Type>::push(const Type& newItem)
{
if(!isFullStack())
{
list[stackTop] = newItem; //add newItem at the 
//top of the stack
stackTop++; //increment stackTop
}
else
cerr<<"Cannot add to a full stack."<<endl;
}//end push




template<class Type>
Type stackType<Type>::top()
{
assert(stackTop != 0); //if stack is empty, 
//terminate the program
return list[stackTop - 1];	 //return the element of the 
//stack indicated by 
//stackTop - 1
}//end top




template<class Type>
void stackType<Type>::pop()
{
if(!isEmptyStack())
stackTop--; //decrement stackTop 
else
cerr<<"Cannot remove from an empty stack."<<endl;
}//end pop




template<class Type>
stackType<Type>::stackType(int stackSize) 
{
if(stackSize <= 0)
{
cerr<<"Size of the array to hold the stack must "
<<"be positive."<<endl;
cerr<<"Creating an array of size 100."<<endl;




maxStackSize = 100;
}
else
maxStackSize = stackSize; //set the stack size to 
//the value specified by 
//the parameter stackSize




stackTop = 0;	 //set stackTop to 0
list = new Type[maxStackSize]; //create the array to
//hold the stack elements
assert(list != NULL);
}//end constructor




template<class Type>
stackType<Type>::~stackType() //destructor
{
delete [] list; //deallocate memory occupied by the array
}//end destructor




template<class Type>
void stackType<Type>::copyStack(const stackType<Type>& otherStack)
{ 




delete [] list;	
maxStackSize = otherStack.maxStackSize;	
stackTop = otherStack.stackTop;	


list = new Type[maxStackSize];	
assert(list != NULL);	




//copy otherStack into this stack
for(int j = 0; j < stackTop; j++) 
list[j] = otherStack.list[j];
} //end copyStack








template<class Type>
stackType<Type>::stackType(const stackType<Type>& otherStack)
{
list = NULL;




copyStack(otherStack);
}//end copy constructor




template<class Type>
const stackType<Type>& stackType<Type>::operator=
(const stackType<Type>& otherStack)
{ 




if(this != &otherStack) //avoid self-copy
copyStack(otherStack);




return *this; 


} //end operator= 


template<class Type>
void stackType<Type>::printBinary(int x){
	int item;
	if(x>0)
    destroyStack();
	while(x!=1){
		item = x % 2 ; 
		x = x / 2 ;
		push(item);
	}
	push(x);
	while(!isEmptyStack()){
	 x = top();
	 cout << x ;
	pop();
	}
	cout << endl ;


}




void main(){ 
	stackType<int> list ; 
	int x ;
	cout << " Enter the Decimal Number to convert it to binary : " ; 
	cin >> x ;
	list.printBinary(x);
	
}
 
1. Define a binary search tree object bst of type bSearchTreeType. 2. Insert the following integers into bst: 100,40, 20, 15, 30, 40, 35, and 77. 3. Display the height of bst. 4. Display the number of nodes of bst. 5. Display the number of leaves of bst. 6. Display the nodes in Preorder, Inorder, and Postorder traversals. 7. Delete the nodes with the content 30 and 35. 8. Display the number of nodes of bst//Header File Binary Search Tree#ifndef H_binaryTree#define H_binaryTree#include using namespace std; //Definition of the nodetemplatestruct nodeType{ elemType info; nodeType *llink; nodeType *rlink;}; //Definition of the classtemplate class binaryTreeType{public: const binaryTreeType& operator= (const binaryTreeType&); //Overload the assignment operator. bool isEmpty(); //Function to determine if the binary tree is empty. //Postcondition: Returns true if the binary tree is empty; // otherwise, returns false. void inorderTraversal(); //Function to do an inorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the inorder sequence. void preorderTraversal(); //Function to do a preorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the preorder sequence. void postorderTraversal(); //Function to do a postorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the postorder sequence. void inorderTraversal(void (*visit) (elemType&)); //Function to do an inorder traversal of the binary tree. //The parameter visit, which is a function, specifies //the action to be taken at each node. int treeHeight(); //Function to deteremine the height of the binary tree. //Postcondition: The height of the binary tree is returned. int treeNodeCount(); //Function to determine the number of nodes in the //binary tree. //Postcondition: The number of nodes in the binary tree // is returned. int treeLeavesCount(); //Function to determine the number of leaves in the //binary tree. //Postcondition: The number of leaves in the binary tree // is returned. void destroyTree(); //Deallocates the memory space occupied by the binary tree. //Postcondition: root = NULL; binaryTreeType(const binaryTreeType& otherTree); //copy constructor binaryTreeType(); //default constructor ~binaryTreeType(); //destructorprotected: nodeType *root;private: void copyTree(nodeType* &copiedTreeRoot, nodeType* otherTreeRoot); //Function to make a copy of the binary tree to //which otherTreeRoot points. //Postcondition: The pointer copiedTreeRoot points to // the root of the copied binary tree. void destroy(nodeType* &p); //Function to destroy the binary tree to which p points. //Postcondition: The nodes of the binary tree to which // p points are deallocated. // p = NULL. void inorder(nodeType *p); //Function to do an inorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the inorder sequence. void preorder(nodeType *p); //Function to do a preorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the preorder sequence. void postorder(nodeType *p); //Function to do a postorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the postorder sequence. void inorder(nodeType *p, void (*visit) (elemType&)); //Function to do an inorder traversal of the binary //tree, starting at the node specified by the parameter p. //The parameter visit, which is a function, specifies the //action to be taken at each node. int height(nodeType *p); //Function to determine the height of the binary tree //to which p points. //Postcondition: The height of the binary tree to which p // points is returned. int max(int x, int y); //Function to determine the larger of x and y. //Postcondition: The larger of x and y is returned. int nodeCount(nodeType *p); //Function to determine the number of nodes in the binary //tree to which p points. //Postcondition: The number of nodes in the binary tree // to which p points is returned. int leavesCount(nodeType *p); //Function to determine the number of leaves in the binary //tree to which p points. //Postcondition: The number of nodes in the binary tree // to which p points is returned.};templateclass bSearchTreeType: public binaryTreeType{public:void insert(const elemType& insertItem); void deleteNode(const elemType& deleteItem);}; //Definition of member functionstemplatebinaryTreeType::binaryTreeType(){ root = NULL;}templatebool binaryTreeType::isEmpty(){ return (root == NULL);}templatevoid binaryTreeType::inorderTraversal(){ inorder(root);}templatevoid binaryTreeType::preorderTraversal(){ preorder(root);}templatevoid binaryTreeType::postorderTraversal(){ postorder(root);}templateint binaryTreeType::treeHeight(){ return height(root);}templateint binaryTreeType::treeNodeCount(){ return nodeCount(root);}templateint binaryTreeType::treeLeavesCount(){ return leavesCount(root);}template void binaryTreeType::copyTree (nodeType* &copiedTreeRoot, nodeType* otherTreeRoot){ if(otherTreeRoot == NULL) copiedTreeRoot = NULL; else { copiedTreeRoot = new nodeType; copiedTreeRoot->info = otherTreeRoot->info; copyTree(copiedTreeRoot->llink, otherTreeRoot->llink); copyTree(copiedTreeRoot->rlink, otherTreeRoot->rlink); }} //end copyTreetemplatevoid binaryTreeType::inorder(nodeType *p){ if(p != NULL) { inorder(p->llink); cout<
infollink); postorder(p->rlink); cout<
inforlink); delete p; p = NULL; }}template void binaryTreeType::destroyTree(){ destroy(root);} //copy constructortemplate binaryTreeType::binaryTreeType (const binaryTreeType& otherTree){ if(otherTree.root == NULL) //otherTree is empty root = NULL; else copyTree(root, otherTree.root);}template binaryTreeType::~binaryTreeType(){ destroy(root);}templateint binaryTreeType::height(nodeType *p){ if(p == NULL) return 0; else return 1 + max(height(p->llink), height(p->rlink));}templateint binaryTreeType::max(int x, int y){ if(x >= y) return x; else return y;}templateint binaryTreeType::nodeCount(nodeType *p){ coutinfo > insertItem)trailCurrent->llink = newNode;elsetrailCurrent->rlink = newNode;}templatevoid bSearchTreeType::deleteNode(const elemType& deleteItem){ nodeType *current; //pointer to traverse the tree nodeType *trailCurrent; //pointer behind current bool found = false; if(root == NULL) cerrllink; else current = current->rlink; } }//end while if(current == NULL) coutrlink); }//end if }}//end deleteNodevoid main();{ binaryTreeType n1; insert(100); insert(40); insert(20); insert(15); insert(30); insert(40); insert(35); insert(77); cout
 
1. Define a binary search tree object bst of type bSearchTreeType. 2. Insert the following integers into bst: 100,40, 20, 15, 30, 40, 35, and 77. 3. Display the height of bst. 4. Display the number of nodes of bst. 5. Display the number of leaves of bst. 6. Display the nodes in Preorder, Inorder, and Postorder traversals. 7. Delete the nodes with the content 30 and 35. 8. Display the number of nodes of bst//Header File Binary Search Tree#ifndef H_binaryTree#define H_binaryTree#include using namespace std; //Definition of the nodetemplatestruct nodeType{ elemType info; nodeType *llink; nodeType *rlink;}; //Definition of the classtemplate class binaryTreeType{public: const binaryTreeType& operator= (const binaryTreeType&); //Overload the assignment operator. bool isEmpty(); //Function to determine if the binary tree is empty. //Postcondition: Returns true if the binary tree is empty; // otherwise, returns false. void inorderTraversal(); //Function to do an inorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the inorder sequence. void preorderTraversal(); //Function to do a preorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the preorder sequence. void postorderTraversal(); //Function to do a postorder traversal of the binary tree. //Postcondition: The nodes of the binary tree are output // in the postorder sequence. void inorderTraversal(void (*visit) (elemType&)); //Function to do an inorder traversal of the binary tree. //The parameter visit, which is a function, specifies //the action to be taken at each node. int treeHeight(); //Function to deteremine the height of the binary tree. //Postcondition: The height of the binary tree is returned. int treeNodeCount(); //Function to determine the number of nodes in the //binary tree. //Postcondition: The number of nodes in the binary tree // is returned. int treeLeavesCount(); //Function to determine the number of leaves in the //binary tree. //Postcondition: The number of leaves in the binary tree // is returned. void destroyTree(); //Deallocates the memory space occupied by the binary tree. //Postcondition: root = NULL; binaryTreeType(const binaryTreeType& otherTree); //copy constructor binaryTreeType(); //default constructor ~binaryTreeType(); //destructorprotected: nodeType *root;private: void copyTree(nodeType* &copiedTreeRoot, nodeType* otherTreeRoot); //Function to make a copy of the binary tree to //which otherTreeRoot points. //Postcondition: The pointer copiedTreeRoot points to // the root of the copied binary tree. void destroy(nodeType* &p); //Function to destroy the binary tree to which p points. //Postcondition: The nodes of the binary tree to which // p points are deallocated. // p = NULL. void inorder(nodeType *p); //Function to do an inorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the inorder sequence. void preorder(nodeType *p); //Function to do a preorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the preorder sequence. void postorder(nodeType *p); //Function to do a postorder traversal of the binary //tree to which p points. //Postcondition: The nodes of the binary tree to which p // points are output in the postorder sequence. void inorder(nodeType *p, void (*visit) (elemType&)); //Function to do an inorder traversal of the binary //tree, starting at the node specified by the parameter p. //The parameter visit, which is a function, specifies the //action to be taken at each node. int height(nodeType *p); //Function to determine the height of the binary tree //to which p points. //Postcondition: The height of the binary tree to which p // points is returned. int max(int x, int y); //Function to determine the larger of x and y. //Postcondition: The larger of x and y is returned. int nodeCount(nodeType *p); //Function to determine the number of nodes in the binary //tree to which p points. //Postcondition: The number of nodes in the binary tree // to which p points is returned. int leavesCount(nodeType *p); //Function to determine the number of leaves in the binary //tree to which p points. //Postcondition: The number of nodes in the binary tree // to which p points is returned.};templateclass bSearchTreeType: public binaryTreeType{public:void insert(const elemType& insertItem); void deleteNode(const elemType& deleteItem);}; //Definition of member functionstemplatebinaryTreeType::binaryTreeType(){ root = NULL;}templatebool binaryTreeType::isEmpty(){ return (root == NULL);}templatevoid binaryTreeType::inorderTraversal(){ inorder(root);}templatevoid binaryTreeType::preorderTraversal(){ preorder(root);}templatevoid binaryTreeType::postorderTraversal(){ postorder(root);}templateint binaryTreeType::treeHeight(){ return height(root);}templateint binaryTreeType::treeNodeCount(){ return nodeCount(root);}templateint binaryTreeType::treeLeavesCount(){ return leavesCount(root);}template void binaryTreeType::copyTree (nodeType* &copiedTreeRoot, nodeType* otherTreeRoot){ if(otherTreeRoot == NULL) copiedTreeRoot = NULL; else { copiedTreeRoot = new nodeType; copiedTreeRoot->info = otherTreeRoot->info; copyTree(copiedTreeRoot->llink, otherTreeRoot->llink); copyTree(copiedTreeRoot->rlink, otherTreeRoot->rlink); }} //end copyTreetemplatevoid binaryTreeType::inorder(nodeType *p){ if(p != NULL) { inorder(p->llink); cout<
infollink); postorder(p->rlink); cout<
inforlink); delete p; p = NULL; }}template void binaryTreeType::destroyTree(){ destroy(root);} //copy constructortemplate binaryTreeType::binaryTreeType (const binaryTreeType& otherTree){ if(otherTree.root == NULL) //otherTree is empty root = NULL; else copyTree(root, otherTree.root);}template binaryTreeType::~binaryTreeType(){ destroy(root);}templateint binaryTreeType::height(nodeType *p){ if(p == NULL) return 0; else return 1 + max(height(p->llink), height(p->rlink));}templateint binaryTreeType::max(int x, int y){ if(x >= y) return x; else return y;}templateint binaryTreeType::nodeCount(nodeType *p){ coutinfo > insertItem)trailCurrent->llink = newNode;elsetrailCurrent->rlink = newNode;}templatevoid bSearchTreeType::deleteNode(const elemType& deleteItem){ nodeType *current; //pointer to traverse the tree nodeType *trailCurrent; //pointer behind current bool found = false; if(root == NULL) cerrllink; else current = current->rlink; } }//end while if(current == NULL) coutrlink); }//end if }}//end deleteNodevoid main();{ binaryTreeType n1; insert(100); insert(40); insert(20); insert(15); insert(30); insert(40); insert(35); insert(77); cout
 
السلام عليكم
يا جماعة ممكن احد يشرح لي شلون احل هالاسايمنت وشنو استخدم
1. Define a binary search tree object bst of type bSearchTreeType.
2. Insert the following integers into bst: 100,40, 20, 15, 30, 40, 35, and 77.
3. Display the height of bst.
4. Display the number of nodes of bst.
5. Display the number of leaves of bst.
6. Display the nodes in Preorder, Inorder, and Postorder traversals.
7. Delete the nodes with the content 30 and 35.
8. Display the number of nodes of bst.
 
السلام عليكم
يا جماعة ممكن احد يشرح لي شلون احل هالاسايمنت وشنو استخدم
1. Define a binary search tree object bst of type bSearchTreeType.
2. Insert the following integers into bst: 100,40, 20, 15, 30, 40, 35, and 77.
3. Display the height of bst.
4. Display the number of nodes of bst.
5. Display the number of leaves of bst.
6. Display the nodes in Preorder, Inorder, and Postorder traversals.
7. Delete the nodes with the content 30 and 35.
8. Display the number of nodes of bst.
عليكم السلام
عادي الاسايمنت ما فيه شي مجرد تسوي كول للفنكشنات مال ال binary tree و ال binary search tree فشغلك كله في ال main
بدايةً بتعرف متغير bst من نوع bSearchTreeType
بتسوي انسيرت 8 مرات بواسطة فنكشن الانسيرت سواء كانت مال binary tree أو binry search tree ما بيفرق لانهم انهرتنز
بعدها يبغي تطلع ارتفاع لتري فبتستخدم كول لفنكشن هايت تري في binary tree
و تواصل للنهاية حسب المطلوب الاسايمنت عبارة عن كول فنكشنات بس :smile2:
 
عليكم السلام
عادي الاسايمنت ما فيه شي مجرد تسوي كول للفنكشنات مال ال binary tree و ال binary search tree فشغلك كله في ال main
بدايةً بتعرف متغير bst من نوع bSearchTreeType
بتسوي انسيرت 8 مرات بواسطة فنكشن الانسيرت سواء كانت مال binary tree أو binry search tree ما بيفرق لانهم انهرتنز
بعدها يبغي تطلع ارتفاع لتري فبتستخدم كول لفنكشن هايت تري في binary tree
و تواصل للنهاية حسب المطلوب الاسايمنت عبارة عن كول فنكشنات بس :smile2:
اخوي مب عارف هل استخدم binary tree أو binry search tree اي وحدة فيهم الي اسوي لها كول
 
اخوي مب عارف هل استخدم binary tree أو binry search tree اي وحدة فيهم الي اسوي لها كول
ال binary search tree انهرتنز من ال binary tree
بما ان ال أوبجتك bst من نوع binary search tree ففي هالحالة تقدر تستخدم فنكشنات ال binary tree و ال binary search tree على اوبجت bst
اذا مو فاهم قصدي اذا ممكن ترفع ملف الأسايمنت و بوضح لك من خلاله اول بارتين عشان توضح الفكرة أكثر :smile2:
 
ال binary search tree انهرتنز من ال binary tree
بما ان ال أوبجتك bst من نوع binary search tree ففي هالحالة تقدر تستخدم فنكشنات ال binary tree و ال binary search tree على اوبجت bst
اذا مو فاهم قصدي اذا ممكن ترفع ملف الأسايمنت و بوضح لك من خلاله اول بارتين عشان توضح الفكرة أكثر :smile2:
اي ملف تقصد السؤوال ؟
 
اي ملف تقصد السؤوال ؟
ملف ال cpp مال الاسايمنت لان مو دائماً يستخدمون الداتا ستركجر الموجودة في الكتاب احياناً يحطون داتا ستركجر نفسها بس اسمها غير شوي و اسماء الفنكشن تختلف بعد على سبيل المثال اسم ال binary tree في لكتاب على ما أعتقد binaryTreeType ، عادي انه تنحط على سبيل المثال BinaryTree و اسماء الفنكشن غير اشوي ، عشان جدي فضلت اشوف ملف الأسايمنت ، اذا تبغي اوضح الشي على الداتا ستركجر مال لكتاب و بعدها انت بتطبق على الاسايمنت الي عندك ، عادي مو مشكلة :smile2:
 
ملف ال cpp مال الاسايمنت لان مو دائماً يستخدمون الداتا ستركجر الموجودة في الكتاب احياناً يحطون داتا ستركجر نفسها بس اسمها غير شوي و اسماء الفنكشن تختلف بعد على سبيل المثال اسم ال binary tree في لكتاب على ما أعتقد binaryTreeType ، عادي انه تنحط على سبيل المثال BinaryTree و اسماء الفنكشن غير اشوي ، عشان جدي فضلت اشوف ملف الأسايمنت ، اذا تبغي اوضح الشي على الداتا ستركجر مال لكتاب و بعدها انت بتطبق على الاسايمنت الي عندك ، عادي مو مشكلة :smile2:
مشاهدة المرفق ADTs(1).rar
هذا ADTS وهذا السؤوال
1. Define a binary search tree object bst of type bSearchTreeType.
2. Insert the following integers into bst: 100,40, 20, 15, 30, 40, 35, and 77.
3. Display the height of bst.
4. Display the number of nodes of bst.
5. Display the number of leaves of bst.
6. Display the nodes in Preorder, Inorder, and Postorder traversals.
7. Delete the nodes with the content 30 and 35.
8. Display the number of nodes of bst.
 
عودة
أعلى أسفل