السلام عليكم ورحمه الله وبركآته
البرنامج يطبع لـي .. اسم الكتاب وسعرهـ ..
طبعا ً بـ كلاس ..
لكن طلع لـي خطأ بـ الاوبجكت ." الكائن " مدري ليـه وعلشان ايـش مع انه ..،
هذا الكود
#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;
}تحيتي