اذهب إلى المحتوى

احمد العبيدي2

الأعضاء
  • المساهمات

    1
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة احمد العبيدي2

  1. بتاريخ On 9‏/6‏/2020 at 06:03 قال آيه عادل:

    شكرا جزيلا لمجهودك

    ولكن كيف اتمكن من ادخال البيانات الاسم وغيره

    وجعله يحدد كم حصل على A وكم على B وهكذا

    ممكن مساعده على حل سؤال Any phone number such as (222) 767-1900 having three parts area code (222), exchange (767) and number (1900). Create a ciass PhoneNumber that is used to store a phone number as three separate parts. The ciass should contaln the following: 1- A constructor to initialize the data members 2- Read Data function to set a phone number as three parts 3- Get Data function to return the phane number as three parts 4 Print as a friend function to display the phone number using the Get_Data function. Write a C++ program to test the created class.

     

    بتاريخ On 27‏/5‏/2020 at 22:55 قال عبود سمير:

    مرحبا 
    يمكن عمل البرنامج بهذا الشكل 
     

    
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    // هنا قمنا بتعريف كلاس الطالب
    class Student{
    // هنا قمنا بتعريف خصائص الطالب 
    public:
        int id;
    public:
        string name;
    public:
        char grade;
        
    public:
        int i = 0;
    
        // هنا قمنا ببناء الدالة المنشئة او ال constructor
        Student(int id, string name, char grade) : id(id), name(name), grade(grade) {}
    
        // هنا استعملنا ++ operator overloading
        Student operator ++() {
            char grade = generateRandomGrade();
            Student tmp(i + 2,"new name " + (i + 2), grade);
            if (grade == 'A' || grade == 'B' || grade == 'C')
                ++i;
    
            return tmp;
        }
    
        // هذا من أجل طباعة عدد الطلاب الذين لديهم grade A, B or C
        void displayCount() {
            cout << "number of students who have grade A, B or C: " << i;
        }
        
        // هذا من أجل تحرير grade عشوائي
        char generateRandomGrade() {
            char grades[6] = { 'A', 'B', 'C', 'D', 'E', 'F'};
            return  grades[rand() % 6];
        }
    };
    
    int main() {
        srand(time(NULL));
        
        // هنا قمنا بإنشاء مجموعة من الطلاب و في كل مرة نطبع ال grade الخاص بكل طالب
        Student s1(1,"Samir Abboud", 'E');
        Student s2 = ++s1;
        cout << "Student 2 grade: " << s2.grade << "\n";
        Student s3 = ++s1;
        cout << "Student 3 grade: " << s3.grade << "\n";
        Student s4 = ++s1;
        cout << "Student 4 grade: " << s4.grade << "\n";
        Student s5 = ++s1;
        cout << "Student 5 grade: " << s5.grade << "\n";
        
        // طباعة عدد الطلاب الذين لديهم ال grade المطلوب
        s1.displayCount();
    }

    بإمكانك تجربة البرنامج من هنا
    بالتوفيق

     

    بتاريخ On 27‏/5‏/2020 at 22:55 قال عبود سمير:

    مرحبا 
    يمكن عمل البرنامج بهذا الشكل 
     

    
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    // هنا قمنا بتعريف كلاس الطالب
    class Student{
    // هنا قمنا بتعريف خصائص الطالب 
    public:
        int id;
    public:
        string name;
    public:
        char grade;
        
    public:
        int i = 0;
    
        // هنا قمنا ببناء الدالة المنشئة او ال constructor
        Student(int id, string name, char grade) : id(id), name(name), grade(grade) {}
    
        // هنا استعملنا ++ operator overloading
        Student operator ++() {
            char grade = generateRandomGrade();
            Student tmp(i + 2,"new name " + (i + 2), grade);
            if (grade == 'A' || grade == 'B' || grade == 'C')
                ++i;
    
            return tmp;
        }
    
        // هذا من أجل طباعة عدد الطلاب الذين لديهم grade A, B or C
        void displayCount() {
            cout << "number of students who have grade A, B or C: " << i;
        }
        
        // هذا من أجل تحرير grade عشوائي
        char generateRandomGrade() {
            char grades[6] = { 'A', 'B', 'C', 'D', 'E', 'F'};
            return  grades[rand() % 6];
        }
    };
    
    int main() {
        srand(time(NULL));
        
        // هنا قمنا بإنشاء مجموعة من الطلاب و في كل مرة نطبع ال grade الخاص بكل طالب
        Student s1(1,"Samir Abboud", 'E');
        Student s2 = ++s1;
        cout << "Student 2 grade: " << s2.grade << "\n";
        Student s3 = ++s1;
        cout << "Student 3 grade: " << s3.grade << "\n";
        Student s4 = ++s1;
        cout << "Student 4 grade: " << s4.grade << "\n";
        Student s5 = ++s1;
        cout << "Student 5 grade: " << s5.grade << "\n";
        
        // طباعة عدد الطلاب الذين لديهم ال grade المطلوب
        s1.displayCount();
    }

    بإمكانك تجربة البرنامج من هنا
    بالتوفيق

    ممكن اتساعدني بحل السوال

    Any phone number such as (222) 767-1900 having three parts area code (222), exchange (767) and number (1900). Create a ciass PhoneNumber that is used to store a phone number as three separate parts. The ciass should contaln the following:

    1- A constructor to initialize the data members

    2- Read Data function to set a phone number as three parts 3- Get Data function to return the phane number as three parts

    4 Print as a friend function to display the phone number using the Get_Data function. Write a C++ program to test the created class.

×
×
  • أضف...