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

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

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

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

[FONT=&quot]Given the following class[/FONT]

[FONT=&quot]Class list [/FONT]
[FONT=&quot] { friend bool operator >(const List& K, const list& H);[/FONT]
[FONT=&quot] private :[/FONT]
[FONT=&quot] Int A[100];[/FONT]
[FONT=&quot] Int size;[/FONT]
[FONT=&quot] Public:[/FONT]
[FONT=&quot] List(int s=0);[/FONT]
[FONT=&quot] Void set(int B[], int s);[/FONT]
[FONT=&quot] Void get(int B[],int & s);[/FONT]
[FONT=&quot] Void print();[/FONT]
[FONT=&quot] List operator /(const list& K);[/FONT]
[FONT=&quot]};[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Define all functions in the class. The operator > add all elements of K and compare them with sum of all elements of H. The operator / divide[/FONT]
[FONT=&quot]Each element in object one by the corresponding element in second object [/FONT]
[FONT=&quot]And store the result in third object. If the two list does not have the same size store zeros in the extra elements.[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Test your program[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Int main()[/FONT]
[FONT=&quot]{[/FONT]
[FONT=&quot] List X,Y,Z;[/FONT]
[FONT=&quot] Int p[3]={2,7,8};[/FONT]
[FONT=&quot] Int q[2]= {20,30};[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] X.set(p,3);[/FONT]
[FONT=&quot]Y. set(q,2);[/FONT]
[FONT=&quot]If(X>Y) [/FONT]
[FONT=&quot] Cout<< “X=”<<X.print();[/FONT]
[FONT=&quot]Else[/FONT]
[FONT=&quot] Cout<< “Y=”<<Y.print();[/FONT]
[FONT=&quot]Z= Y+X;[/FONT]
[FONT=&quot]Z.print();[/FONT]
[FONT=&quot]Return 0;}[/FONT]
 
Given the following class

Class list
{ friend bool operator >(const List& K, const list& H);
private :
Int A[100];
Int size;
Public:
List(int s=0);
Void set(int B[], int s);
Void get(int B[],int & s);
Void print();
List operator /(const list& K);
};

Define all functions in the class. The operator > add all elements of K and compare them with sum of all elements of H. The operator / divide
Each element in object one by the corresponding element in second object
And store the result in third object. If the two list does not have the same size store zeros in the extra elements.


Test your program

Int main()
{
List X,Y,Z;
Int p[3]={2,7,8};
Int q[2]= {20,30};

X.set(p,3);
Y. set(q,2);
If(X>Y)
Cout<< “X=”<<X.print();
Else
Cout<< “Y=”<<Y.print();
Z= Y+X;
Z.print();
Return 0;}

وش سؤالك بالضبط؟
وقبل أي شي.. تأكد/تأكدي من friend bool operator >(const List& K, const list& H); اذا كانوا( List k و list H)..أو (list k و list H)..
واذا السؤال انت اللي كتبته افضل ان تسويه copy
 
التعديل الأخير:

اختي انتي مخليه سؤالين ، واثنينهم بنفس الفكره تقريبا
انا مابقدر اجاوبهم اثنينهم ، بجاوب الأول


هذا حل السؤال الأول


PHP:
#include<iostream>
using namespace std;

class bookList {
      private :
      string *list;
      int size;
      int count;
      public:
             bookList(int = 10);
             bookList(const bookList &);
             void printList();
             void addNewBook(string);
             ~bookList();
             };
             bookList::bookList(int MaxSize){
             size=MaxSize;
             count=0;
             list=new string[MaxSize];    
             }
             
             bookList::bookList(const bookList &obj){
             size=obj.size;
             count=obj.count;
             
             list=new string[size]; 
             for(int i=0 ;i<count ;i++)
             list[i]=obj.list[i];
             }
             
             void  bookList::printList(){
                         for(int i=0 ;i<count ;i++)
                         cout<<list[i]<<" ";
                         cout<<endl;
                         }
                         
             void  bookList::addNewBook(string item)
             { 
             bool found=false;
             if(count<size){
             for(int i=0 ;i<count ;i++)
             if(list[i]==item)
             found=true;
             if(!found){
             list[count]=item;
             count++;}      
             }
             }
             
             bookList::~bookList()
             {delete [] list ;}
             
            int main(){
                 string item;
                 bookList myList1(5);
                 cout<<"Enter the titles of books "<<endl;
                 for(int i=0 ;i<5 ;i++){
                 cin>>item;
                 myList1.addNewBook(item);}
                 
                 bookList myList2(myList1);
                 
                 myList1.printList();
                 myList2.printList();
                 cout<<endl;
                 system("Pause");
                return 0;
                 }


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

شكرا ما قصرت
بس انا كنت ابي بارت B المين والسؤال الثاني
لان الاول حاولت فيه بس المين ما عرفت له
 
شكرا ما قصرت
بس انا كنت ابي بارت B المين والسؤال الثاني
لان الاول حاولت فيه بس المين ما عرفت له

طيب ، هذا الحل للسؤال الثاني
ملاحظه
:

isListEmpty
isListFull
لضيق الوقت ، ولان حسيت مالهم داعي ماكتبت الكود الخاص فيهم

PHP:
#include<iostream>
using namespace std;


class shoppingList {
      private :
              string *list;
              int maxSize;
              int numItems;
              public :
                     shoppingList(int =10);
                     shoppingList(const shoppingList & );
                     void printList();
                     void addNewItem(string);
                     bool isListEmpty();
                     bool isListFull();
                     ~shoppingList();
      };
      
     shoppingList::shoppingList(int MaxSize){
             maxSize=MaxSize;
             numItems=0;
             list=new string[maxSize];    
             }
                       
    shoppingList::shoppingList(const shoppingList &obj ){
                         maxSize=obj.maxSize;
                         numItems=obj.numItems;
                         list=new string[maxSize];
                         for(int i=0 ; i<numItems ;i++)
                         list[i]=obj.list[i];
                         }
      
   void shoppingList::printList()
   {for(int i=0 ; i<numItems ;i++)
   cout<<list[i]<<" ";
   cout<<endl;}
   
    void  shoppingList::addNewItem(string item)
       { 
             bool found=false;
             if(numItems<maxSize){
             for(int i=0 ;i<numItems ;i++)
             if(list[i]==item)
             found=true;
             if(!found){
             list[numItems]=item;
             numItems++;}      
             }
             }
             
       shoppingList::~shoppingList()
             {delete [] list ;}
int main()
{
    shoppingList myList1(5);
    myList1.addNewItem("Rice");
    myList1.addNewItem("Sugar");
    shoppingList myList2(myList1);
    myList2.addNewItem("Milk");
    myList2.addNewItem("Coffee");
    myList1.printList();
    myList2.printList();
    cout<<endl;
    system("pause");
    return 0;
    }

نسألكم الدعاء
 
شباااب ضروري ابي اعرف ان الحل صح ولا لا .. ما اعرف شئ في البوينترز ولا الاوفرلودنج ولا الداينمك ميموري .. خصوصا الداينمك كلش ما افهم فيه شئ .. خلكم وياي شي

PHP:
Problem 1:   
Consider the following declaration to answer the questions below:  
      int x = 15; 
a)  Write a statement to declare a pointer intptr1 to point to x. 
b)  Write a statement to print the content of the memory location pointed by intptr1. 
c)  Write a statement to declare a pointer intptr2 which points to a memory location that holds data    
of type integer. 
d)  Write a statement to let intptr2 points to the same memory location where intpr1 is pointing. 
e)  Write a statement to print the address of intptr2.

السؤال الأول
PHP:
a)  Write a statement to declare a pointer intptr1 to point to x.

الجواب
PHP:
int *ptr1;
   
 ptr1=&x

السؤال الثاني
PHP:
b)  Write a statement to print the content of the memory location pointed by intptr1.

الجواب
PHP:
cout <<*ptr1<< endl;

السؤال الثالث
PHP:
c)  Write a statement to declare a pointer intptr2 which points to a memory location that holds data    
of type integer.

الجواب
PHP:
بصراحه ما فهمت السؤال !!

السؤال الرابع
PHP:
d)  Write a statement to let intptr2 points to the same memory location where intpr1 is pointing.

الجواب
PHP:
int *ptr1;
int *ptr2;
    
ptr1=&x;
 ptr2=ptr1;

السؤال الخامس
PHP:
e)  Write a statement to print the address of intptr2.

الجواب
PHP:
 cout<<ptr2<<endl;


..

خبروني وين الأغلاط و شلون اصححها :tears::no::RpS_huh:
 
من يعرف الحل مالها .. انا متاخره وماعرف افكر ف السوال اساسا ماحضرن اللكجر فمن جذي .. هاي لاب اسايمنت ... بليييز من يقدر يساعد ؟

class Rectangle
{
public:
float getLength() {return length;}
void setLength(float L);
float getWidth() {return width;}
void setWidth(float W);
double perimeter(void) {return (length*2 + width*2);}

double area(void) {return length*width);}
private:
float length;
float width;
};

use the above class to overlaod the + operator as a non member function and test your program.
 
هذي الـProblem 2 في الـPointers

انا حليته وابي اعرف وين الأخطاء إذا ممكن .. يشتغل صح مافيه شئ بس ابي اعرف إذا عندي خطأ في الأكسبريشن او طريقة الحل .. خبروني

PHP:
Problem 2:   
Consider the following class declaration: 
class Example { 
public: 
    void setValue(int a)      { value = a; } 
    void print( ) const  { cout << "Value = " << value << endl; } 
private: 
   int value;    }; 
Write a main function that includes the following statements: 
a)  Write a statement to declare an object named ExObject of type Example. 
b)  Write a statement to declare a pointer named  ExPointer  of type  Example that points to 
ExObject. 
c)  Write a statement to set the value of ExObject to 5 using ExPointer. 
d)  Write a statement to print the value of ExObject using ExPointer.

الحل
PHP:
#include <iostream>

using namespace std;

class Ex
{
public:
    void setValue(int a)      { value = a; }
    void print( ) const  { cout << "Value = " << value << endl; }
private:
   int value;

};


int main()
{

    Ex  ExObject;
    Ex *Expointer;
    Expointer=&ExObject;

    (*Expointer).setValue(5);
    (*Expointer).print();

    return 0;
}

الـOutput
PHP:
Value = 5

نسألكم الدعاء جماعة
 
هل كيف نحل هالسؤال ؟ بطبط مخي !!

:RpS_blink::RpS_blink::RpS_blink::sad_1::sad_1:

PHP:
Problem 3:   
a.  Write a function named Firstzero  that takes as parameters an array of integers, the array length, 
and two pointers. The prototype of the function is: void Firstzero (int arr[],int length, int* &ptr, 
int * pos). The function should let ptr points to the first zero in the array and pos to be equal to the 
position of the first zero in the array. 
b.  Consider the following declaration in the main function: 
int arr[]={1,2,0,1,2,0};   int len=5;   int *ptr, pos; 
-  Write a statement to call the function Firstzero defined in (a) using the variables declared 
above. 
-  Write a statement to output the value of the memory location pointed by ptr, and the 
value of pos.
 
هل كيف نحل هالسؤال ؟ بطبط مخي !!

:RpS_blink::RpS_blink::RpS_blink::sad_1::sad_1:

PHP:
Problem 3:   
a.  Write a function named Firstzero  that takes as parameters an array of integers, the array length, 
and two pointers. The prototype of the function is: void Firstzero (int arr[],int length, int* &ptr, 
int * pos). The function should let ptr points to the first zero in the array and pos to be equal to the 
position of the first zero in the array. 
b.  Consider the following declaration in the main function: 
int arr[]={1,2,0,1,2,0};   int len=5;   int *ptr, pos; 
-  Write a statement to call the function Firstzero defined in (a) using the variables declared 
above. 
-  Write a statement to output the value of the memory location pointed by ptr, and the 
value of pos. 
][/QUOTE][PHP]#include<iostream>


[LEFT][PHP]
#include<iostream>
using namespace std;
void Firstzero(int arr[],int length, int* &ptr, int *pos)
{
 for (int i = 0;i<length;i++)
  if( arr[i] ==0)
  {
   ptr = &arr[i];
   *pos = i;
  }
}
int main()
{
 int arr[]={1,2,0,1,2,0}; 
 int len=5;  
 int *ptr, pos; 
 Firstzero(arr,len,*&ptr,&pos);
 cout << *&ptr << " " << pos << endl;
return 0;
}
[/LEFT]

مو متأكدة اذا كان صح :\
لاني مضيعة في هذا الدرس اطالع النوت و احل بدون فهم:RpS_sleep:
​
 
التعديل الأخير:
  • Like
التفاعلات: xrom
هذي الـProblem 2 في الـPointers

انا حليته وابي اعرف وين الأخطاء إذا ممكن .. يشتغل صح مافيه شئ بس ابي اعرف إذا عندي خطأ في الأكسبريشن او طريقة الحل .. خبروني

PHP:
Problem 2:   
Consider the following class declaration: 
class Example { 
public: 
    void setValue(int a)      { value = a; } 
    void print( ) const  { cout << "Value = " << value << endl; } 
private: 
   int value;    }; 
Write a main function that includes the following statements: 
a)  Write a statement to declare an object named ExObject of type Example. 
b)  Write a statement to declare a pointer named  ExPointer  of type  Example that points to 
ExObject. 
c)  Write a statement to set the value of ExObject to 5 using ExPointer. 
d)  Write a statement to print the value of ExObject using ExPointer.

الحل
PHP:
#include <iostream>

using namespace std;

class Ex
{
public:
    void setValue(int a)      { value = a; }
    void print( ) const  { cout << "Value = " << value << endl; }
private:
   int value;

};


int main()
{

    Ex  ExObject;
    Ex *Expointer;
    Expointer=&ExObject;

    (*Expointer).setValue(5);
    (*Expointer).print();

    return 0;
}

الـOutput
PHP:
Value = 5

نسألكم الدعاء جماعة

لايوجد اخطاء
 
  • Like
التفاعلات: xrom
الي عنده حل لهالسؤال يخبرنا ... جربت يمين يسار ما فيه فايدة ... ما رضى يشتغل
class Rectangle
{
public:
float getLength() {return length;}
void setLength(float L);
float getWidth() {return width;}
void setWidth(float W);
double perimeter(void) {return (length*2 + width*2);} double area(void) {return length*width);}
private:
float length;
float width;
};
use the above class to overlaod the + operator as a non member function and test your program.
 
@FHJ

بعد التأكد من حل الـProblem 1 in Pointers .. هذا السؤال مع الحل

وألف ألف ألف شكر لأخت @FHJ .. بطلتي عيني على شغلات وايد وفهمت تقريبا كلشي في البوينترز .. يبقى اطبق بس :msn-wink:

Problem 1 - Pointers

PHP:
/*

Problem 1:
Consider the following declaration to answer the questions below:
      int x = 15;
a)  Write a statement to declare a pointer intptr1 to point to x.
b)  Write a statement to print the content of the memory location pointed by intptr1.
c)  Write a statement to declare a pointer intptr2 which points to a memory location that holds data
of type integer.
d)  Write a statement to let intptr2 points to the same memory location where intpr1 is pointing.
e)  Write a statement to print the address of intptr2.


*/

#include <iostream>

using namespace std;

int main()
{
    int x=15; // Part A
    int *intptr1; // Part A
    int *intptr2; // Part C

    intptr1=&x; // Part A

    cout<<*intptr1<<endl; //Part B

    intptr1=intptr2; // Part D

    cout<<*&intptr2<<endl; // Part E
    cout<<*&intptr1<<endl; // Part E

    return 0;
}

وبعد إذا في شي خبروني خطأ طريقة حل او شئ
 
@FHJ

بعد التأكد من حل الـProblem 1 in Pointers .. هذا السؤال مع الحل

وألف ألف ألف شكر لأخت @FHJ .. بطلتي عيني على شغلات وايد وفهمت تقريبا كلشي في البوينترز .. يبقى اطبق بس :msn-wink:

Problem 1 - Pointers

PHP:
/*

Problem 1:
Consider the following declaration to answer the questions below:
      int x = 15;
a)  Write a statement to declare a pointer intptr1 to point to x.
b)  Write a statement to print the content of the memory location pointed by intptr1.
c)  Write a statement to declare a pointer intptr2 which points to a memory location that holds data
of type integer.
d)  Write a statement to let intptr2 points to the same memory location where intpr1 is pointing.
e)  Write a statement to print the address of intptr2.


*/

#include <iostream>

using namespace std;

int main()
{
    int x=15; // Part A
    int *intptr1; // Part A
    int *intptr2; // Part C

    intptr1=&x; // Part A

    cout<<*intptr1<<endl; //Part B

    intptr1=intptr2; // Part D

    cout<<*&intptr2<<endl; // Part E
    cout<<*&intptr1<<endl; // Part E

    return 0;
}

وبعد إذا في شي خبروني خطأ طريقة حل او شئ

بعدنا جهال على هذا المقرر .. :nosweat:

بس في شغلة اظن هذي :
كود:
    cout<<*&intptr2<<endl; // Part E

مثل :
كود:
    cout<<intptr2<<endl; // Part E

الطريقتين يطلعون العنوان .. :whistling:
 
  • Like
التفاعلات: xrom
بعدنا جهال على هذا المقرر .. :nosweat:

بس في شغلة اظن هذي :
كود:
    cout<<*&intptr2<<endl; // Part E

مثل :
كود:
    cout<<intptr2<<endl; // Part E

الطريقتين يطلعون العنوان .. :whistling:

صحيح كلامك اخووي .. بس يبين عليك شطان مافي شئ صعب عليك هههههه
 
  • Like
التفاعلات: xrom
هذا حلي للـProblem 2 in Pointers

PHP:
/*

Problem 2:
Consider the following class declaration:
class Example {
public:
    void setValue(int a)      { value = a; }
    void print( ) const  { cout << "Value = " << value << endl; }
private:
   int value;    };
Write a main function that includes the following statements:
a)  Write a statement to declare an object named ExObject of type Example.
b)  Write a statement to declare a pointer named  ExPointer  of type  Example that points to
ExObject.
c)  Write a statement to set the value of ExObject to 5 using ExPointer.
d)  Write a statement to print the value of ExObject using ExPointer.

*/

#include <iostream>
using namespace std;

class Example
 {

public:
    void setValue(int a)      { value = a; }
    void print( ) const  { cout << "Value = " << value << endl;


}

int main()
{

    Example ExObject; // Part A
    Example *Expointer; // Part B

    Expointer=&ExObject; // Part B

    Expointer->setValue(5); // Part C
    Expointer->print(); // Part D



    system("pause");
    return 0;
}

وهذي هم طريقه حل ثانيه لآخر بارتين

PHP:
 (*Expointer).setValue(5); // Part C
    (*Expointer).print(); // Part D
 
حلي لــ Problem 3 in Pointers بمساعده الـ@FHJ

PHP:
/*

Problem 3:
          a.  Write a function named Firstzero that takes as parameters an array of integers, the array length,
              and two pointers. The prototype of the function is: void Firstzero (int arr[],int length, int* &ptr,
              int * pos). The function should let ptr points to the first zero in the array and pos to be equal to the
              position of the first zero in the array.
         b.   Consider the following declaration in the main function:
                   int arr[]={1,2,0,1,2,0};  int len=5;      int *ptr, pos;
                   -    Write a statement to call the function Firstzero defined in (a) using the variables declared
                        above.
                   -    Write a statement to output the value of the memory location pointed by ptr, and the
                        value of pos.

*/



#include <iostream>
using namespace std;

void Firstzero (int arr[],int length, int* &ptr, int * pos)
{
    for(int i=0 ; i<5 ; i++)
    {
        if(arr[i]==0)
        {
            ptr=&arr[i];
            *pos=i;
        }
    }
}


int main()
{
    int arr[]={1,2,0,1,2,0};
    int length=5;
    int *ptr;
    int pos;

    Firstzero(arr,length,*&ptr,&pos); // Part B First Statement

    cout<<"The address of first zero is: "<< *&ptr <<endl<<"At Position: "<<pos<<endl; // Part B Second Statement - *&ptr will print the address of the first zero
    cout<<"The address of first zero is: "<< *&ptr <<endl<<"At Position: "<<pos<<endl; // Part B Second Statement - *ptr will print the value of the address of the first zero

    return 0;
}
 
عودة
أعلى أسفل