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

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

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

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

^^


نعرف pointer داخل الـ function
مثلاً char * P;
نسوي سيرج عادي,
و اذا حصلنا الحرف,
نسوي
P=arr+i;
و نسوي return حق الـ P

بس
​



أنا ما أعرف للبوينتر شي !!

لأني كله غايبة .. بشوف الشرح اللي خاله الإخو .. Kaito KiD

بس طبعاً مو الحين .. لأن ما في وقت كلش .. كل إجازة تجي .. يطلعونها من عيونه .. حسبيّ الله عليهم ..​
 
السلام عليكم.....

عندي سؤال يتعلق بـــ ITCS102 ..
السؤال يتعلق بـــ Class و بــــStruct

احد يقدر احله وبكوون شااااكر له ..

او على الاقل افهمني اياه :)


السؤال


Consider the following structure Date
struct Date
{
int month;
int day;
int year;
};


Use the class EmployeeInfo that uses the Date structure in solving the problem below
class EmployeeInfo
{
private:
int ID;
string firstname;
string lastname;
double salary;
Date hiredate;
public:
void setInfo(int, string, string, double, date);
int getID() const;
string getFname() const;
string getLname() const;
double getSalary() const;
Date getDate();
EmployeeInfo ();
EmployeeInfo (int,string,string,double,Date);
};


1. Write the code for each member functions.
2. Write a program that defines array of EmployeeInfo of size 15. The program should ask the user to enter the data of those employees and store them in the array. Then the program displays the information of employee that has largest salary.​

في حال عدم وضوح السؤال , يوجد نسخة له في المرفقات
 

المرفقات

هذه محاولتي في حله


void EmployeeInfo::setInfo(int id, string fn, string ln, double S, Date hd)
{
ID=id;
firstname=fn;
lastname=ln;
salary=S;
hiredate=hd;
}


int EmployeeInfo::getID() const
{
return ID;

}

string EmployeeInfo::getFname() const
{
return firstname;

}

string EmployeeInfo::getLname() const
{
return lastname;

}

double EmployeeInfo::getSalary() const
{
return salary;

}

Date EmployeeInfo::getDate()
{
return hiredate ;

}

EmployeeInfo::EmployeeInfo()
{
ID=0;
firstname=" ";
lastname=" ";
salary=0.0;

}

EmployeeInfo::EmployeeInfo(int id,string fn,string ln,double S,Date hd)
{
setInfo(id,fn,ln,S,hd);

}

int main()
{
int i;
EmployeeInfo arr[15];
for(i=0;i<15;i++)
cout<<"ENTER";
cin>>arr;

}
​
 
^^

صح الحل تقريباً,, :shiny:
بس.
في الـ constructor لازم تضيف شي واحد
EmployeeInfo::EmployeeInfo()
{
ID=0;
firstname=" ";
lastname=" ";
salary=0.0;

}

هو الـ defualt values للـ date
يعني بس جذي,

PHP:
hiredate.month=
hiredate.day=
hiredate.year=


++

الـ main
مو جذي,
لازم تسوي cin حق كل شي,
يعني تعرف لك variable من نوع Date
و 3 integer
و بعدين في كل element من الـ array
تسوي cin لهم,
و تسوي
arr.set( ...... )
النقط هم الـ variables اللي عرفتهم

​
 
قصدك جذي...

int main()
{
EmployeeInfo arr[15];
Date a; int d,m,y;

for(int i=0;i<15;i++){
cout<<"Enter";
cin>>a.day;
cin>>a.month;
cin>>a.year;

arr.setInfo(d,m,y);}

}
​


سويت جذي طلع لي error
 
التعديل الأخير:
قصدك جذي...
int main()
{
EmployeeInfo arr[15];
Date a; int z,x,c;

for(int i=0;i<15;i++){
cout<<"Enter";
cin>>a;
cin>>z;
cin>>x;
cin>>c;
arr.setInfo(a,z,x,c)}

}

سويت جذي طلع لي error


ما يصير تسوي cin حق object من نوع struct بهذي الطريقة,,
سو جذي
cin>>a.month;
cin>>a.year;
cin>>a.day;
و بعدين حط الـ a في الـ set مثل مو مسوي انت الحين​
 
تم التعديل على الرد :)
 
^^
مسماحة فكرت الـ private data الباقيين من نوع integer,,
عرف في الـ main
الـ date أوكي, سويته

int b;
string c,d
double e;

و داخل الـ for
سو لهم cin
و سو call للـ set و حطهم كـ parameters

setInfo(a,b,c,d,e);​
 
جذي صح
int main()
{
EmployeeInfo arr[15];
Date a;
int d;
string m,y;
double x;

for(int i=0;i<15;i++){
cout<<"Enter";
cin>>a.day;
cin>>a.month;
cin>>a.year;

arr.setInfo(d,m,y,x,a);}

}
:)

بس بالنسبة الى

Then the program displays the information of employee that has largest salary.
اشلون اصير

مسامحة تعبناك
 
هل ممكن كتابة

double max=0;

for(int j=0;j<15;j++)
if(arr[j].getSalary()>max)
max=arr[j].getSalary;}​
 
^^
المطلوب هني هو الـ index
لأن المعلومات كلها مطلوبة
فـ
احفظ الـ index في الـ max
و المقارنة
if(arr.getSalary() > arr[max].getSalary())
max=i;

و بعدين سو print للمعلومات اللي في الـ array ه


for(int i=0;i<15;i++){
cout<<"Enter";
cin>>a.day;
cin>>a.month;
cin>>a.year;

arr.setInfo(d,m,y,x,a);}

سو cin
حق الـ d و الـ m و الـ y و الـ x
داخل الـ for loop


تم تعديل الرد,,,
​
 
سويت جذي وماضبط

int main()
{
EmployeeInfo arr[15];
Date a;
int d;
string m,y;
double x;

for(int i=0;i<15;i++){
cout<<"Enter";
cin>>a.day;
cin>>a.month;
cin>>a.year;
cin>>d;
cin>>m;
cin>>y;
cin>>x;
arr.setInfo(d,m,y,x,a);}


int max;

for(int j=0;j<15;j++)
if(arr[j].getSalary() > arr[max].getSalary())
max=j;

cout<<arr[max].getSalary()<<endl;
cout<<arr[max].getLname()<<endl;
cout<<arr[max].getFname()<<endl;
cout<<arr[max].getID()<<endl;
}
​
 
التعديل الأخير:
اوبس ضبط , نسيت احط system pause

بس Date اشلون انسوي ليه cout ???
 
^^
عندك هالفنكشن
Date getDate();
سو له get في variable جديد,
يعني
Date New = arr.getDate();
و بعدين,,
cout<<New.day<<New.month<<New.year
​
 
تم انهاء السؤال بنجاح :)

مشكوور اخوي على المساعدة , ماكنت بقدر احله من دون مساعدتك.

الله اوفقك انشاءالله

شكرا
 
شوفو هذا السؤال شيرت فيه شوي ( جزء من الأسايمت )

Write a function named FirstOcurence that takes as parameters an array of char(c-strings) and a character c. The function should return a pointer that point to the first occurrence of c in the string. If c is not found the function should return NULL.
The function prototype is: char* FirstOccrence(char arr[], char c)

:confused: هل يقصدون ان ندور على نفس الc في الأري و نخلي البوينتر بوينت الى

المكان الي جافه فيه لو ويش !!!
 
^^
هالسؤال احسه ناقص شوي :confused:
نتكلم عن array احنا,
يعني الـ size مو معروف أبداً
ما بنسوي allocate حق memory في الـ function احنا,
يعني الـ parameters لازم يكون من ضمنهم الـ size
=================================

أو ان احنا نستخدم الـ C-String اللي ما درسناه احنا الكورس اللي طاف في الـ 101 :confused:
بما انه char
فلازم نجوف جم طوله,


تقدرون تستخدمون هالفنكشن,,

strlen
و لازم تسوون include للـ cstring

و بعدين, المطلوب في السؤال هو,
ان نجوف أول ظهور للحرف,
نسوي قيمة الـ pointer هي الـ adress لأول ظهور للحرف
يعني
ptr=&arr;
داخل if حق اختبار الحرف طبعاً
و break
و نسوي return للـ ptr
اللي هو pointer من نوع char
​
 
مساعده

عدي اسايمنت
:sad_1:
ولازم اسلمه باجر:icon1366:
ياريت توضحون ايي اشلون احله:surrender:
موجود في المرفق
 

المرفقات

  • ass7.doc
    ass7.doc
    24 KB · المشاهدات: 69
عودة
أعلى أسفل