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

C++ OOP

آيه عادل

السؤال

Recommended Posts

  • 0

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

#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();
}

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

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 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.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ On 13‏/12‏/2021 at 22:48 قال احمد العبيدي2:

ممكن مساعده على حل سؤال 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.

 

 

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

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.

#include <iostream>

using namespace std;IMG_20220823_122226_019.jpg.8520e7d65a6463cf762eb04f0b1fa81f.jpg

class phone{

 int n , s , m;//n الرقم الاول ، s الرقم الثاني ، m الرقم الثالث 

 public:

 phone()

 {

  n=0;

  s=0;

  m=0;

 }

 void read_info()

 {

  cout<<"ادخل رقم الهاتف الى ثلاث اجزاء :"<<endl;

  cin>> n>>s>>m;

 }

 void getdata()

 {

  cout<<n<<"-"<< s<< "( "<<m<< ")"<<endl;

 }

 friend void print(phone );

};

 void print( phone p)

 {

  p.getdata();

 }

 int main ()

 {

  phone p;

  p.read_info();

  print(p);

  

 }

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...