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

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

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

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

كود:
pos=removeall( list,leanght, item)

loc=removeat( list,leanght, i);
pos and loc are from type int..and the functions remove at and remove all are from type void

void does not return a value and when you say int pos=removeat() you say pos = nothing because void does not return any thing as i mentioned
you have to give the int variables a value

the second point
the semicolons (;) need to be checked

third
include <iostream> must be in 1 line not in 2 lines

these are the major errors try to fix it

if you didn't understand you can ask me for more details..hope that you understand it
​

​
 
التعديل الأخير:
مسآاء آلخيــر ::

بنآآت / شبآآب :smile2:

عندي سؤال ، يعني ماله علاقة في المآدة :RpS_unsure:

بس سمعت انه المحاضرات يوم الأحد من الساعة 9 بتكون ملغية :RpS_huh:
فأبي أعرف الخبر صح أو لا؟؟
​
 
سلاام عليكم ..

عندي سؤال في جبتر 10 ..

اذا كان عندي اراي وفايل شلون انسخ القيم من الفايل لي الاراي ؟؟ وشلون اطبع كل جم قيمة في سطر ؟؟

اللي يعررف لايبخل ..

ومشكورين مقدما ..
 
HTML:
for(int i=0 ; i<n ; i++)
 file>>array[i];

ان شاء الله يكون واضح.. السؤال الثاني ما فهمت شتقصدين !
 
ممكن شرح لأنوع الـsearch ...
الـBinary Search و الـsequential ..
هل في الـ Binary Search و الـsequential نبحث عن الKey ؟؟

ال sequential search ابسط انواع ال search وكل اللي يصير ان في key ندور عليه في وسط مجموعه من ال values نمشي عليهم واحد واحد حتى نوصل لل key
say that we have array (values) and key = 5
values : 1,2,3,4,5,6,7

for(int i=0;i<6;i++)
if (values==key)
cout<<"key is found"
طبعا الكود مش مظبوط بس هاي الفكره نمشي على كل واحد

ال binary search نفس فكرة ال search في ال dictionary
هو معقد شوي عن ال sequential بس في الاخر هو سهل
كل الفكرة مثلا لو ندور على 5 في نفس المثال اللي فوق
1,2,3,4,5
اول خطوه في pointer يوقف عند نص ال values وفي المثال النص عند ال 3 ويقارن هل ال key اكبر ولا اصغر؟ ال 5 اكبر
ثاني خطوه يصغر ال values ويدور في الجزء المطلوب اللي هو اكبر من 3 يعني ال values تصير 4,5 وبنفس الطريقه ال pointer يوقف عند النص هني بتكون ال 4 اذا كان يوقف عند الرقم الاصغر اذا ما في رقم في النص بينهم
4 اصغر من ال 5 يشتغل الحين على اللي اكبر من 4
بتصير ال values
5 بس
ال 5=key ?
اذا حصل ال key بس خلاص اذا ما حصله نطلع رساله مثلا نقول الرقم غير موجود

اتمنى يكون الشرح مفهوم
 
  • Like
التفاعلات: Lutos
Assignment #1
sec 8

13306816662.jpg

كود:
#include <iostream>
using namespace std;

int getMax(int marks[])
{
    int max=marks[0];
    for(int i=0;i<11;i++)
    {
        if(marks[i]>max)
            max=marks[i];
    }
    return max;
}

int getMin(int marks[])
{
    int min=marks[0];
    for(int i=0;i<11;i++)
    {
        if(marks[i]<min)
            min=marks[i];
    }
    return min;
}

double getAverage(int marks[],int numberOfMarks)
{
    double avg=0;

    for(int i=0;i<11;i++)
    {
        avg=avg+marks[i];
    }
    return avg/numberOfMarks;
}

int main ()
{
    const int numberResults=11;
    int marks[numberResults]={75,32,56,12,11,45,47,87,7,12,16};


    cout << "The low score is  " <<getMin(marks);
    cout << "\n\nThe high score is  " <<getMax(marks);
    cout << "\n\nThe average score is : " <<getAverage(marks,numberResults);
    
    cin.get();
  return 0;
}

حل Assignment#1
اتمنى الحل يكون للتاكيد بعد ما كل واحد يحاول بنفسه للافاده واللي عنده اي سؤال يسال وانشاء الله ارد عليه
 
التعديل الأخير:
سلاام عليكم ..

عندي سؤال في جبتر 10 ..

اذا كان عندي اراي وفايل شلون انسخ القيم من الفايل لي الاراي ؟؟ وشلون اطبع كل جم قيمة في سطر ؟؟

اللي يعررف لايبخل ..

ومشكورين مقدما ..

1-create file
2-put some values in it
3-change the path of the file in the code

كود:
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int i;
    int j=0;
    int arr[5];

    ifstream infile("C:\\Users\\Ahmed\\Downloads\\Desktop\\example.txt");

    if (!infile) {
        cout << "There was a problem opening file "
             << endl;
        return 0;
    }

    while (infile >> i) {
        arr[j]=i;
        j++;
    }

    //لطباعة الارقام الموجوده في ال file 
    for(j=0;j<5;j++)
        cout<<arr[j]<<endl;
    cin.get();
    return 0;
}
 
Sequential Search in file

كود:
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int i;
    int j=0;
    int key=0;

    ifstream infile("C:\\Users\\Ahmed\\Downloads\\Desktop\\example.txt");

    if (!infile) {
        cout << "There was a problem opening file "
             << endl;
        return 0;
    }

    cout<<"Enter the key number : "<<endl;
    cin>>key;

    while (infile >> i) {
        if(i==key)
        {
            cout<<"you key "<< key << " has been found succssefully\npress any number to exit";
            cin>>key;
            return 0;
        }
        j++;
    }

    cout<<"you key "<< key << " has not been found\npress any number to exit";
    cin>>key;
    return 0;
}
 
  • Like
التفاعلات: Lutos
Binary Search in Array

ملحوظه في ال binary search الارقام او الحروف لازم تكون بالترتيب

كود:
#include <iostream>
#include <fstream>

using namespace std;

void binarySearch(int values[], int lowerbound, int upperbound, int key)
{
       int position;
       
       // To start, find the subscript of the middle position.
       position = ( lowerbound + upperbound) / 2;

       while((values[position] != key) && (lowerbound <= upperbound))
       {
              if (values[position] > key)               // If the number is > key, ..
             {                                                       // decrease position by one.
                    upperbound = position - 1;   
             }                                                      
             else                                                
            {                                                        // Else, increase position by one.
                   lowerbound = position + 1;     
             }
             position = (lowerbound + upperbound) / 2;
       }
      if (lowerbound <= upperbound)
      {
            cout<< "The number was found in array at position "<< position<<endl<<endl;
            
      }     
       else
             cout<< "Sorry, the number is not in this array. ";
       return;
       // you may also consider returning the subscript
} 

int main()
{
    int key;
    int values[10]={20,24,36,40,67,70,80,84,95,102};
    cout<<"Enter your key"<<endl;
    cin>>key;
    binarySearch(values,0,9,key);
    cin>>key;
}
 
  • Like
التفاعلات: Lutos
اللي عنده اي اسئله انا موجود انشاء الله اجاوب
 
  • Like
التفاعلات: Lutos
اللي عنده اي اسئله انا موجود انشاء الله اجاوب
 
  • Like
التفاعلات: Lutos
A very simple c++ class

ال class يسوي عمليات حسابيه على رقمين
استخدمت Switch عشان احدد العمليه اللي بسويها
ال class فيه constructor يطلع رساله اول ما اسوي object من ال class
الباب مفتوح للاسئلة اذا في اي شيئ

كود:
#include <iostream>
using namespace std;

class Calculate
{
    double sum;
public: 
    Calculate()
    {
        cout<<"This is the constructor of the class 'Calculate'"<<endl;
    }

    void PlusOperation(double num1,double num2)
    {
        sum=num1+num2;
        cout<<"Sum is "<<sum<<endl;
    }

    void MinusOperation(double num1,double num2)
    {
        sum=num1-num2;
        cout<<"Sum is "<<sum<<endl;
    }

    void MultiplicationOperation(double num1,double num2)
    {
        sum=num1*num2;
        cout<<"Sum is "<<sum<<endl;
    }

    void DivisionOperation(double num1,double num2)
    {
        sum=num1/num2;
        cout<<"Sum is "<<sum<<endl;
    }
};



int main()
{
    int choice;
    double num1,num2;
    Calculate obj;//this is an object of the class
    cout<<"Select the operation that you want to perform\npress 1 for plus.\npress 2 for minus.\npress 3 for multiplication\npress 4 for division\npress 0 for exit"<<endl;
    cin>>choice;
    while(choice!=0)
    {
        cout<<"Enter the first number"<<endl;
        cin>>num1;
        
        cout<<"Enter the second number"<<endl;
        cin>>num2;

        switch(choice)
        {
        case 1:
            {
                obj.PlusOperation(num1,num2);
                break;
            }
            
        case 2:
            {
                obj.MinusOperation(num1,num2);
                break;
            }
            
        case 3:
            {
                obj.MultiplicationOperation(num1,num2);
                break;
            }
            
        case 4:
            {
                obj.DivisionOperation(num1,num2);
                break;
            }
        }
        cout<<"Select the operation that you want to perform\npress 1 for plus.\npress 2 for minus.\npress 3 for multiplication\npress 4 for division\npress 0 for exit"<<endl;
    cin>>choice;
    
    }
    return 0;
}
 
  • Like
التفاعلات: Lutos
ال sequential search ابسط انواع ال search وكل اللي يصير ان في key ندور عليه في وسط مجموعه من ال values نمشي عليهم واحد واحد حتى نوصل لل key
say that we have array (values) and key = 5
values : 1,2,3,4,5,6,7

for(int i=0;i<6;i++)
if (values==key)
cout<<"key is found"

طبعا الكود مش مظبوط بس هاي الفكره نمشي على كل واحد


ليش الفور لوب i<6
يصير نخليهاi<7


هالتمرين حليته , حاولت فيه , لكن أعتقد اجابتي خطأ

​

Write a function named Shift To Right that takes as parameters: an array of integers (array)
number of elements in the array (Length),and an integer (pos).The function should shift the elements
of the array one step to the right from pos and increment the array size by 1 .The prototype of the function is:
Void shiftToRight(int array[],int &length,int pos);

HTML:
# include <iostream>
using namespace std;
void  main ()
{
    int pos,arr[7]={1,2,3,4,5,6,7}
    cout<<"enter alist of array";
    cin>>arr;
}
void Shift to Right(int arr[],int&length,int pos)
{
    void insert (int a[],int &n,int loc,int item)
    {
        for (int i=n;i>loc,i--)
            a[i]=a[i-1];
            a[loc]=item;
            n++;
    }
    arr[]+1;
}


​
 
في السؤال الاول صح المفروض تصير 7

السؤال الثاني في شيء اسمه dynamic array alloacting اذا هو المطلوب بيكون له طريقه صعبة شوي لان الاماكن في ال memory ال processor بيسويلها allocate او بيحجزها في ال run time او خلال تنفيذ البرنامج بس اذا هاي المطلوب قوليلي و بقولج الطريقه انشاء الله


هاي الكود انا سويت array عادي وخليت اخر رقم فيه على اليمين 0 لان الارقام بسويلها shift وامسح ال 0 و ادخل الرقم الجديد في ال pos اللي يتحدد بس هذا اسمه static array يختلف تماما عن ال dynamic array

كود:
#include <iostream>

using namespace std;

#define dountilbreak  while (1)

void ShifttoRight(int arr[],int length,int pos)
{
        for(int i=length-1;i>pos;i--)
        {
            arr[i]=arr[i-1];
        }
        cout<<"Enter the new value"<<endl;
        cin>>arr[pos];
        for(int i=0;i<length;i++)
            cout<<"the values after shifting \n"<<arr[i]<<endl;
}

int main () {

    int pos;
    int arr[6]={1,2,3,4,5,0};
    cout<<"Enter the pos"<<endl;
    cin>>pos;
    ShifttoRight(arr,6,pos);
    cin>>pos;
    return 0;
}

وانا موجود اذا في اي اسئله
 
  • Like
التفاعلات: Lutos
هاي الكود في بعض الاخطاء
كود:
int pos,arr[7]={1,2,3,4,5,6,7}
ناقص ;

كود:
void Shift to Right(int arr[],int&length,int pos)
ما يصير انه يكون في spaces بين اسم ال function

كود:
void Shift to Right(int arr[],int&length,int pos)
{
    void insert (int a[],int &n,int loc,int item)
ما يصير تسوي function داخل function الصح ان تسوي كل واحده بروحها وتسويلها call نفس ما سويت call لل shiftToRight في ال main

كود:
for (int i=n;i>loc,i--)
بعد ال loc تكون ; مش ,

كود:
for (int i=n;i>loc,i--)
            a[i]=a[i-1];
            a[loc]=item;
            n++;
ما في اقواس { } لل for loop

كود:
arr[]+1;
هذا السطر غلط لانه اذا ال size مال ال array بيزيد بيكون بطريقة ال dynamic memory allocation

اتمنى الشرح يكون واضح واحسن شيئ انك تحاول وتسوي اخطاء لانه محد يتعلم الا بهاي الطريقه
 
  • Like
التفاعلات: Lutos
مشكوور اخووي على التوضيح وصلت الفكرة ,,

عندي بعد سؤال بخصوص السيرج في الأراي ..

اذا نبي نبحث عن 3 keys نحتااج 3 فور لوب ؟؟؟
 
ممكن شرح مفصل لهذه الخطوة ..
HTML:
for(int i=length-1;i>pos;i--)
ليش int i=length-1; , و i<poss ..
و شكرااا جزيلا مقدما ..

 
لا فور لوب واحده بس..بس في الاول لما تسوي call لل function تغيري ال key يعني
بتسوي call 3 مرات مش 3 فور لوب
مثلا بيكون ال main اذا مثلا ال keys مره 1 ومره 2 ومره 3
كود:
binarySearch(values,0,9,1);
binarySearch(values,0,9,2);
binarySearch(values,0,9,3);

بس اذا تبي تدوري عل ال 3 keys في خطوه واحده بتعرفي key1 و key 2 و key 3 وتزيدي ال
parameters مالة ال function
اتمنى الرد يكون واضح انشاء الله
 
ممكن شرح مفصل لهذه الخطوة ..
HTML:
for(int i=length-1;i>pos;i--)
ليش int i=length-1; , و i<poss ..
و شكرااا جزيلا مقدما ..


انا ابي اسوي shhift to the right يعني في اتجاه اخر ال array فبخلي البدايه عند اخر ال array وابدا اسوي لين ما اوصل لل pos
اول شيء عشان اخلي ال i في اخر ال array ...اذا ال length =5 يعني الاماكن في ال array بتكون 0و1و2و3و4 اخر مكان ال 4 عشان شذي خليت ال i=length-1 يعني 5-1 يوقف عند 4
ثاني شيئ خليت ال i>pos عشان يسوي shift لين يوصل لل pos بس وما يكمل على باقي ال values لان اذا ما سويتها شذي بتسوي shift
لكل ال values و ال new value بيخليها في اول مكان في ال array يعن arr[0] وانا ابي اخليه في arr[pos]

اذا في شيئ مش واضح قوليلي وانشاء الله احاول اوضح اكثر
 
  • Like
التفاعلات: Lutos
ممكن شرح مفصل لهذه الخطوة ..
HTML:
for(int i=length-1;i>pos;i--)
ليش int i=length-1; , و i<poss ..
و شكرااا جزيلا مقدما ..


هذا معناته أن الـ i راح تبدأ من آخر عنصر فالـ array
لو فرضنا حجم الـ array = 10
يعني فيها 10 عناصر
آخر عنصر جم البوزيشن ماله بيكون ، 10 لو 9 ؟
اذا بدأ من الـ 0 شي طبيعي بيكون لـ 9
واحنا ندري أن السايز هو 10
من جدي قلنا i = length -1
عشان نخلي الـ i تأشر على البوزيشن رقم 9 مو 10 لان 10 empty

الهدف من الفور لوب شنو
أن نسوي shift to right
يعني ناخذ العنصر اللي في البوزيشن 9 نوديه البوزيشن 10 ( i = 9 )
ونروح ناخذ العنصر اللي في البوزيشن 8 نوديه البوزيشن 9 ( i = 8 )
ناخذ اللي في البوزيشن 7 نوديه البوزيشن 8 ( i = 7 )

فرضنا ال pos = 5

ناخذ اللي في البوزيشن 6 نوديه البوزيشن 7 ( i = 6 )
ناخذ اللي في البوزيشن 5 ( i = 5 ) هل الـ i > pos ؟ لا لانهم متساويين :RpS_unsure:

لاحظي الحين نقلنا كل العناصر اللي عقب البوزيشن إلى اليمين وصار عندنا البوزيشن 6 فاضي ( البوزيشن اللي عقب البوزيشن 5 )

الحين نقدر نسوي insert داخله لأي قيمة لو طلب السؤال هالشي ..

----------------------------------------

في حال لو كانت الفور لوب بهالشكل :

PHP:
for(int i=length-1;i>=pos;i--)

راح ياخذ اللي في البوزيشن 5 ويوديه البوزيشن 6 وبيصير البوزيشن 5 فاضي

اذا في جزئية ما فهمتينها لا يردش الا الكيبورد :smile2:​
 
  • Like
التفاعلات: Lutos
عودة
أعلى أسفل