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

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

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

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

شرح Sorting
بالتحديد (bubble sort)

sort يعني ترتيب
نفرض عندنا array وداخلها عناصر بهذا الشكل
(10,5,4,8,11)
لما اسوي لهم ترتيب من الصغير الى الكبير يعني راح يكونون بهذا الشكل
(4,5,8,10,11)
كيف نعمل الكود اللي يسوي لنا هالشغله ؟

هذي function جاهزه للاستخدام كل ماعليكم تخلونها برى int main
وداخل int main تسوون لها call

PHP:
    void bubbleSort(int list[] , int length)
       {
       int temp , iteration , index ;
       for (iteration =1 ; iteration<length ; iteration++)
{
       for( index =0 ; index <length - iteration ;index++)
         if (list[index] > list[index + 1])
         { temp = list[index];
           list[index] = list[index + 1];
           list[index + 1] = temp;                         
                     }
       }       
        
        }



طبعا الكود من الكتاب ، في حل ثاني وهو استخدام while و for بدلاً من استخدام for فقط
بس مايحتاج اعور راسكم فيه ، حاولوا فيه للي يبيه لان مابقدر اشرحه :)


اذا في أي مشكله في فهم الكود اسألوا أي استفسار انا حاضر

كل التوفيق ، ونسألكم الدعاء
احلى تحية



شكرا على الشرح :smile2:
بحاول احل السؤال الي عندي وبكتبه اهني ...
عشان اختبر نفسي :whistling:
 
حاولت احل السؤال لكن ما عرفت :RpS_blink:
السؤال نفس المثال :whistling:
السؤال : عندنا array ترتيبها (2,4,6,10,5,0,15,11)
المطلوب هو اعادة ترتيب الـ array من الاصغر الي الاكبر (0,2,4,5,6,10,11,15)

+ في اشياء ما فهمت ليش صارت في المثال , ممكن شرح مفصل :no:
 
امم انا مادري انت صبي لو بنت من جدي شوي اكلمك ع انك صبي وشوي على انك بنت

المهم ، ليش ماعرفتين تجاوبينه ؟
الfunction انا كتبها فوق جاهزه للاستخدام في اي مثال كان
يمكن يكون صار خطأ في كتابه الكود او شي
ياليت تخلين هالمره الكود عشان نشوف وين المشكله ونساعدش يكون احسن ( للاستفاده )

حددي اللي مو واضح وانا بشرحه

هذا الحل للسؤال
PHP:
#include <iostream>
using namespace std;

    void bubbleSort(int list[] , int length)
       {
       int temp , iteration , index ;
       for (iteration =1 ; iteration<length ; iteration++)
      {
       for( index =0 ; index <length - iteration ;index++)
         if (list[index] > list[index + 1])
         { 
           temp = list[index];
           list[index] = list[index + 1];
           list[index + 1] = temp;                         
           }          
       }       
        
        }    
        
        int main()
   {
        
       int array[8]={2,4,6,10,5,0,15,11};
       int n=8;
        cout<<"Array before sorting ="<<endl; 
       for(int i=0;i<n;i++) // to print array contents
       {
        cout<<array[i]<<" ";
       }
        cout<<endl;
       bubbleSort(array,n); //n = size of array
       
       cout<<"Array after sorting ="<<endl; 
       for(int i=0;i<n;i++) // to print array contents
       {
        cout<<array[i]<<" ";
       }
       cout<<endl;
       
    system("pause");
     return 0;
}

سويت طباعه لمحتوى array قبل الsort وبعد sort عشان يكون اوضح
 
ما شاء الله ... مجتهدين ..

د.أمل غانم .. بعدهي ما بدت ويانا ..
تذكير Array

يوم الإثنين راح نبدي وندش المعمعة وياكم
​
 
عندي سؤال يمكن غبي :sly:
ليش الدكتورة ما تكتب لنا الي تحت الـ int main :RpS_lol:
<< مو ضروري ؟
 
يمكن اللي تشرحه يكون في function، واللي بالـmain function راح يكون بسيط، غالباً بس تطلب input من اليوزر وتستخدم الفنكشن تالي تطبع الـoutput، المفترض نكون عارفين هالأشياء من جذي ما تكتب لكنه ضروري إذا طلب بالاختبار نكتب برنامج كامل.
 
عندي سؤال يمكن غبي :sly:
ليش الدكتورة ما تكتب لنا الي تحت الـ int main :RpS_lol:
<< مو ضروري ؟

ههه لا ماله داعي تقول غبي
لان انت في 104 قد يطلب منك بس تكتب function بدون برنامج كامل
 
مشكور it student ما تقصر الله يوفق ليك :smile:
 
^^
العفو ، حاضر لكم
 
الموضوع صار بارد نوعا ما ..
فحبيت اشاركم بأسألة Tutorial من جبتر 8 الـ string type

Problem 1: Five-letter word x is hidden in a string y such that the first two letters of x are the first two letters of y and the third letter of x is the middle letter of y and the last two letters of x are the last two letters of y. Note that y is any string with length greater than 5.
For example, the 10-letter string grabcefgat hides the 5-letter word great.
And the 7-letter string enatber hides the 5-letter word enter.
(a) Write a function called extract that takes a string as an input parameter and returns the hidden word.
(b) Write a program that reads a string from the user and displays the hidden word extracted from the entered string using the function extract.
Problem 2: Write a program that prompts the user to input a string. The program then should remove all the vowels from the string and output the new string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. Your program must contain a function to determine whether a character is a vowel and another function to remove any vowel character using the function “substr”.
 
يعطيكم العافية
 
ممكن مساعده :nosweat: في فهم السؤال :مع العلم انني حاولت فهمه :RpS_blink: بس من جد ماكو فايده :tears:


Part I​
a) Write a function called printArray that takes as parameters: an array of integers and size. The function should output the elements of the array each 10 in a line. The function prototype is:​
void printArray float A[], int size)​
b) Write a function called SelectionSort that takes as parameters: an array of integers and size. The function should sort the elements of the array in ascending order using SelectionSort.​
c) Write a function called seqSearch_ordredlist that takes as parameters: an array of integers, a key and size. The function should search for the key in the array using seqSearch. The function prototype is:​
int seqSearch_ordredlist (float A[], float key, int size)​
d) Write a function called InsertAfterakey that takes as parameters: an array of integers, a key, a new element, size and Maxsize. The function should search for the key in the array using seqSearch_ordredlist and insert newelt after it. The function prototype is:​
int InsertAfterakey (float A[], float key, int newelt , int &size, int Mazsize)


​
Part II
​
Write a main function to test your functions in Part (I)
​
 
ممكن مساعده :nosweat: في فهم السؤال :مع العلم انني حاولت فهمه :RpS_blink: بس من جد ماكو فايده :tears:


Part I
​
a) Write a function called printArray that takes as parameters: an array of integers and size. The function should output the elements of the array each 10 in a line. The function prototype is:
​
void printArray float A[], int size)
​
نكتب void function تاخذ array and size
وظيفتها تطبع عناصر الArray كل عشرة في سطر واحد
وعاطنكم الprototype جاهزه


b) Write a function called SelectionSort that takes as parameters: an array of integers and size. The function should sort the elements of the array in ascending order using SelectionSort.
​
نكتب function الخاصه بـ Selection Sort بالضبط نفس اللي اخذناها في ch.10

c) Write a function called seqSearch_ordredlist that takes as parameters: an array of integers, a key and size. The function should search for the key in the array using seqSearch. The function prototype is:
​
int seqSearch_ordredlist (float A[], float key, int size)
​
نكتب function الخاصة بـ seq. Search بالضبط نفس اللي اخذناها في ch.10

d) Write a function called InsertAfterakey that takes as parameters: an array of integers, a key, a new element, size and Maxsize. The function should search for the key in the array using seqSearch_ordredlist and insert newelt after it. The function prototype is:
​
int InsertAfterakey (float A[], float key, int newelt , int &size, int Mazsize)​
نكتب function تاخذ array , key , new element , size and Max. size
الوظيفة : نبحث بطريقة Seq.Search عن الKey ولما نحصله نضيف بعده ال new element
وكاتب لنا الprototype جاهزه



Part II
​
Write a main function to test your functions in Part (I)​
بعد ماكتبنا فوق الfunctions كلهم الحين نسوي برنامج عشان نجربهم طبعا في
PHP:
int main()
{


return 0 ;
}

كل التوفيق لنا ولكم
نسالكم الدعاء
 
هذا الحل :blushing::
#include<iostream>
using namespace std;
void shiftRight(int A[],int index, int & length)
{
for(int i=length-1;i>=index;i--)
{
A[i+1]=A;
length++;
}
}
int main()
{
int index=5;
int length=10;
int A[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
shiftRight(A,index,length);
for(int i=0; i<20;i++)
cout<<A<<" ";
return 0;
}
​
 
بالنسبة لهذا السؤال، انا ما قدرت احله باللي درسونا اياه فقط
احتجت اشياء ثانية ما درسناها، سؤالي هو هل بالإمكان حله بطريقة ثانية من خلال اللي درسناه فقط؟

صورة للسؤال
2yv5ooh.png


وهذا الحل
PHP:
#include <iostream>
#include <string>
using namespace std;
size_t CountThe( const std::string &str1, const std::string &str2 );
int main()
{
	string str1, str2="the";

	cout<<"Enter a string:\n";
	getline(cin, str1);

	
	cout<<"# of the = "<<CountThe(str1, str2)<<endl;
	
	return 0;
}

size_t CountThe( const std::string &str1, const std::string &str2 )
{
	size_t count = 0;
	std::string::size_type pos = 0;

	while ( ( pos = str1.find( str2, pos ) ) != std::string::npos )
	{
		count++;
		pos += str2.size();
	}

	return count;
}
 
بالنسبة لهذا السؤال، انا ما قدرت احله باللي درسونا اياه فقط
احتجت اشياء ثانية ما درسناها، سؤالي هو هل بالإمكان حله بطريقة ثانية من خلال اللي درسناه فقط؟

صورة للسؤال
2yv5ooh.png


وهذا الحل
PHP:
#include <iostream>
#include <string>
using namespace std;
size_t CountThe( const std::string &str1, const std::string &str2 );
int main()
{
    string str1, str2="the";

    cout<<"Enter a string:\n";
    getline(cin, str1);

    
    cout<<"# of the = "<<CountThe(str1, str2)<<endl;
    
    return 0;
}

size_t CountThe( const std::string &str1, const std::string &str2 )
{
    size_t count = 0;
    std::string::size_type pos = 0;

    while ( ( pos = str1.find( str2, pos ) ) != std::string::npos )
    {
        count++;
        pos += str2.size();
    }

    return count;
}
ما أعرف اشرح:nosweat:
بس الي سويته إني حطيت فور لوب يبدأ من 0 و يوقف عند طول السترنغ
و كل حين يجيك كل 3 حروف اذا يساوون the الكاونتر يزيد
​
PHP:
#include<iostream>
#include<string>
using namespace std;
int countThe(string str,int length,string the)
{
 int count =0;
 the = "the";

 for(int i=0;i<length;i++)
  if (str.substr(i,3) == the)
 count++;
 
 
 return count;
}
int main()
{
 string str1;
 string str2 = "the";
 int length1;
 cout << "Enter string" << endl;
 getline(cin,str1);
 length1 = str1.length();
 cout << countThe(str1,length1,str2);
 return 0;
}
 
ممكن مساعده :nosweat: في فهم السؤال :مع العلم انني حاولت فهمه :RpS_blink: بس من جد ماكو فايده :tears:


Part I​
a) Write a function called printArray that takes as parameters: an array of integers and size. The function should output the elements of the array each 10 in a line. The function prototype is:​
void printArray float A[], int size)​
b) Write a function called SelectionSort that takes as parameters: an array of integers and size. The function should sort the elements of the array in ascending order using SelectionSort.​
c) Write a function called seqSearch_ordredlist that takes as parameters: an array of integers, a key and size. The function should search for the key in the array using seqSearch. The function prototype is:​
int seqSearch_ordredlist (float A[], float key, int size)​
d) Write a function called InsertAfterakey that takes as parameters: an array of integers, a key, a new element, size and Maxsize. The function should search for the key in the array using seqSearch_ordredlist and insert newelt after it. The function prototype is:​
int InsertAfterakey (float A[], float key, int newelt , int &size, int Mazsize)


​
Part II
​
Write a main function to test your functions in Part (I)
​

ممكن مساعده بليييززز لاني محتاجتنه ضروري :sad_1:
 
ما أعرف اشرح:nosweat:
بس الي سويته إني حطيت فور لوب يبدأ من 0 و يوقف عند طول السترنغ
و كل حين يجيك كل 3 حروف اذا يساوون the الكاونتر يزيد
​
PHP:
#include<iostream>
#include<string>
using namespace std;
int countThe(string str,int length,string the)
{
 int count =0;
 the = "the";

 for(int i=0;i<length;i++)
  if (str.substr(i,3) == the)
 count++;
 
 
 return count;
}
int main()
{
 string str1;
 string str2 = "the";
 int length1;
 cout << "Enter string" << endl;
 getline(cin,str1);
 length1 = str1.length();
 cout << countThe(str1,length1,str2);
 return 0;
}

والله فر راسنا فر .. الطريقة الأولى كلش ما عندنا فكرة هنا .. كأني أقرأ طلاسم

الفكرة الثانية كانت في بالي .. بس دكتورة لاب شوشت مخنا تقول أستخدمو وايل وعفستنا..

المهم .. عندي كم سؤال في بروتوتايب ..

عرفتين في بروتوتايب string str ويعادله في المين str1 >>
وكذالك length يعادله في المين length1
و السترينغ الثاني string the يعادله في مين str2
 
في احد يعرف شنو طبيعة اسئلة الكواز لدكتورة امل غانم ؟؟:rolleyes2:
 
عودة
أعلى أسفل