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

Class : فيه خطأ .. بالكلاس .. ما أدري وش يبي

بدأه منى القلب في 30 مارس 2009 · 2 رد · 397 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله وبركآته

فيه خطأ بالكلاس ما ادري ليـه

طبعاً البرنامج للمستطيل يحسب المساحه والمحيط

وهذا الكود .. فيه خطأ ما ادري ايش ..

#include<iostream.h>

class Rectangle
{
public:
	Rectangle(){ a = b = 0.1;}
	float set(float , float);
	float get(float , float);
	float area( float , float);
	float p(float , float );
private:
	float a,b;
}

float Rectangle::set( float f1 , float f2)
{
	a = ( f1 > 0.0 && f1 < 20.0 ) ? a : 0.1;
	b = ( f2 > 0.0 && f2 < 20.0 ) ? b : 0.1;
	return 0;
}
float Rectangle::get( float a , float b )
{
	cout << "The length is: " << a << endl << "The width is: " << b << endl;
	return 0;
}
float Rectangle::area( float a , float b)
{
	return a * b;
}
float Rectangle::p( float a , float b )
{
	return 2 * a * b;
}

int main()
{
	Rectangle R;


	R.set(1.4,5.5);

	cout << "The area is: " << R.area(a,b)<< endl;
	cout << "The perimeter is: " << R.p(a,b) << endl;

	R.ger(1.4,5.5);
	return 0;
}

تحيتي لكمـ

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

هذا تعديل على الكود بسيط

#include<iostream.h>

class Rectangle
{
public:
	Rectangle():a(0.1),b(0.1){}
	void  set(float , float);
	float get_length();
	float get_width();
	float area();
	float p();
private:
	float a,b;
};

void Rectangle::set(float f1 , float f2)
{
	a = f1; b = f2;

}
float Rectangle::get_length()
{

	return a;
}
float Rectangle::get_width()
{

	return b;
}
float Rectangle::area()
{
	return a * b;
}
float Rectangle::p()
{
	return 2 * a * b;
}

int main()
{
	Rectangle R;


	R.set(3,2);

	cout << "The area is: " << R.area()<< endl;
	cout << "The perimeter is: " << R.p() << endl;

  cin.get();  
	return 0;
}
tvquran_6.gif

#3

تسـلم اخوي على الكود بعد التعـديل ..

ويأليـت تشـرح لو شـرح بسـيط .. اللي عدلتـه ..

تحيتي لـًك اخوي

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