ممكن مساعده على حل سؤال 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>usingnamespace std;// هنا قمنا بتعريف كلاس الطالبclassStudent{// هنا قمنا بتعريف خصائص الطالب public:int id;public:
string name;public:char grade;public:int i =0;// هنا قمنا ببناء الدالة المنشئة او ال constructorStudent(int id, string name,char grade): id(id), name(name), grade(grade){}// هنا استعملنا ++ operator overloadingStudentoperator++(){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 Cvoid 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();}
#include<iostream>#include<ctime>usingnamespace std;// هنا قمنا بتعريف كلاس الطالبclassStudent{// هنا قمنا بتعريف خصائص الطالب public:int id;public:
string name;public:char grade;public:int i =0;// هنا قمنا ببناء الدالة المنشئة او ال constructorStudent(int id, string name,char grade): id(id), name(name), grade(grade){}// هنا استعملنا ++ operator overloadingStudentoperator++(){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 Cvoid 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.
C++ OOP
في أسئلة البرمجة
نشر
ممكن مساعده على حل سؤال 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.