Jump to content
منتدى البحرين اليوم

.-.المواضيـــع المتعلقــة بمقررITCS102.-.


Recommended Posts

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

بل .. محد حله ...

ع العموم ذي الحل يمكن احد يبيه تفضلووو...

 

 

 

include <iostream>

using namespace std;

class date

{

private:

int day;

int month;

int year;

public:

date(){

day=1;

month=1;

year=1980;}

void set(int d,int m, int y){

if(d>=1 && d<=31)

day=d;

else

day=1;

if(m>=1 && m<=12)

month=m;

else

month=1;

if(y>=1980 && y<=2010)

year=y;

else

year=1980;}

void get(int &d, int & m, int &y){

d=day;

m=month;

y=year;}

void print(){

char ch='/';

if (day<10)

cout<<"0"<<day;

else

cout<<day;

cout<<ch;

if (month<10)

cout<<"0"<<month;

else

cout<<month;

cout<<ch;

cout<<year;}

bool operator==(const date & d){

return (day==d.day && month==d.month && year==d.year);}

};

bool operator==(date x,date y){

int d1,m1,y1;

int d2,m2,y2;

x.get(d1,m1,y1);

y.get(d2,m2,y2);

return (d1==d2 && m1==m2 && y1==y2);}

void main(){

date myDate;

date yourDate;

myDate.set(27,3,1988);

yourDate.set(21,12,1988);

if (myDate==yourDate)

cout<<"The dates are similar"<<endl;

else

cout<<"The dates are different"<<endl;

if( (operator==(myDate,yourDate))==1)

cout<<"The dates are similar"<<endl;

else

cout<<"The dates are different"<<endl;

myDate=yourDate;

if (myDate==yourDate)

cout<<"The dates are similar"<<endl;

else

cout<<"The dates are different"<<endl;

if( (operator==(myDate,yourDate))==1)

cout<<"The dates are similar"<<endl;

else

cout<<"The dates are different"<<endl;}

Link to comment
Share on other sites

بعدين انشالله بنزل اسايمنت 8 السؤال والحل عقب ماكمله ومسامحه ع التأخير
Link to comment
Share on other sites

ذي السؤاال حق اسايمنت 8 ::

 

 

Write a template class that manage a list of elements, the class has two private members the list and its size, and two member functions which are FindMax() and Print().

 

Write the main function to create a list of integers and a list of float numbers using the above created class, then find the maximum number in each list.

 

 

 

وذي الحل ::

 

 

#include< iostream>

using namespace std;

template <class T>

class element {

private:

T list [10];

int size;

 

public:

element( int N){

size = N;

for( int i = 0; i<N; i++)

cin>> list ;}

T FindMax( ){

T max= list [0];

for(int i=1;i<size;i++)

if( list >max)

max = list ;

return max;

}

void Print(){

for( int i=0;i<size;i++)

cout<<list ;

}

};

int main(){

 

element <int> list1(5);

element <float> list2(9);

cout<<list1.FindMax( );

cout<<list2.FindMax( );

void Print( );

return 0;

}

 

 

 

انشالله ما تأخرت عليكم وانشالله تستفيدووون

Link to comment
Share on other sites

  • 2 weeks later...

اسايمنت 9::

 

 

Write a recursive function CountKey that counts and returns the number of occurrences of a key value in an array of integer numbers. The function accepts as parameters an array of integer numbers, the array size, and an integer key value. The function finds the numbers of times the key value occurred in the array.The function prototype is:

int CountKey(int arr[], int size, int key);

Example:

If the array contains:

12 2 30 2 2 12 1 2

and the key value is 2,

the function CountKey should return 4

 

 

 

الجوااااااااب::

 

#include <iostream>

using namespace std;

int CountKey(int arr[], int size, int key)

{

if(size ==0)

return 0;

if(arr[size-1]==key)

return 1+CountKey(arr,size-1, key);

else

return CountKey (arr, size-1, key);

}

int main()

{

int arr[15]={12, 2, 30, 2, 2, 12 , 1, 2};

int size=7;

int key;

 

cout<<"The Count Key is"<<CountKey(arr, size, key)<<endl;

 

return 0;

}

Link to comment
Share on other sites

  • 1 month later...
Guest
This topic is now closed to further replies.

×
×
  • Create New...