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

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

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

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

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

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

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

عرفتين في بروتوتايب string str ويعادله في المين str1 >>
وكذالك length يعادله في المين length1
و السترينغ الثاني string the يعادله في مين str2

شوفه جدي
PHP:
#include<iostream>
#include<string>
using namespace std;

int countThe(const string str,int length)
{
 int i=0 , count =0;
string str2 = "the";
 
 while(i<length)
 { 
   if (str.substr(i,3) == str2)
 count++;
 
 i++;
 
}
 
 return count;
}


int main()
{
 string str1;
 string str2 = "the";
 int length1;
 cout << "Enter string" << endl;
 getline(cin,str1);
 length1 = str1.length();
 cout << "# of the = "<<countThe(str1,length1)<<endl;
 system("pause");
 return 0;
}

ملاحظه : عدلت ع كود FHJ
 
وايل أو فور كـل الطرق تؤدي إلى روما :RpS_laugh:
Str2 صدق ما ليه لزمة لا في الفنكشن ولا حتى المين
لو نحط بس جدي أوفر بعد
PHP:
if (str.substr(i,3) == " the")
​
 
^^
اختي هذا اللي اقدر اساعدش فيه حاليا

هذي function : selection Sort

PHP:
void selection(int x[] , int length)
{
     int smallestindex , temp;
     
     for(int index=0 ; index<length ; index++)
     {
     smallestindex= index;
     for(int minindex = index+1 ; minindex<length ; minindex++)
     if(x[minindex]<x[smallestindex])
     smallestindex=minindex;
     
     temp=x[smallestindex];
     x[smallestindex]=x[index];
     x[index]=temp;
     
     }
     
     }

هذي function : Seq.Search
PHP:
void searchfun(int array[], int key2)
    {
    int index;
    bool found = false ;  
    for(int i=0; i<10; i++)    
       {if (array[i] == key2)
           {found = true;  
           index=i; 
           break ;    
            }
        }
      if (found)
      cout<< "Your number is at " << index <<".\n";
      else
      cout<< "Sorry,Your number is not in array"<<".\n";  
         }
 
  • Like
التفاعلات: the
هذا الحل :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;
}
​



incorrect :no:

if we want to do shift in array
size should be greater than and not equal length
 
مرحبا شباب أبي توضيح حق كم من شغلة في bubble sort


كود:
void bubbleSort(int list[], int length)
{
    int temp;
    int iteration;
    int 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;
            }
    }
}

length طول الآري صح ؟
list شنو دورها ووين موقعها في الآري وشنو الي راح تسوي
iteration بعد مثل الشي شنو موقعها في اآري وشنو وظيفتها وفي شنو راح تأثر
ليش في for loop الأولية قلنا iteration بدينا بواحد
و for الثانية list[index] +1 مو فاهمنها بعد :RpS_tongue:
 
التعديل الأخير:
^^
اختي هذا اللي اقدر اساعدش فيه حاليا

هذي function : selection Sort

PHP:
void selection(int x[] , int length)
{
     int smallestindex , temp;
     
     for(int index=0 ; index<length ; index++)
     {
     smallestindex= index;
     for(int minindex = index+1 ; minindex<length ; minindex++)
     if(x[minindex]<x[smallestindex])
     smallestindex=minindex;
     
     temp=x[smallestindex];
     x[smallestindex]=x[index];
     x[index]=temp;
     
     }
     
     }

هذي function : Seq.Search
PHP:
void searchfun(int array[], int key2)
    {
    int index;
    bool found = false ;  
    for(int i=0; i<10; i++)    
       {if (array[i] == key2)
           {found = true;  
           index=i; 
           break ;    
            }
        }
      if (found)
      cout<< "Your number is at " << index <<".\n";
      else
      cout<< "Sorry,Your number is not in array"<<".\n";  
         }
ربي يوفقك تسلم :smile2: عاد لاتنساني بكرمك ههههه وتكملي الحل :blushing: واكون شاكرتلك اخوي :smile:
 
ممكن مساعده :(
 
مرحبا شباب أبي توضيح حق كم من شغلة في bubble sort


كود:
void bubbleSort(int list[], int length)
{
    int temp;
    int iteration;
    int 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;
            }
    }
}

length طول الآري صح ؟
عدد العناصر اللتي تحتويها الArray
list شنو دورها ووين موقعها في الآري وشنو الي راح تسوي
list[] هي الarray نفسها !
iteration بعد مثل الشي شنو موقعها في اآري وشنو وظيفتها وفي شنو راح تأثر
اخوي لاتربط الloop مع الأراي لان مافي علاقه بينهم
iteration موقعها في الloop الاول ، وتعني التكرار ( أي عدد المرات اللي بتتكرر فيها العملية)


ليش في for loop الأولية قلنا iteration بدينا بواحد
شوف for loop الثانيه وبالتحديد الشرط وبتفهم ليش الواحد
و for الثانية list[index] +1 مو فاهمنها بعد :RpS_tongue:
اتخيل هذي الarray
[ 10 , 40 , 50 , 100 , 70]
في الدخول الأول للloop
بتكون قيمه index تساوي 70
وبتكون قيمة index+1 تساوي 100
فـ نقارن بين القيمتين اللي ذكرتهم

اتمنى افدتك
 
بالنسبة للسؤال التالي
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)
​
يتكون السؤال من Part A & B

Part A يتكون من اربع functions
الأولى : يجب ان تطبع كل عناصر الarray لكن كل عشرة في سطر .
الثانية : تعمل sorting بأستخدام selection Sort .
الثالثة : نعطيها key وترجع لنا موقعه في الarray (لإستخدامه في الfunction الرابعة) .
الرابعة :
الموقع اللي رجعته الfunction الثالثة ، نضيف بعده رقم جديد .

Part B عبارة عن int main
أي نكتب برنامج نستخدم فيه الfunctions اللي سويناهم في
Part A

عشان يكون كل شي واضح
ملاحظه : جميع قيم الarray من نوع float

اول ماتفتح الكود راح يطبع العناصر كل عشرة في سطر ( مجموعهم 20 عنصر )
بعدين راح يسوي sort ويطبع العناصر بعد السورت بشكل عادي (في سطر واحد)
بعدين راح يطلب الرقم اللي نبي نضيف بعده (
يعني ليس الرقم المطلوب اضافته)

اذا كان كان الرقم ليس موجود راح يطبع مسج يقول ان (ليس موجود) وراح يوقف البرنامج
اما اذا كان الرقم موجود راح يطلب الرقم اللي نبي نضيفه (الجديد)
وبيضيفه وبيطبع لنا العناصر وراح نشوف الرقم الجديد (مـُضاف)

ملاحظه : بالنسبة للsort ممكن نضيفه ايضاً بعد اضافة الرقم الجديد
لكن انا اتعمدت اخليه بالأول ، عشان نشوف الرقم الجديد المضاف
لان السورت راح يغير موقعه بحسب الترتيب


PHP:
#include<iostream>
using namespace std;

void printArray (float A[], int size)
{
     cout<<"The elements of the array each 10 in a line = "<<endl;
for(int i=0 ; i<size ; i++)
{

if(i % 10 == 0)
cout<<endl;
cout<<A[i]<<"  ";

}
cout<<endl;
cout<<endl;
}            
                   
void selection(float A[] , int size)
{
     int smallestindex ;
     float temp;
     
     for(int index=0 ; index<size ; index++)
     {
     smallestindex= index;
     for(int minindex = index+1 ; minindex<size ; minindex++)
     if(A[minindex]<A[smallestindex])
     smallestindex=minindex;
     
     temp=A[smallestindex];
     A[smallestindex]=A[index];
     A[index]=temp;
     
     }
     cout<<"Array After sorting = "<<endl;
     for(int i=0 ; i<size ; i++)
     cout<<A[i]<<"  ";
     
     cout<<endl;
cout<<endl;
     
}     

 int seqSearch_ordredlist (float A[], float key, int size)
 {
     for(int i=0; i<size; i++)    
       if (A[i] == key)
           return i ;
           return -1 ;  
    
     }
          
void InsertAfterakey (float A[], int key, float newelt , int &size, int Maxsize)
{
     int loc;
    loc=key+1 ;
    
    if(size<Maxsize)
for(int i=size ; i>loc ;i--)
A[i]=A[i-1];

A[loc]=newelt;
size++;

}



int main()
{
float list[25]={20.5,50.5,10.8,44.8,25.5,87.5,78.5,40.5,49.8,11.4,14.7,10.5,17.9,17.8,90.5,95.0,
97.4,100.5,141.7,150.5};
int maxsiz=25 , siz=20 , R ;
float newel,key1;

printArray (list,siz);
selection(list,siz);

cout<<"Enter a key (that you want to add another after it) = "<<endl;
cin>>key1;

R=seqSearch_ordredlist(list,key1,siz);
if(R==-1)
cout<<"not found this key!"<<endl;
else
{
cout<<"Enter a new element = "<<endl;
cin>>newel;
InsertAfterakey (list,R,newel,siz,maxsiz);
 cout<<"Array After add new element = "<<endl;
     for(int i=0 ; i<siz ; i++)
     cout<<list[i]<<"  ";
}

    
     
cout<<endl;
cout<<endl;
system("pause");
return 0;
}

أي سؤال ؟

اعتذر على أي تقصير
نسألكم الدعاء

 
بالنسبة للسؤال التالي
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)
​
يتكون السؤال من Part A & B

Part A يتكون من اربع functions
الأولى : يجب ان تطبع كل عناصر الarray لكن كل عشرة في سطر .
الثانية : تعمل sorting بأستخدام selection Sort .
الثالثة : نعطيها key وترجع لنا موقعه في الarray (لإستخدامه في الfunction الرابعة) .
الرابعة :
الموقع اللي رجعته الfunction الثالثة ، نضيف بعده رقم جديد .

Part B عبارة عن int main
أي نكتب برنامج نستخدم فيه الfunctions اللي سويناهم في
Part A

عشان يكون كل شي واضح
ملاحظه : جميع قيم الarray من نوع float

اول ماتفتح الكود راح يطبع العناصر كل عشرة في سطر ( مجموعهم 20 عنصر )
بعدين راح يسوي sort ويطبع العناصر بعد السورت بشكل عادي (في سطر واحد)
بعدين راح يطلب الرقم اللي نبي نضيف بعده (
يعني ليس الرقم المطلوب اضافته)

اذا كان كان الرقم ليس موجود راح يطبع مسج يقول ان (ليس موجود) وراح يوقف البرنامج
اما اذا كان الرقم موجود راح يطلب الرقم اللي نبي نضيفه (الجديد)
وبيضيفه وبيطبع لنا العناصر وراح نشوف الرقم الجديد (مـُضاف)

ملاحظه : بالنسبة للsort ممكن نضيفه ايضاً بعد اضافة الرقم الجديد
لكن انا اتعمدت اخليه بالأول ، عشان نشوف الرقم الجديد المضاف
لان السورت راح يغير موقعه بحسب الترتيب


PHP:
#include<iostream>
using namespace std;

void printArray (float A[], int size)
{
     cout<<"The elements of the array each 10 in a line = "<<endl;
for(int i=0 ; i<size ; i++)
{

if(i % 10 == 0)
cout<<endl;
cout<<A[i]<<"  ";

}
cout<<endl;
cout<<endl;
}            
                   
void selection(float A[] , int size)
{
     int smallestindex ;
     float temp;
     
     for(int index=0 ; index<size ; index++)
     {
     smallestindex= index;
     for(int minindex = index+1 ; minindex<size ; minindex++)
     if(A[minindex]<A[smallestindex])
     smallestindex=minindex;
     
     temp=A[smallestindex];
     A[smallestindex]=A[index];
     A[index]=temp;
     
     }
     cout<<"Array After sorting = "<<endl;
     for(int i=0 ; i<size ; i++)
     cout<<A[i]<<"  ";
     
     cout<<endl;
cout<<endl;
     
}     

 int seqSearch_ordredlist (float A[], float key, int size)
 {
     for(int i=0; i<size; i++)    
       if (A[i] == key)
           return i ;
           return -1 ;  
    
     }
          
void InsertAfterakey (float A[], int key, float newelt , int &size, int Maxsize)
{
     int loc;
    loc=key+1 ;
    
    if(size<Maxsize)
for(int i=size ; i>loc ;i--)
A[i]=A[i-1];

A[loc]=newelt;
size++;

}



int main()
{
float list[25]={20.5,50.5,10.8,44.8,25.5,87.5,78.5,40.5,49.8,11.4,14.7,10.5,17.9,17.8,90.5,95.0,
97.4,100.5,141.7,150.5};
int maxsiz=25 , siz=20 , R ;
float newel,key1;

printArray (list,siz);
selection(list,siz);

cout<<"Enter a key (that you want to add another after it) = "<<endl;
cin>>key1;

R=seqSearch_ordredlist(list,key1,siz);
if(R==-1)
cout<<"not found this key!"<<endl;
else
{
cout<<"Enter a new element = "<<endl;
cin>>newel;
InsertAfterakey (list,R,newel,siz,maxsiz);
 cout<<"Array After add new element = "<<endl;
     for(int i=0 ; i<siz ; i++)
     cout<<list[i]<<"  ";
}

    
     
cout<<endl;
cout<<endl;
system("pause");
return 0;
}

أي سؤال ؟

اعتذر على أي تقصير
نسألكم الدعاء


تسلم ماعليك زود ماقصرت :blushing:
بالتوفيق والنجاح انشاء الله :smile2:
 
PHP:
#include<iostream>
using namespace std;
int maxP (int list[], int size)
{
int max=0;
int i;
for(i=0; i<size;i++)
 if (max < list[i])
  max = list[i];
return max;
}

هي الفنكشن ترجع أكبر قيمة في الآري

مو اذا بنرجع موقع أكبر قيمة بدل retuen max نحط return i
!!!!!!!!!!!!
ما يرضى يرجعها:RpS_glare:
ترجع قيمة السايز و اذا حطيت اقواس للفور ترجع
0​
 
^^
شوفي الحين
PHP:
#include<iostream>
using namespace std;
int maxP (int list[], int size)
{
int max=list[0];
int index;
for(int i=0; i<size;i++)
 if (max < list[i])
{
  max = list[i];
index=i;
}
return index;
}
int main()
{
int r;
int array[5]={12,34,56,76,55};
r=maxP (array,5);
cout<<"Max. number in index = "<<r<<endl;
return 0;
}

مايصير نقول return i
راح يرجع اخر قيمة الى i
وهي = size
 
  • Like
التفاعلات: FHJ
^^
شوفي الحين
PHP:
#include<iostream>
using namespace std;
int maxP (int list[], int size)
{
int max=list[0];
int index;
for(int i=0; i<size;i++)
 if (max < list[i])
{
  max = list[i];
index=i;
}
return index;
}
int main()
{
int r;
int array[5]={12,34,56,76,55};
r=maxP (array,5);
cout<<"Max. number in index = "<<r<<endl;
return 0;
}

مايصير نقول return i
راح يرجع اخر قيمة الى i
وهي = size

جربت هالطريقة بس كنت أحط الريتيرن داخل:mellow:
شُكراً :)
​
 
^^
انتبهي للأقواس
للعلم ان return اول يوصل لها الcompiler
و يرجع للmian بغض النظر عن الشرط في الloop
 
السلام عليكم ..
يا جماعة في احد يقدر يساعدني في حل الاسايمنت حق مقرر cs 104
واييد متوهقه :RpS_crying:
اكون لكم من الشاكرين :tears:
 
Hone Assignment #1 (Applications of Arrays)
Part I
a) Write a function called displayArray that takes as parameters: an array of integers and length. The function should output the elements of the array each 10 in a line. The function prototype is:
void displayArray(int arr[], int length)

b) Write a function called BubbleSort that takes as parameters: an array of integers and length. The function should sort the elements of the array in ascending order using Bubble sort. The function prototype is:
void BubbleArray(int arr[], int length)


c) Write a function called BinarySearch that takes as parameters: an array of integers, a key and length. The function should search for the key in the array using Binary Search. The function prototype is:
int BinarySearch (int arr[], int key, int length)



Part II
Write a main function to test your functions in Part (I)
 
السلام عليكم ..
يا جماعة في احد يقدر يساعدني في حل الاسايمنت حق مقرر cs 104
واييد متوهقه :RpS_crying:
اكون لكم من الشاكرين :tears:


Hone Assignment #1 (Applications of Arrays)
Part I
a) Write a function called displayArray that takes as parameters: an array of integers and length. The function should output the elements of the array each 10 in a line. The function prototype is:
void displayArray(int arr[], int length)

b) Write a function called BubbleSort that takes as parameters: an array of integers and length. The function should sort the elements of the array in ascending order using Bubble sort. The function prototype is:
void BubbleArray(int arr[], int length)


c) Write a function called BinarySearch that takes as parameters: an array of integers, a key and length. The function should search for the key in the array using Binary Search. The function prototype is:
int BinarySearch (int arr[], int key, int length)



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

رجعي للصفحات السابقة للموضوع ..
تحديدا الصفحة السابعة:RpS_sleep:
 
مشكور اخوي واختي ماتقصوروون
لا خله ولا عددم
 
عودة
أعلى أسفل