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

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

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

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

(Overloading)


Consider the following class named Sentence.
class Sentence
{
private:
string words[25]; // An array that represents the words of the sentence
intSentenceLength; //Number of words in the sentence
public:
Sentence ( ); //Initialize SentenceLength to zero
voidReadSentence( ); // Toread the length and words of the sentence
voiddisplaySentence ( ); //Display Sentence
};

PART(A)

Overload the = = operator (equal) as a member function of the class Sentence. Two sentences (S1 and S2) are considered to be equal if they have the same SentenceLength and the words of S1 equal to the corresponding words in S2.



PART(B):

In the main function:
- Declare two objects named S1 and S2 of type Sentence.

- Use the ReadSentence function to read the length and words of S1 and S2.

- Compare if S1 and S2 are equal and output an appropriate message.



بليز احد يساعدني

هذا الحل
PHP:
#include <iostream>
#include <string>
using namespace std;
class Sentence 
{ 
private: 
	string words[25]; // An array that represents the words of the sentence 
	int SentenceLength; //Number of words in the sentence 
public: 
	Sentence(); //Initialize SentenceLength to zero 
	void ReadSentence(); // To read the length and words of the sentence 
	void displaySentence(); //Display Sentence
	bool operator == (const Sentence &) const;
	~Sentence();
};
Sentence::Sentence(){
	SentenceLength=0;
}
void Sentence::ReadSentence(){
	cout<<"Enter the number of words in the sentence: ";
	cin>>SentenceLength;

	cout<<"Write the sentence: ";
	for(int i=0; i<SentenceLength; i++)
		cin>>words[i];
}
bool Sentence::operator==(const Sentence &obj) const{
	if(SentenceLength==obj.SentenceLength)
		for(int i=0; i<SentenceLength; i++)
		{
			if(words[i] != obj.words[i])
				return false;
		}
	else
		return false;

		return true;
}
Sentence::~Sentence(){cout<<"Deleted"<<endl;}

int main()
{
	Sentence S1, S2;
	S1.ReadSentence();
	cout<<endl;
	S2.ReadSentence();

	if(S1==S2)
		cout<<"S1 and S2 are equals"<<endl;
	else
		cout<<"S1 and S2 are not equal"<<endl;

	return 0;
}

كتبت فقط اللي احتاجه للسؤال، displaySentence ما كتبتها لأن ما طلب مني السؤال استخدامها
إذا فيه نقطة معينة ما فهمتيها بالحل قولي وإن شاء الله راح اشرح لج.
 
ممكن أحد يوضح ليي هذا
مضيع حدي مادري شنو السالفة

Write a recursive function named Series that takes as parameter an integer i. The function should compute and return the result of the following series:
Series(i)= 1 + 2 + 3+ …..+ (i-1)+ i​
​
Write a recursive function to implement the sequential search. the function take as parameters an array of integers (array),an integer (key), and two integers (first and Last) representing the first and last index of the array. the function should search and return the position of the first occurrence of key in the array. if key does not exist (hint: first>last) the function should return -1.
int search(int array[], int key, int first, int last);
 

​
أحد يصحح حل السؤال ضرووووووري​


UT601.jpg






PHP:
#include<iostream>
using namespace std;
class TDate
{
 friend bool operator == (TDate& , TDate&);
private:
 int Day;
 int Month;
 int Year;
public:
 TDate(int D=1,int M=1, int Y=1900);
 void SetTDate(int,int,int); // not required
 void print();
 bool operator<(TDate&);
};
TDate :: TDate(int D,int M, int Y)
{
 Day = D;
 Month = M;
 Year = Y;
}
void TDate :: SetTDate(int D,int M, int Y)
{
 Day = D;
 Month = M;
 Year = Y;
}
void TDate::print()
{
 cout << Day << "/" << Month << "/" << Year;
}
bool TDate :: operator<(TDate& D1) // 
{ 
if(D1.Year < Year)
 return true;
else if (D1.Year ==Year && D1.Month <Month)
 return true;
else if (D1.Year ==Year && D1.Month ==Month && D1.Day <Day)
 return true;
else return false;
}
bool operator == (TDate& D1, TDate& D2)
{
 if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day == D2.Day)
  return true;
 else return false;
}
int main()
{
 TDate DD1,DD2 ,DDD1,DDD2;
 DD1.SetTDate(1,1,2013); //DD2=(1/1/1990) by defult
 if( DD1 < DD2)
  cout << " Date 1 is first " << endl;
 else 
  cout << "Date 2 is fisrst " << endl;

 DDD1.SetTDate(1,1,1900); //non-member
 if (DDD1 == DDD2)
  cout << "They are equal " << endl;
 return 0;
}




فنككش الأوفر لودنغ غلط :|

شلون اقارنهم ثنينهم و ما يصير احط ثنين براميترز!؟
​

PHP:
if(D1.Year < D2.Year)
 return true;
else if (D1.Year == D2.Year && D1.Month < D2.Month)
 return true;
else if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day < D2.Day)
 return true;
else return false;
 
Hw RECURSION

Write a recursive function named recursiveMin that takes three parameters, which are an array
of integers, and two integers first and last representing the beginning index and ending index of
the array.
The prototype of the function is: int recursiveMin (int a[], int first, int last);
The function should return the value of Minimum element in the array by finding a middle point
in the array call it middle. Recursively find the Min of the top half of the array, also Recursively
find the Min of the bottom half of the array, then return the Minimum of these two numbers.
Use only the recursive Minimum algorthim specified above.
No loops should be used
​
ممكن مساعده في حل الاسايمنت واكون شاكرة لكم :sad_1:.
 

​
أحد يصحح حل السؤال ضرووووووري





PHP:
#include<iostream>
using namespace std;
class TDate
{
 friend bool operator == (TDate& , TDate&);
private:
 int Day;
 int Month;
 int Year;
public:
 TDate(int D=1,int M=1, int Y=1900);
 void SetTDate(int,int,int); // not required
 void print();
 bool operator<(TDate&);
};
TDate :: TDate(int D,int M, int Y)
{
 Day = D;
 Month = M;
 Year = Y;
}
void TDate :: SetTDate(int D,int M, int Y)
{
 Day = D;
 Month = M;
 Year = Y;
}
void TDate::print()
{
 cout << Day << "/" << Month << "/" << Year;
}
bool TDate :: operator<(TDate& D1) // 
{ 
if(D1.Year < Year)
 return true;
else if (D1.Year ==Year && D1.Month <Month)
 return true;
else if (D1.Year ==Year && D1.Month ==Month && D1.Day <Day)
 return true;
else return false;
}
bool operator == (TDate& D1, TDate& D2)
{
 if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day == D2.Day)
  return true;
 else return false;
}
int main()
{
 TDate DD1,DD2 ,DDD1,DDD2;
 DD1.SetTDate(1,1,2013); //DD2=(1/1/1990) by defult
 if( DD1 < DD2)
  cout << " Date 1 is first " << endl;
 else 
  cout << "Date 2 is fisrst " << endl;

 DDD1.SetTDate(1,1,1900); //non-member
 if (DDD1 == DDD2)
  cout << "They are equal " << endl;
 return 0;
}




فنككش الأوفر لودنغ غلط :|

شلون اقارنهم ثنينهم و ما يصير احط ثنين براميترز!؟


PHP:
if(D1.Year < D2.Year)
 return true;
else if (D1.Year == D2.Year && D1.Month < D2.Month)
 return true;
else if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day < D2.Day)
 return true;
else return false;

دائما عندي مشاكل في قرائة كود مو انا اللي كاتبنه =/

على أي حال اتمنى ان هذا الجواب اللي تحتاجه

NOTE: أي سطر مكتوب جنبه كومنت EDITED هذا اللي مغير او مكتوب

PHP:
#include
<iostream>

using
 namespace std;

class
 TDate

{

 
friend bool operator == (TDate& , TDate&);

private
:

 
int Day;

 
int Month;

 
int Year;

public
:

 TDate(
int D=1,int M=1, int Y=1900);

 
void SetTDate(int,int,int); // not required

 
void print();

 
bool operator<(TDate&);

};

TDate :: TDate(
int D,int M, int Y)

{

 Day = D;

 Month = M;

 Year = Y;

}

void
 TDate :: SetTDate(int D,int M, int Y)

{

 Day = D;

 Month = M;

 Year = Y;

}

void
 TDate::print()

{

 cout << Day << 
"/" << Month << "/" << Year;

}

bool
 TDate :: operator<(TDate& D2) // EDITED

{ 

if
(Year < D2.Year)//EDITED

 
return true;

else
 if (Year ==D2.Year && Month <D2.Month)//EDITED

 
return true;

else
 if (Year ==D2.Year && Month ==D2.Month && Day <D2.Day)//EDITED

 
return true;

else
 return false;

}

bool
 operator == (TDate& D1, TDate& D2)

{

 
if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day == D2.Day)

  
return true;

 
else return false;

}

int
 main()

{

 TDate DD1,DD2 ,DDD1,DDD2;

 DD1.SetTDate(1,1,2013); 
//DD2=(1/1/1990) by defult //It's 1900 not 1990! //EDITED

 
if( DD1 < DD2)

  cout << 
" Date 1 is first " << endl;

 
else if (DD2<DD1)//EDITED

  cout << 
"Date 2 is fisrst " << endl;//EDITED

 
else//EDITED

     cout<<
"neither"<<endl;//EDITED


 DDD1.SetTDate(1,1,1900); 
//non-member

 
if (DDD1 == DDD2)

  cout << 
"They are equal " << endl;

 
else//EDITED

     cout<<
"they are not equal"<<endl;//EDITED

 
return 0;}
 
  • Like
التفاعلات: FHJ
دائما عندي مشاكل في قرائة كود مو انا اللي كاتبنه =/

على أي حال اتمنى ان هذا الجواب اللي تحتاجه

NOTE: أي سطر مكتوب جنبه كومنت EDITED هذا اللي مغير او مكتوب

PHP:
#include
<iostream>

using
 namespace std;

class
 TDate

{

 
friend bool operator == (TDate& , TDate&);

private
:

 
int Day;

 
int Month;

 
int Year;

public
:

 TDate(
int D=1,int M=1, int Y=1900);

 
void SetTDate(int,int,int); // not required

 
void print();

 
bool operator<(TDate&);

};

TDate :: TDate(
int D,int M, int Y)

{

 Day = D;

 Month = M;

 Year = Y;

}

void
 TDate :: SetTDate(int D,int M, int Y)

{

 Day = D;

 Month = M;

 Year = Y;

}

void
 TDate::print()

{

 cout << Day << 
"/" << Month << "/" << Year;

}

bool
 TDate :: operator<(TDate& D2) // EDITED

{ 

if
(Year < D2.Year)//EDITED

 
return true;

else
 if (Year ==D2.Year && Month <D2.Month)//EDITED

 
return true;

else
 if (Year ==D2.Year && Month ==D2.Month && Day <D2.Day)//EDITED

 
return true;

else
 return false;

}

bool
 operator == (TDate& D1, TDate& D2)

{

 
if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day == D2.Day)

  
return true;

 
else return false;

}

int
 main()

{

 TDate DD1,DD2 ,DDD1,DDD2;

 DD1.SetTDate(1,1,2013); 
//DD2=(1/1/1990) by defult //It's 1900 not 1990! //EDITED

 
if( DD1 < DD2)

  cout << 
" Date 1 is first " << endl;

 
else if (DD2<DD1)//EDITED

  cout << 
"Date 2 is fisrst " << endl;//EDITED

 
else//EDITED

     cout<<
"neither"<<endl;//EDITED


 DDD1.SetTDate(1,1,1900); 
//non-member

 
if (DDD1 == DDD2)

  cout << 
"They are equal " << endl;

 
else//EDITED

     cout<<
"they are not equal"<<endl;//EDITED

 
return 0;}
[/QUOTE

شككككككراً :)
​
 
السلام عليكم
الاساسيمت 11 الهوم اساسمنت

PHP:
Hw RECURSION
 
Write a recursive function named recursiveMax that takes three parameters, which are an array
of integers, and two integers first and last representing the beginning index and ending index of
the array.
The prototype of the function is: int recursiveMax (int a[], int first, int last);
The function should return the value of maximum element in the array by finding a middle point
in the array call it middle. Recursively find the max of the top half of the array, also Recursively
find the max of the bottom half of the array, then return the maximum of these two numbers.
Use only the recursive maximum algorthim specified above.
No loops should be used.


الحل :


PHP:
#include <iostream>
using namespace std;
int recursiveMax(int a[],int first,int last)
{
int mid=(first+last)/2;
static int max1=0;
static int max2=0;
static bool found=false;
if (last>mid && !found)
{
if(a[last-1]>max1)
max1=a[last-1];
return recursiveMax(a,++first,--last);
found=true;
}
if(first>0)
{
if(a[first-1]>max2)
max2=a[first-1];
return recursiveMax(a,--first,last);
}
if(max1>max2)
return max1;
else
return max2;
}
void main(){
const int size=8;
int list[size]={1,2,3,4,5,6,7,8};
int first=0;
int last=size;
cout<<recursiveMax(list,first,last);
}


التغيير مطلوب :nosweat:

لا احد ينقله نقل يرحم امكم :bleh:

ولين فيه اخطاء يخبرنا , بدون فلسفة :msn-wink:

نسالكم الدعاء

اهم شي الدعاء


في امان الله:rolleyes2:
 
رحم الله والديك ابو حسين ما قصرت

يعطيك العافية يا رب :)
 
فنككش الأوفر لودنغ غلط :|

شلون اقارنهم ثنينهم و ما يصير احط ثنين براميترز!؟

​

PHP:
if(D1.Year < D2.Year)
 return true;
else if (D1.Year == D2.Year && D1.Month < D2.Month)
 return true;
else if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day < D2.Day)
 return true;
else return false;
[/QUOTE]

هذا الكود ، مكتوب بأستخدام friend function
ونسميها non-member function

يعني نحط كـ براميتر 2 objects

اما اذا كانت function عاديه واللي نسميها member function
فـ نكتب بهالطريقة (ع سبيل المثال)
year == D2.Year


اما يقارن واحنا مطرشين براميتر واحد
فهذي شغلة compiler يعني هو يعتبر الاولي current object والثاني يعتبر بارميتر
object3=object1+object2

وفي الfriend يعتبرهم اثنينهم باراميتر لان اوردي الfunction هذي عاديـة وكأن ماليها علاقه بالكلاس
مجرد ليها تصريح بأستخدام class ومحتوياته
 
  • Like
التفاعلات: FHJ


Write a Recursive function that replace negative numbers with zero in array A. Void Replace(int *p, int n) where p is pointer to array A. For example if array A = { 1,-2,8,-5,9,3,-5}. After the call A will be = {1,0,8,0,9,3,0}


:RpS_blink::sad_1: HELP ME :RpS_blink::sad_1:
 
فنككش الأوفر لودنغ غلط :|

شلون اقارنهم ثنينهم و ما يصير احط ثنين براميترز!؟

​

PHP:
if(D1.Year < D2.Year)
 return true;
else if (D1.Year == D2.Year && D1.Month < D2.Month)
 return true;
else if (D1.Year == D2.Year && D1.Month == D2.Month && D1.Day < D2.Day)
 return true;
else return false;

هذا الكود ، مكتوب بأستخدام friendfunction
ونسميها non-member function

يعني نحط كـ براميتر 2 objects

اما اذا كانت function عاديه واللي نسميها member function
فـ نكتب بهالطريقة (ع سبيل المثال)
year == D2.Year


اما يقارن واحنا مطرشين براميتر واحد
فهذي شغلة compiler يعني هو يعتبر الاولي current object والثاني يعتبر بارميتر
object3=object1+object2

وفي الfriend يعتبرهم اثنينهم باراميتر لان اوردي الfunction هذي عاديـة وكأن ماليها علاقه بالكلاس
مجرد ليها تصريح بأستخدام class ومحتوياته
[/QUOTE]
كنت مضيعة و بعدين استوعبت الموضوع:nosweat:
شُكككراً :RpS_thumbsup:
​
 
Write a Recursive function that replace negative numbers with zero in array A. Void Replace(int *p, int n) where p is pointer to array A. For example if array A = { 1,-2,8,-5,9,3,-5}. After the call A will be = {1,0,8,0,9,3,0}


:RpS_blink::sad_1: HELP ME :RpS_blink::sad_1:



PHP:
#include<iostream>
using namespace std;
void Replace(int *p, int n) 
{
   if (n != 0)
   {
 if (*p < 0 )
 {*p = 0;}
  
 cout << *p << " ";
 p++;
 Replace(p,n-1);
   }
}
 

int main()
{
 int *p;
 int A[] = { 1,-2,8,-5,9,3,-5};
 p = &A[0];
 Replace(p,7);  // 7  the number of elements in A
     
 
return 0;
}
 
ممكن أحد يوضح ليي هذا
مضيع حدي مادري شنو السالفة

Write a recursive function named Series that takes as parameter an integer i. The function should compute and return the result of the following series:
Series(i)= 1 + 2 + 3+ …..+ (i-1)+ i​
Write a recursive function to implement the sequential search. the function take as parameters an array of integers (array),an integer (key), and two integers (first and Last) representing the first and last index of the array. the function should search and return the position of the first occurrence of key in the array. if key does not exist (hint: first>last) the function should return -1.
int search(int array[], int key, int first, int last);

...
 
من يقدر يشرح ليي الـ recursion ضروري :tears:
 
ممكن أحد يوضح ليي هذا
مضيع حدي مادري شنو السالفة

Write a recursive function named Series that takes as parameter an integer i. The function should compute and return the result of the following series:
Series(i)= 1 + 2 + 3+ …..+ (i-1)+ i​
Write a recursive function to implement the sequential search. the function take as parameters an array of integers (array),an integer (key), and two integers (first and Last) representing the first and last index of the array. the function should search and return the position of the first occurrence of key in the array. if key does not exist (hint: first>last) the function should return -1.
int search(int array[], int key, int first, int last);
السؤال في فنكشنين الاولى لو تدخل له رقم 3 يجمع 1+2+3 لو تدخل رقم 6 يجمع 1+2+3+4+5+6
الفنكشن الثانية اريه انت تدخل رقم موجود في الاريه اذا موجود يرجع لك مكان الرقم اذا مو موجود يرجع -1
مثال الاريه {1,2,3,4,5,6,7,8} فرضا يدور رقم 6 المفروض يرجع لك 5 لو دخلت 9 يرجع -1
 
Write a recursive function named printAlternate that takes two parameters, which are an array of integers, and the array size. The array size is the current number of elements stored in the array. The prototype of the function is: void printAlternate (int a[], int size);
The function should display the numbers stored in the array starting from the beginning alternatively. Which means printing one number and skip the next number, this process should be repeated until the end of the array is reached. Example: if the array contains {10,20,15,18,5}; The output is: 10 15 5



A palindrome is a string that is spelled the same way forwards and backwards. Some examples of palindromes are: “radar”, “able was I ere I saw elba”, “non”. Write a recursive function that tests whether a word is a palindrome or not. The function should take as parameters a c-string, and two integers. The first integer represents the beginning index of the string and the other one represents the last index of the string. The function should also return an integer, where 1 represents a palindrome, and 0 represents not a palindrome. The following is the function prototype: int testPalindrome(char[], int, int);




Write a recursive function named outputfunct. The function takes one argument which is an integer value called x. The function should print the plus sign (+) x times, followed by the hash sign (#) x times. Do NOT use any loops. Do NOT use any variables other than x.
The prototype of the function is: void outputfunct(int x);
Examples: If x=8 the ouput is: + + + + + + + + # # # # # # # #
If x=2 the ouput is: + + # #


من يقدر يحل للي هالثلاث الاسئلة شعب واكون شاكر ليه
 
ممكن مساعدة في سؤال :( ITCS102 104

ممكن مساعدة في حل سؤال ضروري حق باجر :99:


Write a recursive function named recursiveMax that takes three parameters, which are an array
of integers, and two integers first and last representing the beginning index and ending index of
the array.
The prototype of the function is: int recursiveMax (int a[], int first, int last);
The function should return the value of maximum element in the array by finding a middle point
in the array call it middle. Recursively find the max of the top half of the array, also Recursively
find the max of the bottom half of the array, then return the maximum of these two numbers.
Use only the recursive maximum algorthim specified above.
No loops should be used​
 
int recursiveMax (int a[], int first, int last){

int max=a[first];
if (max<a[first])
max=a[first]

if (first==last)
return max;
esle
recursiveMax (int a[], int first+1, int last);

}



اتوقع جدي .. مو متأكد .. مسامحة على الجواب السريع
:nosweat:
 
عودة
أعلى أسفل