الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن شرح المطلوب من السؤآل

بدأه سبحوا الله في 31 مارس 2010 · 12 رد · 1,909 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

..

السلام عليكم جميعآ ..

سعيدهـ بتوآجدي في هذا المنتدى ..

لدلدي تكليف من الأستآذهـ .. وهي إنشآء برنآمجين ..

ولكل برنآمج تم تحديد المطلوب ..

لكن لم أفهمه ..

الرجآء التوضيح لي فقط .. مالمطلوب ( بالعربي )

وشكرآ مقدمآ ..

Exercise2:

Create a class called String (Note different capitalization). It has the following data members: value and length.

- Define a default constructor that initializes value to empty string and length to zero.

- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.

Hint: use the built in functions of class string

- Provide the appropriate set and get functions for the class data members if needed.

Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.

Sample output screen

Exercise 3:

Create product class. It contains name, price, discount percentage and price after discount as data members.

- Define a default constructor to initialize all data members.

- Define a member function that uses price and discount percentage to calculate and set the price after discount. Note that a member function can call another member function.

- Create a non member function displayInfo that receives the product from the main. Display all the object information and also print the price after discount.

- In the main let the user enters the product name, discount percentage and price. Next, set the product object with this information. Finally calculate the price after discount and call diaplyinfo().

Sample output screen

#2

في الأول: المطلوب كتابة ال string كـ class له الحقول؛ قيمة وطول السلسلة وكتابة بانيين له، الأول يهيء القيم ل0 والثاني لتهيئة القيم من دخل المستخدم، ثم كتابة تابع main لتجريب ال class

...

المصدر: babylon:P-

1
#3

طيب السؤآل الأول ..

Create a class called String (Note different capitalization). It has the following data members: value and length.

- Define a default constructor that initializes value to empty string and length to zero.

- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.

Hint: use the built in functions of class string

- Provide the appropriate set and get functions for the class data members if needed.

Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.

Sample output screen

هذا برنآمجي .. ويعطيني إيرور مو عآرفه ليش

يآليت تسآعدوني مع شرح الأغلاط مشكورين

#include <iostream>
using namespace std;

class String // String must with capetal S not (string)
{
	private: 
	string value;
	int length;


	puplic:
	string();
	string(string,int)

	string value()
	{
		cout<<"String object with the default constructor " << endl;
		value="";
		length=0;
		cout<<"Value is "<<value<<endl;
		cout<<"Length is "<<length<<"charecter"<<end;
	}
	string stri(string value,int length)
	{
		cout<<"String object with the parameterized constructor  " << endl;
		cout<<"Value is "<<value<<endl;
		cout<<"Length is "<<length<<"charecter"<<endl;
	}
};
int main()
{
	String Stg;
	Stg.value();
	Stg.stri(value,length);
	return 0;
}
#4

سبحان الله....

السلام عليكم.

من النظرة الأولى، الباني يجب أن يكون بنفس اسم الصف (وهذا محقق) لكن ++C حساسة لحالة الأحرف لذلك الباني يجب أن يبدأ ب capital letter

فاصلة منقوطة بعد الباني الثاني + نفس الخطأ.

أين شيفرة الباني( code)....؟.

التوقيع: مبرمج java.

لكن عندي سؤال، هل أحدكم يبدأ البرمجة دون أن يتعلم قواعد اللغة أو الـ Syntax، أو حتى التفكير البرمجي

اقرأي كتبا عن البرمجة بال++C ,بالتوفيق...

#5

تفضل التعديل .

تم التعديل والان يمكن للمثال قراءة كامل السطر . جملة كاملة . .

/*  
Create a class called String (Note different capitalization). It has the following data members: value and length
- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.
Hint: use the built in functions of class string
- Provide the appropriate set and get functions for the class data members if needed.


*/

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

class String // String must with capetal S not (string)
{
        private: 
         string value;
        int length;


        public:

        //- Define a default constructor that initializes value to empty string and length to zero.
        String()
        {
                cout<<"String object with the default constructor " << endl;
                value="";
                length=0;
                cout<<"Value is "<<value<<endl;
                cout<<"Length is ("<<length<<") charecter"<<endl;
        }
        //- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.

        String(string v)
        {
                value=v;
		 		length=value.length() ;
                cout<<"Value is "<<value<<endl;
                cout<<"Length is("<<length<<")charecter"<<endl;
         }
 };

/*
Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.
Sample output screen

*/
int main()
{
	/* Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.
      Sample output screen */
	string value="";
	String stg; //With Default Constractor;
    cout<<"Enter A value\n";
	getline(cin,value);
 //With Parameter constracture .After getting value .

        String St1(value);
        system("pause");
        return 0;
}

تحياتي

تم تعديل هذه المشاركة بواسطة omani في 2 أبريل 2010 في 04:19

1

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#6

وهنا تجد حل السؤال الثالث :

/index.php?showtopic=217889

تحياتي

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#7

عمآني مشكور كثييير

لكن فيه إيرور بالبرنآمج اللي كتبته ياليت تشوفه لي ..

/

JDurrah

أخوي احنا عندنا يشرحون الشيت بعد مآنسلمه ..!

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

الكل مو فاهم وخصوصا اللي طرحته هنا

مشكور اخوي واكيد أنا أقرأ كتب عن الـ c++ وشروحات بالعربي بعد

الله يعين

#8
سبحوا الله كتب:

عمآني مشكور كثييير

لكن فيه إيرور بالبرنآمج اللي كتبته ياليت تشوفه لي ..

البرنامج يعمل معي بدون اي مشاكل .. استخدم c++.net

تحياتي

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#9

^

^

مشكور اخوي

الله يجزآكـ الجنه يآرب

#10

عمآني

ربيّ يوفقك ويسعدك

بس أتمنى أن الشرح يكون بـ العربيَّ ، حتى تعم الفآئده لـ الجميع

#11
مبتدئه برمجه كتب:

عمآني

ربيّ يوفقك ويسعدك

بس أتمنى أن الشرح يكون بـ العربيَّ ، حتى تعم الفآئده لـ الجميع

وهذا الشرح بالعربي .. وأتمنى يكون مفهوم. لاني شرحته فقط مجرد ترجمه . على افتراض انكم ملمون بأساسيات اللغة .

السؤال هنا يركز على التعامل مع النصوص من خلال الدالة string بالاضافة الى constructor Overloading والمقصود بها اكثر من كونستركتر بنفس الاسم مع اختلاف البارميتر.

/*  
انشى كلاس اسمه String  ( مع التأكد من أن الحرف الاول استهلالي) وبه العناصر التالية : value,length
Create a class called String (Note different capitalization). It has the following data members: value and length
انشى constructor يحمل بارميتر string  للداتا ميمبر في الكلاس المسمى value  (ملاحظة يجب استخدام الفانكشن المسماة string  وذلك لتعريف المتغير value) 
- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.
Hint: use the built in functions of class string
انشى فانكشن لادخال او عرض البيانات حسب الحاجة . 
- Provide the appropriate set and get functions for the class data members if needed.


*/
//ننشى هنا الملفات الرأس
#include <iostream>
// الملف سترينج يحمل داخله المتغير string  والذي سوف نستخدمه في تعريف المتغير value 
#include<string>
using namespace std;
// ننشئ الكلاس String  وهي تختلف عن string
class String // String must with capetal S not (string)
{
//ننشئ قيم الكلاس .
        private: 
         string value;
        int length;


        public:
  // ننشئ الكونستركتر الافتراضي حسب ماورد في السؤال لتصفير القيم الى صفر مع استخدامنا له لعرض البيانات مباشرة ( لكي لا نقوم بكتابة فانكشن لعرض البيانات )
        //- Define a default constructor that initializes value to empty string and length to zero.
        String()
        {
                cout<<"String object with the default constructor " << endl;
                value="";
                length=0;
                cout<<"Value is "<<value<<endl;
                cout<<"Length is ("<<length<<") charecter"<<endl;
        }
// الجزء الثاني من السؤال والذي يقوم بإنشاء كونستركتر يحمل بارميتر لاعادة بناء القيم واستخراج طول النص الذي سوف يستلمه الكونستركتر عن انشاء الأوبجكت أو الشي
        //- Define a parameterized constructor that takes a string as parameter, set it to the member data value and set the member data length to the size of the member data value.

        String(string v)
        {
                value=v;
                                length=value.length() ;
                cout<<"Value is "<<value<<endl;
                cout<<"Length is("<<length<<")charecter"<<endl;
         }
 };

/*
هنا ننشئ الفنكشن ماين . 
Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.
Sample output screen

*/
int main()
{
        /* Finally, write a main function to test your class. And don’t forget to declare two objects using different constructor and print their information.
      Sample output screen */
        string value="";
// في هذا السطر أنشأنه الكائن  للكلاس وبدون بارميتر وسوف يعمل الكونستركتر تلقائيا بعد هذا السطر لان الكونستركتر يعمل تلقائي .
        String stg; //With Default Constractor;
// هنا سوف نطلب القيمة من الشاشة 
    cout<<"Enter A value\n";
        cin>>value;
// بعدها ننشى كائن أخر يحمل معه بارميتر .. والهدف من البارميتر هنا هو تشغيل الكونستركتر الذي يحتوي على البارميتر 
 //With Parameter constracture .After getting value .

        String St1(value);
        system("pause");
        return 0;

تحياتي

2

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#12

جزآك الله خيرآ

وإن شآالله في ميزآن حسنآتك

#13

ـم تعديل المثال السابق بحيث اصبح الان يقرأ كامل السطر .

سابقا استخدمنا

cin>>value;

واستبدلناها بهذا السطر

getline(cin,value);

تحياتي

2

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

مواضيع مشابهة