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

Class خطأ ب Object ما ادري ليه

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

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

البرنامج يطبع لـي .. اسم الكتاب وسعرهـ ..

طبعا ً بـ كلاس ..

لكن طلع لـي خطأ بـ الاوبجكت ." الكائن " مدري ليـه وعلشان ايـش مع انه ..،

هذا الكود

#include<iostream.h>

#include<cstring>

class book
{
public:
	book(char *a );
	void set_title( char *);
	void set_price( double );
	char get_title();
	double get_price();
private:
	char title[50];
	double price;
};
void book::set_title(char *a)
{
	int l = strlen(a);
	l = ( l < 50 ? l : 49 );
	strncpy( title , a , l);
	title[l] = '\0';
}
void book::set_price( double b)
{
	price = b;
}
char book::get_title()
{
	return *title;
}
double book::get_price()
{
	return price;
}
int main()
{
	book mybook;
	mybook.set_title("c++ how to programing");
	mybook.set_price(150.9);

	cout << "The title is: "<< mybook.get_title() << endl;
	cout << "The price is: "<< mybook.get_price() << endl;

	return 0;
}

تحيتي

#2

اين ال constructor

ينقصك ايضا استعمال namespace std من اجل الدوال cout

تم تعديل هذه المشاركة بواسطة fkugd2003 في 8 أبريل 2009 في 19:56

العمل كثير و الوقت قليل أعاننا الله

seo zen SEO Enlightment amazon danbo

#3

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

يوجد خطأ فى constructor

وأيضا الداله get_title

تصحيح البرنامج مع بعض الإضافات


#include<cstring>
class book
{
public:
book();
book(char*,double);
void set_title( char *);
void set_price( double );
char* get_title();
double get_price();
private:
char title[50];
double price;
};
book::book()
{
title[0]='\0';
price=0;
}
book::book(char* name,double p)
{
set_title(name);
set_price(p);
}
void book::set_title(char *a)
{
int l = strlen(a);
l = ( l < 50 ? l : 49 );
strncpy( title , a , l);
title[l] = '\0';
}
void book::set_price( double b)
{
price = b;
}
char* book::get_title()
{
return title;
}
double book::get_price()
{
return price;
}
int main()
{
book mybook;
mybook.set_title("c++ how to programing");
mybook.set_price(150.9);

cout << "The title is: "<< mybook.get_title() << endl;
cout << "The price is: "<< mybook.get_price() << endl;
book cc("c++ very good",25.5);
cout << "The title is: "<< cc.get_title() << endl;
cout << "The price is: "<< cc.get_price() << endl;

return 0;
}
#include<iostream.h>

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#4

تشكروون واللهـً ..

وعرفت الخلل .. وبطبقه ان شاء الله

مع خالص شكري وودي لكم :)

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