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

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

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

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

ممكن الحل مال هدا
Write a program that reads student's names followed by their ID and test scores. student data should be stored in a struct variable of type studenttype which has 3 members: name ,ID, and test score. Declare array ITCS104students of size 5 of elements of type studenttype. add the following functions to your program:
* a function to read all members of your array.
* a function to print name and ID of the student with the lowest test score.

اني بعد ابي مساعده في هالسؤال رحم الله والديكم

ملاحظه ، السؤال يقول ان اطبع الاسم والID واقل درجه
معنى هالكلام ان score في struct نوعه array
والسؤال مو كاتب هالشي ( هذي اولاً )
ثانيا : لازم function ثالثه عشان تطلع لنا اقل درجه
وهالشي مو مكتوب بعد
فـ انا سويت المطلوب بس ، لكن في طباعه اقل درجه خليت يطبع الدرجه نفسها
اذا تبون ما التزم بالمطلوب بعدله وقت أخر
PHP:
#include<iostream>
#include<string>
using namespace std;

struct studentType {
string name;
long ID;
int testScore;      
    };
       
           
       void Read(studentType &arr)
       {
            cout<<"Enter name,ID and test Score = ";
            cin>>arr.name>>arr.ID>>arr.testScore; 
            }
            
   
      void Print(studentType &arr)
       {
            cout<<"Name = "<<arr.name<<endl;
            cout<<"ID = "<<arr.ID<<endl;
            cout<<"Test Score = "<<arr.testScore<<endl;
            cout<<endl;
            }

int main()
{

studentType ITCS104student[5];

for(int i=0 ;i<5 ;i++)
Read(ITCS104student[i]);

for(int i=0 ;i<5 ;i++)
Print(ITCS104student[i]);

system("pause");
    return 0;
}
 
@itcs student

اخوي بغيتك تدرسني الفنكشن وشلون نسوي لهم كوول فب المين لان وايد معقد عليه بصراحه وماني فاهم فيه شي وكل ساعه بعطيك تعبك

حده مهم لان دةرت المعاهد ومالقيت .. كلهم راحوا جدام في الماده! !

الستركجر والكلاس كلشي تمان بس عندي مشكله في الفنكشن معقدتني

كلمني عالخاص ماعليك امر ولك مني على كل ساعه كثر ماتبي ..

هلا اخوي
ان شاء الله بقدم المساعده لكم باللي الله يقدرني عليه

والأجر على الله
 
ملاحظه ، السؤال يقول ان اطبع الاسم والID واقل درجه
معنى هالكلام ان score في struct نوعه array
والسؤال مو كاتب هالشي ( هذي اولاً )
ثانيا : لازم function ثالثه عشان تطلع لنا اقل درجه
وهالشي مو مكتوب بعد
فـ انا سويت المطلوب بس ، لكن في طباعه اقل درجه خليت يطبع الدرجه نفسها
اذا تبون ما التزم بالمطلوب بعدله وقت أخر
PHP:
#include<iostream>
#include<string>
using namespace std;

struct studentType {
string name;
long ID;
int testScore;      
    };
       
           
       void Read(studentType &arr)
       {
            cout<<"Enter name,ID and test Score = ";
            cin>>arr.name>>arr.ID>>arr.testScore; 
            }
            
   
      void Print(studentType &arr)
       {
            cout<<"Name = "<<arr.name<<endl;
            cout<<"ID = "<<arr.ID<<endl;
            cout<<"Test Score = "<<arr.testScore<<endl;
            cout<<endl;
            }

int main()
{

studentType ITCS104student[5];

for(int i=0 ;i<5 ;i++)
Read(ITCS104student[i]);

for(int i=0 ;i<5 ;i++)
Print(ITCS104student[i]);

system("pause");
    return 0;
}

استفسار عالسريع أخي مافهمت ليش خليت علامة refrence & في الفنكشن ثنتينهم
هل وجودهم مهم يعني قصدي انه اليوزر راح يدخل قيم عشوائية فما راح احتاجهم عشان أحفظ قيم من فنكشن الى المين ؟؟
 
عندي الكتاب .. بس مافهمت منه شي! ! لازم احد يشرح =(

عندك اليوتيوب بعد ..

ترى اذا ظليت تعتمد على الشرح بيضيع عليك الوقت .. حاول تعتمد على نفسك قد ما تقدر :smile2: ..

محد ينكر ان الشرح اليه دور في الاستيعاب ..
بس علشان الوقت لا يروح لازم دراسة ذاتية
:RpS_wink:

​
 
استفسار عالسريع أخي مافهمت ليش خليت علامة refrence & في الفنكشن ثنتينهم
هل وجودهم مهم يعني قصدي انه اليوزر راح يدخل قيم عشوائية فما راح احتاجهم عشان أحفظ قيم من فنكشن الى المين ؟؟
انا كنت امام خيارين
اما اسوي اللوب اللي بيتحرك على اندكس الArray ( داخل الfunction او خارجها )

اذا خليتها داخل لازم بطرش في ال parameter الاراي كامل يعني بكون شكلها جدي
PHP:
  Read(studentType arr[] )
بدون & > لان الarray اوردي هي by refrence

الخيار الثاني (اللي سويته)
اني اطرش كلاندكس بشكل منفصل
بهالحاله مثل ماشفت شكل الparameter
ف يعتبر الاندكس عباره عن متغير عادي ، مو مثل الarray
فـ وجود & مهم عشان انا بقرأ البيانات بالfunction وبرجع الmain بالبيانات نفسها
اذا ماخليت ال& بروح الfuction وبقرأ بيانات ومابصير عندك ايرور لكن وقت اللي يرجع الmain راح يفقد البيانات بسبب عدم وجود &

امم كيف قيم عشوائية وليش فرضت هالشي :) ؟
 
Write a function named averageQuiz1 that takes as parameter mySectionof type section. The function should return the average of first quiz for all students in the section



Write a function named topStudents that take as parameter: mySection of type section. The function should print the students’ names with quiz1 score greater than the average of quiz1 for all students. (Hint: use averageQuiz1 function to get the average of quiz1)

ممكن احد يساعدني في كتابة الـــ functions
 
^^
لو تكتبين السؤال كامل احسن
لان انا مادري الطلاب في array وكم عددهم وشغلات من هالقبيل
 
ممكن احد يشرحلي بس بالكلام شسالفه ال
class
???
 
ممكن احد يشرحلي بس بالكلام شسالفه ال
class
???
الكلاس عبارة عن library تسوينها على حسب رغبتج
مثل ما عندنا #include <string> و #include <cmath> وغيره من الـlibraries
هي شبيهة للكلاس مع functions جاهزة للاستخدام
مثلاً لو بنكتب st1.length() عشان نعرف طول الـstring.. المكتبة الخاصة بالـstring فيها فنكشن جاهزة تقوم بهذي الوظيفة

نفس الشي الـclasses، عبارة عن libraries احنا نسويها
الـprivate عبارة عن المتغيرات اللي بتحطينها وما يصير تحددين لهم قيمة مبدئية، مجرد تعرفين المتغيرات الخاصة بالكلاس
والـpublic عبارة عن الـprototype للfunctions للإستخدام العام، (اليوزر بإمكانه يستخدمها)

هذي فكرة الكلاس بشكل عام
 
^^
لو تكتبين السؤال كامل احسن
لان انا مادري الطلاب في array وكم عددهم وشغلات من هالقبيل

Struct (Records)
Part 1

a. Write the definition of a structure type named studentthat includes the following members: student ID, name, and an array of size five to represent students’ quiz grades.

b. Write a function named getData that takes a parameter X of type student. The function should read the data of X.


c. Write a function named printData that takes a parameter X of type student. The function should display the data of X.

d. Write a function named calculateAvg that takes a parameter X of type student. The function should calculate and return the average of Xquiz grades.


e. Write a function named equal that takes two parameters X, and Y of type student. The function should return true if the Quiz array of X has the same content as the quiz grades of Y, otherwise the function should return false.

f. Write a main function to test your functions.
 

Assignment
Part 2

Complete the previous exercise to include the following:
a. Write the definition of a structure type named section, which includesthe following components: section number (secNo) of type int, number of students in the section (noStudents) of type int, room number (roomNo) of type string, and an array (studentsList) of type student of size 20.

b. Write a function named getData that takes as parameter: mySection of typesection. The function should prompt the user to enter the data of mySection.

c. Write a function named printData that takes as parameter mySection of type section. The function should print the data of mySection.

d. Write a function named averageQuiz1 that takes as parameter mySectionof type section. The function should return the average of first quiz for all students in the section

e. Write a function named topStudents that take as parameter: mySection of type section. The function should print the students’ names with quiz1 score greater than the average of quiz1 for all students. (Hint: use averageQuiz1 function to get the average of quiz1)

f. Write a main program to test your functions.

​
حل Part 1
#include<string>
#include<iostream>
using namespace std;
struct student {
long studentID;
string name;
float quizGrades[5];
};
void getData (student & x)
{
cout<<"please enter studentID,name,quizGrades";
cin>>x.studentID>>x.name;
for (int i=0;i<5;i++)
cin>>x.quizGrades[5];
}
void printData(student &x )
{
cout<<"studentID"<<x.studentID<<endl<<"name"<<x.name<<endl<<"quizGrades"<<x.quizGrades;
}
double calculateAvg(student &x)
{
double sum=0;
for(int i=0;i<5;i++)
sum+=x.quizGrades;

return sum/5.0;
}
bool equal (student x,student y)
{
for(int i=0;i<5;i++)
if(x.quizGrades!=y.quizGrades)
return false;
return true;
}
int main()
{
student s1;
student s2;
getData(s1);
getData(s2);
cout<<"quizsAvg="<<calculateAvg;
if (equal(s1,s2)==true)
cout<<"all are the same";
else
cout<<"Not equal";

system("pause");
}

حل Part 2
a-b-c
struct section
{
int secNo;
int noStudents;
string roomNo;
int studentsList[20];
}
void getData (section & mySection)
{

cout<<"please enter secNo,noStudents,roomNo";
cin>>mySection.secNo>>mySection.noStudents>>mySection.roomNo;

for (int i=0;i<20;i++)
cin>>mySection.studentsList[20];
}
void printData(section & mySection)
{
cout<<"secNo"<<mySection.secNo<<endl<<"noStudents"<<mySection.noStudents<<endl<<"roomNo"<<mySection.roomNo<<endl<<"studentsList"<<mySection.studentsList;
}

ابي احد يساعدني في كتابة d & e functions
 
ممكن شرح تفصيلي لـــ الستركجر والكلاس اذا ماعليكم امر
 
انا كنت امام خيارين
اما اسوي اللوب اللي بيتحرك على اندكس الArray ( داخل الfunction او خارجها )

اذا خليتها داخل لازم بطرش في ال parameter الاراي كامل يعني بكون شكلها جدي
PHP:
  Read(studentType arr[] )
بدون & > لان الarray اوردي هي by refrence

الخيار الثاني (اللي سويته)
اني اطرش كلاندكس بشكل منفصل
بهالحاله مثل ماشفت شكل الparameter
ف يعتبر الاندكس عباره عن متغير عادي ، مو مثل الarray
فـ وجود & مهم عشان انا بقرأ البيانات بالfunction وبرجع الmain بالبيانات نفسها
اذا ماخليت ال& بروح الfuction وبقرأ بيانات ومابصير عندك ايرور لكن وقت اللي يرجع الmain راح يفقد البيانات بسبب عدم وجود &

امم كيف قيم عشوائية وليش فرضت هالشي :) ؟

اهاا صح كلامك
ههه ماعليك من كلامي شكلي تخربطت وجبت فكرة مالت سؤال غير اله هذي
موفقين جميعاً
 
اختي عاشقة الدموع

PART A
فيه اخطاء ، كتبته كامل من جديد
وفي الmain استخدمت كل الـ functions
عاد انتي شوفي شنو تبين تطبعين وشنو لا ، بس اللي عليش تعدلين في الmain


PHP:
#include<iostream>
#include<string>
using namespace std;

struct student {
long studentID;
string name;
float quizGrades[5];
};

void getData(student &X)
{
     cout<<"Enter student ID,name and quiz grades = "<<endl;
     cin>>X.studentID>>X.name;
     cout<<"Enter quiz grades = "<<endl;
     for(int i=0 ;i<5 ;i++)
     cin>>X.quizGrades[i];
     }
     
void PrintData(const student X)
{
     cout<<"Student ID = "<<X.studentID<<endl;
     cout<<"Student name = "<<X.name<<endl;
     cout<<"Student quiz grades = ";
     for(int i=0 ;i<5 ;i++)
     cout<<X.quizGrades[i]<<"  ";
     cout<<endl;
     }



float averageQuiz1 (student X)
{float avg;
      for(int i=0 ;i<5 ;i++)
      avg+=X.quizGrades[i];
      return avg/5;
      }
      
      bool equal(student X,student Y)
      {
             if(X.quizGrades[0] == Y.quizGrades[0] && X.quizGrades[1] == Y.quizGrades[1] && 
             X.quizGrades[2] == Y.quizGrades[2] && X.quizGrades[3] == Y.quizGrades[3] && 
             X.quizGrades[4] == Y.quizGrades[4] )
             return true;
      
             return false;
           }
           
int main()
{
    student X,Y;
    bool R;
    
    getData(X);
    getData(Y); 
    
    PrintData(X);
    cout<<"........................."<<endl;
    PrintData(Y);
      
   cout<<endl<<"avg of student X = "<<averageQuiz1(X)<<endl;
   cout<<endl<<"avg of student Y = "<<averageQuiz1(Y)<<endl;
   
   R=equal(X,Y);
   if(R)
   cout<<"Equal"<<endl;
   else
   cout<<"Not Equal"<<endl;
   
system("pause");
return 0;
}
 
وهذا Part 2
ملاحظه الfunctions مامسحت مايتعلق ب part 1 لان استخدمتهم في part 2
اللي فرق بس في main
استخدمت الmain بدون تقيّد بشي
انتي استخدميهم حسب ماتحبين

PHP:
#include<iostream>
#include<string>
using namespace std;
struct student {
long studentID;
string name;
float quizGrades[5];
};
struct section {
       int secNo;
       int noStudents;
       string roomNo;
       student studentsList[20];
       
       };
       
void getData(student &X)
{
     cout<<"Enter student ID,name and quiz grades = "<<endl;
     cin>>X.studentID>>X.name;
     cout<<"Enter quiz grades = "<<endl;
     for(int i=0 ;i<5 ;i++)
     cin>>X.quizGrades[i];
     }
     
void PrintData(const student X)
{
     cout<<"Student ID = "<<X.studentID<<endl;
     cout<<"Student name = "<<X.name<<endl;
     cout<<"Student quiz grades = ";
     for(int i=0 ;i<5 ;i++)
     cout<<X.quizGrades[i]<<"  ";
     cout<<endl;
     }
float averageQuiz1 (student X)
{float avg=0;
      for(int i=0 ;i<5 ;i++)
      avg+=X.quizGrades[i];
      return avg/5;
      }
      
     bool equal(student X,student Y)
     {
           if(X.quizGrades[0] == Y.quizGrades[0] && X.quizGrades[1] == Y.quizGrades[1] && 
            X.quizGrades[2] == Y.quizGrades[2] && X.quizGrades[3] == Y.quizGrades[3] && 
             X.quizGrades[4] == Y.quizGrades[4] )
             return true;
      
          return false;
       
          }
       
       //part 2   
void ReadData(section &mySection)
{
     cout<<"Enter section No. and # of students and room No. = "<<endl; 
     cin>>mySection.secNo>>mySection.noStudents>>mySection.roomNo;
     cout<<endl;
     for(int i=0;i<mySection.noStudents;i++)
     getData(mySection.studentsList[i]);
     }
     
     void PrintSection(const section mySection)
{
     cout<<"section No. = "<<mySection.secNo<<endl;
     cout<<"# of students = "<<mySection.noStudents<<endl; 
   cout<<"Room No. = "<<mySection.roomNo;
     cout<<endl;
       for(int i=0;i<mySection.noStudents;i++)
    PrintData(mySection.studentsList[i]);
    cout<<endl;
     }
     
        float averageQuiz1(section mySection)
        {  
       float avg;
       float sum=0;
       for(int i=0;i<mySection.noStudents;i++)
       sum+=mySection.studentsList[i].quizGrades[0];
    
       avg=sum/mySection.noStudents;
       return avg;
       }
     
     void aboveavg(section mySection)
     {   cout<<"Student get grade above avg. : "<<endl;
          for(int i=0;i<mySection.noStudents;i++)
          if(mySection.studentsList[i].quizGrades[0]>averageQuiz1(mySection))
          {
          cout<<"Name = "<<mySection.studentsList[i].name<<endl;
          cout<<"Grade = "<<mySection.studentsList[i].quizGrades[0]<<endl;
          }
          }
     
   
int main()
{
section mysection1;
ReadData(mysection1);
PrintSection(mysection1);
cout<<"Avg. = "<<averageQuiz1(mysection1)<<endl;
aboveavg(mysection1);
system("pause");
return 0;
}


متعــــــب بصراحه :RpS_lol:
 
التعديل الأخير:
وهذا Part 2
ملاحظه الfunctions مامسحت مايتعلق ب part 1 لان استخدمتهم في part 2
اللي فرق بس في main
استخدمت الmain بدون تقيّد بشي
انتي استخدميهم حسب ماتحبين

PHP:
#include<iostream>
#include<string>
using namespace std;
struct student {
long studentID;
string name;
float quizGrades[5];
};
struct section {
       int secNo;
       int noStudents;
       string roomNo;
       student studentsList[20];
       
       };
       
void getData(student &X)
{
     cout<<"Enter student ID,name and quiz grades = "<<endl;
     cin>>X.studentID>>X.name;
     cout<<"Enter quiz grades = "<<endl;
     for(int i=0 ;i<5 ;i++)
     cin>>X.quizGrades[i];
     }
     
void PrintData(const student X)
{
     cout<<"Student ID = "<<X.studentID<<endl;
     cout<<"Student name = "<<X.name<<endl;
     cout<<"Student quiz grades = ";
     for(int i=0 ;i<5 ;i++)
     cout<<X.quizGrades[i]<<"  ";
     cout<<endl;
     }
float averageQuiz1 (student X)
{float avg;
      for(int i=0 ;i<5 ;i++)
      avg+=X.quizGrades[i];
      return avg/5;
      }
      
     bool equal(student X,student Y)
     {
           if(X.quizGrades[0] == Y.quizGrades[0] && X.quizGrades[1] == Y.quizGrades[1] && 
            X.quizGrades[2] == Y.quizGrades[2] && X.quizGrades[3] == Y.quizGrades[3] && 
             X.quizGrades[4] == Y.quizGrades[4] )
             return true;
      
          return false;
       
          }
       
       //part 2   
void ReadData(section &mySection)
{
     cout<<"Enter section No. and # of students and room No. = "<<endl; 
     cin>>mySection.secNo>>mySection.noStudents>>mySection.roomNo;
     cout<<endl;
     for(int i=0;i<mySection.noStudents;i++)
     getData(mySection.studentsList[i]);
     }
     
     void PrintSection(const section mySection)
{
     cout<<"section No. = "<<mySection.secNo<<endl;
     cout<<"# of students = "<<mySection.noStudents<<endl; 
   cout<<"Room No. = "<<mySection.roomNo;
     cout<<endl;
       for(int i=0;i<mySection.noStudents;i++)
    PrintData(mySection.studentsList[i]);
    cout<<endl;
     }
     
        float averageQuiz1(section mySection)
        {  
       float avg;
       float sum=0;
       for(int i=0;i<mySection.noStudents;i++)
       sum+=mySection.studentsList[i].quizGrades[0];
    
       avg=sum/mySection.noStudents;
       return avg;
       }
     
     void aboveavg(section mySection)
     {   cout<<"Student get grade above avg. : "<<endl;
          for(int i=0;i<mySection.noStudents;i++)
          if(mySection.studentsList[i].quizGrades[0]>averageQuiz1(mySection))
          {
          cout<<"Name = "<<mySection.studentsList[i].name<<endl;
          cout<<"Grade = "<<mySection.studentsList[i].quizGrades[0]<<endl;
          }
          }
     
   
int main()
{
section mysection1;
ReadData(mysection1);
PrintSection(mysection1);
cout<<"Avg. = "<<averageQuiz1(mysection1)<<endl;
aboveavg(mysection1);
system("pause");
return 0;
}


متعــــــب بصراحه :RpS_lol:

اي حده متعب بصراحة
بس
d. Write a function named averageQuiz1 that takes as parameter mySectionof type section. The function should return the average of first quiz for all students in the section

e. Write a function named topStudents that take as parameter: mySection of type section. The function should print the students’ names with quiz1 score greater than the average of quiz1 for all students. (Hint: use averageQuiz1 function to get the average of quiz1)
ما ادري شلون اكتب الــ functions
 
اي حده متعب بصراحة بس d. Write a function named averageQuiz1 that takes as parameter mySectionof type section. The function should return the average of first quiz for all students in the sectione. Write a function named topStudents that take as parameter: mySection of type section. The function should print the students’ names with quiz1 score greater than the average of quiz1 for all students. (Hint: use averageQuiz1 function to get the average of quiz1)ما ادري شلون اكتب الــ functions
اكو انا كتبتها لاشوفي شلون سويته وبتعرفين
 
ثنكس اخووي تعبتك معااي رحم الله والديك :smile:
 
اخوي بس في الجزء D لما استخدمت الفنكش اللي انت كتبته ما طلع لي اavg لل student y
فحاولت فيه وقدرت اوصل للحل

PHP:
 //d
floa calcuateAvg1 (student x)

{
float avg=0;
for(int i=0 ; i<5 ; i++)
avg+=(x.Quizgrades[i])/5;
return avg;
 
اخوي بس في الجزء D لما استخدمت الفنكش اللي انت كتبته ما طلع لي اavg لل student y
فحاولت فيه وقدرت اوصل للحل

PHP:
 //d
floa calcuateAvg1 (student x)

{
float avg=0;
for(int i=0 ; i<5 ; i++)
avg+=(x.Quizgrades[i])/5;
return avg;

صباح الخير
اممم اختي ماكان الغلط مني
يفرق في البرنامج اللي تستخدمونه
يعني انا ماخليت الكود الا وانا ادري مافيه ايرور
انتو تستخدمون برنامج نفس اللي في اللاب ودقيق يعني لازم نضع قيمه زيرو للavg
وانا اللي عندي شغل بدون هالمشكله

عموما شكراً ع الملاحظه
 
شرح الـ Class

الclass واحده من التعريفات اللي نعرفها خارج الmain

تحتوي على dataType تندرج تحت كلمة (private)
وتحتوي على functions تندرج تحت كلمة (public)
we can't read or print or do any thing from (private) without using this function

اذا هي نوع من التنظيم

Syntax:
PHP:
class className{
private:

member

public:


functions


}; //do not forget (;)

مثال :
بنسوي class الى الطلاب
تحتوي على
Name(strign),ID(long), and GPA of type float

اذا راح تكون بهذا الشكل
PHP:
class student {
private:
string name;
long ID;
float GPA;
Public:


};

الحين انتهينا من الخطوه الأولى (وهي شبيهه بالstruct)

الحين السؤال / بعد ما حجزت في الmain
object ( متغير ) من نوع student اللي هو class يعني
بهالشكل

PHP:
student s1 ;

شنو المفروض يكون داخله ؟
المفروض هالobject اللي سميناه (s1) يحتوي name و ID و GPA
مثل ما قلنا في private ،
ومثل ماكنا نسوي في struct

الحين السؤال / كيف نقرأ البيانات داخل (s1) ؟

هل بهذي الطريقه ؟

PHP:
cin>>s1;
أو مثل struct
PHP:
cin>>s1.name
cin>>s1.ID;
cin>>s1.GPA;

طبعاً ولاطريقة صحيحة مما ذكر اعلى

ماهي الطريقة الصحيحة ؟
تكون بأستخدام function كما ذكرت في المقدمه وتكون داخل public (عشان يكون عندها تصريح بأستخدام الprivate)

طبعا الـ function بتكون عاديه في كتابتها ، ولكن فيها بعض الخصوصيه في اول سطر (انظر اسفل)

بنكتب three
functions
وحده بتقرأ data ،وحده بتسحب data،وحده بتطبع data

الحين انا بدخل (بقرأ) بيانات داخل s1 الي المفروض يحتوي على
(name , ID , GPA)
هالعملية نسميها setData، ولما بسحب الData من الprivate الى main
سواء للطباعه او للاستخدام ، نسمي العلمية
getData، والطباعه العاديه print

الحين نكتب prototype
للfunction اللي بنسويهم ونسوي ليهم كوبي ونخليهم في public

اول وحده setData
PHP:
void setData(string,long,float);
ثاني وحده getData
PHP:
void getData(string&,long&,float&);
ثالث وحده Print
PHP:
void printData( )const;

مثل ماقلت لكم الحين نسوي ليهم كوبي داخل الpublic
PHP:
class student {
private:
string name;
long ID;
float GPA;
Public:
void setData(string,long,float);
void getData(string&,long&,float&);
void printData( )const;

};
بهذا الشكل الclass اصبح جاهز للاستخدام ( Afterimplementationfunction)
يعني بعد كتابة الكود للfunctions


الفرق الوحيد ان احنا اول
بنكتب اسم الclass :: بعدين اسم الfunction


اول وحده :
PHP:
void student :: setData(string Sname ,long Sid ,float Sgpa)
{
name=Sname;
ID=Sid;
GPA=Sgpa;
}

ثاني وحده :
PHP:
void student :: getData(string Sname&,long&Sid,float&Sgpa)
{
Sname=name;
Sid=ID;
Sgpa=GPA;

}

ثالث وحده :
PHP:
void  student :: printData( )const
{
cout<<"Student name : " <<name<<endl;
cout<<"Student ID = "<<ID<<endl;
cout<<"Student GPA = <<GPA<<endl;
}

الحين الجزء الاخير ( main )

اولا حجز object وحجز المتغيرات اللي نحتاجها

PHP:
student st1;
string Sname;
long Sid;
float Sgpa;

قراءة بيانات بأستخدام الsetData

PHP:
cout<<"Please enter stdent name,ID,GPA"<<endl;
cin>>Sname>>Sid>>Sgpa;
st1.setData(Sname,Sid,Sgpa);

طباعة البيانات:
PHP:
st1.printData();

سحب البيانات:
PHP:
st1.getData(Sname,Sid,Sgpa);

الحين لو سوينا طباعه الى name راح يطبع الموجود في الاسم الموجود st1
PHP:
cout<<"Student name : "<<Sname<<endl;
///////// (ملاحظـــــة) ///////////
بين set و get
انا دائماً اذا بشرح الى احد اقول له يحفظ
( main الى public الى private )

-----اقرا من اليمين ---->

يعني انا في main عرفت s1 بضيف له بيانات لازم اروح Function اللي في public بعدين اوصل private
والعكس (اذا بسحب البيانات)
بدون هالpubilc لايمكن استخدام private بطريقه اخرى لانها بيانات محمية

/////////////////////////////


في كلمات لازم نتعود عليها في هذا الدرس

class , private , public , implementation , set , get , print, Is_empty , Is_full constructor , destructor
كلهم سهلين ان شاء الله

هذا اللي الله قدرني عليه ، شرحت الاساسيات تقريبا كامل
واذا في فرصه اكمل في جزء ثاني للشرح بكمل
مع ان مضغوط وايد هالايام تعرفون ايام العيد ، وتستات
فـ اعتذر على التقصير


كل عام وانتم بخير
اخوكم ITCS Student

 
عودة
أعلى أسفل