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

ممكن أحد يصحح خطأي بالكود؟؟

مغلق
بدأه نفسي عزيزه في 6 أبريل 2007 · 5 رد · 518 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

ممكن أحد منكم يصحح الخطأ بالكود الي صلحته

لكم جزيل الشكر..

</B></DIV> <DIV><B>#include <iostream>
#include <string>
using namespace std;</B></DIV> <DIV><B>class Mobile{
private: 
		 string  colour;
		 static const string  make; 
		 const string  model;</B></DIV> <DIV><B>public: 
 Mobile(string c, string m): model(m)
  {
   colour = c;
  }</B></DIV> <DIV><B>  void display()
  {
			   cout << "colour: " << colour << ", make: " << make;
			   cout << ", model: " << model << "\n";
		 }</B></DIV> <DIV><B>  void ring()
  {
   cout<< "ring! ring! ring!"<< endl;
  }</B></DIV> <DIV><B>	
		void changeColur(string c){
			 colour = c;
			 }</B></DIV> <DIV><B>  friend bool issame(Mobile m,Mobile m2);</B></DIV> <DIV><B>};
//****************************************
 bool issame(Mobile m,Mobile m2)
{
 return (m.model == m2.model);
}
const string Mobile::make="Nokia";
//*****************************************
class Owner{ friend class Mobile;
 string name;
 //Mobile mobile;</B></DIV> <DIV><B> Owner(string n, string mo,string cl): mobile(cl,mo) </B></DIV> <DIV><B> Mobile& getMobile(){</B></DIV> <DIV><B>  return mobile;}
void print(){
 
 cout<<"name is: "<<name<<endl;
}</B></DIV> <DIV><B> mobile.disply();
  
};
//****************************************
int main()
{
 
 cout<<"Mobile class"<<endl;
 cout<<"------------"<<endl<<endl;</B></DIV> <DIV><B> Mobile b1("silver", "6600");
	Mobile b2("Red", "5020");
 issame(b1,b2);
	
	
   
   
 system("pause");
 return 0;
}</B></DIV><B> <DIV> </DIV> <DIV>

<B></B>

mobile1.cpp

#2

html++ :D

هذا هو الكود من غير اكواد الhtml

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

class Mobile{
private: 
		 string  colour;
		 static const string  make; 
		 const string  model;

public: 
	Mobile(string c, string m): model(m)
		{
			colour = c;
		}

		void display()
		{
			   cout << "colour: " << colour << ", make: " << make;
			   cout << ", model: " << model << "\n";
		 }

		void ring()
		{
			cout<< "ring! ring! ring!"<< endl;
		}	
		void changeColur(string c){
			 colour = c;
			 }
		friend bool issame(Mobile m,Mobile m2);

};
//****************************************
 bool issame(Mobile m,Mobile m2)
{
	return (m.model == m2.model);
}
const string Mobile::make="Nokia";
//*****************************************
class Owner{ friend class Mobile;
 string name;
 //Mobile mobile;

 Owner(string n, string mo,string cl): mobile(cl,mo) 

 Mobile& getMobile(){

	 return mobile;}
void print(){

	cout<<"name is: "<<name<<endl;
}

 mobile.disply();

};
int main()
{	
	cout<<"Mobile class"<<endl;
	cout<<"------------"<<endl<<endl;
	Mobile b1("silver", "6600");
	Mobile b2("Red", "5020");
	issame(b1,b2);	 
	system("pause");
	return 0;
}
#3

صححته لك اخى..

#include <iostream>
#include <string>
using namespace std;
class Mobile{
private:
		 string  colour;
		 static const string  make;
		 const string  model;
public:
	Mobile(string c, string m): model(m)
		{
			colour = c;
		}

		void display()
		{
			   cout << "colour: " << colour << ", make: " << make;
			   cout << ", model: " << model << "\n";
		 }

		void ring()
		{
			cout<< "ring! ring! ring!"<< endl;
		}
		void changeColur(string c){
			 colour = c;
			 }
		friend bool issame(Mobile m,Mobile m2);
};
bool issame(Mobile m,Mobile m2)
{
	return (m.model == m2.model);
}
const string Mobile::make="Nokia";
//*****************************************
class Owner{ friend class Mobile;
string name;
Mobile mobile;
Owner(string n, string mo,string cl): mobile(cl,mo)
Mobile& getMobile()
{return mobile;}
void print(){
	cout<<"name is: "<<name<<endl;
}
int mobiledisplay();
};
int main()
{
	cout<<"Mobile class"<<endl;
	cout<<"------------"<<endl<<endl;
	Mobile b1("silver", "6600");
	Mobile b2("Red", "5020");
	issame(b1,b2);
	system("pause");
	return 0;
}
#4

لكن طلع عندي 3 أخطاء Mistrio_xp مشكور أخوي

ompiling...

Mobile.cpp

C:\Documents and Settings\rr\mobile\Mobile.cpp(40) : error C2612: trailing 'PCH creation point' illegal in base/member initializer list

C:\Documents and Settings\rr\mobile\Mobile.cpp(41) : error C2601: 'getMobile' : local function definitions are illegal

C:\Documents and Settings\rr\mobile\Mobile.cpp(57) : fatal error C1004: unexpected end of file found

Error executing cl.exe.

Mobile.obj - 3 error(s), 0 warning(s)

#5
#include <iostream>
#include <string>
using namespace std;
class Mobile{
private:
		 string  colour;
		 static const string  make;
		 const string  model;
public:
	Mobile(string c, string m): model(m)
		{
			colour = c;
		}

		void display()
		{
			   cout << "colour: " << colour << ", make: " << make;
			   cout << ", model: " << model << "\n";
		 }

		void ring()
		{
			cout<< "ring! ring! ring!"<< endl;
		}
		void changeColur(string c){
			 colour = c;
			 }
		friend bool issame(Mobile m,Mobile m2);
};
bool issame(Mobile m,Mobile m2)
{
	return (m.model == m2.model);
}
const string Mobile::make="Nokia";
//*****************************************
class Owner{ friend class Mobile;
	string name;
	Mobile mobile;
	Owner(string n, string mo,string cl): mobile(cl,mo){}
	Mobile& getMobile()
	{return mobile;}
void print(){
	cout<<"name is: "<<name<<endl;
}
int mobiledisplay();
};
int main()
{
	cout<<"Mobile class"<<endl;
	cout<<"------------"<<endl<<endl;
	Mobile b1("silver", "6600");
	Mobile b2("Red", "5020");
	issame(b1,b2);
	system("pause");
	return 0;
}

فقط أضفت {} للOwner Constructor

#6

طيب الله يجزاكم خير هل حلي صحيح ولا لا؟؟؟؟؟

هذا هو السؤال.....

  • Write a Mobile class, which contains three attributes: colour, make, and model.
    • All attributes should be represented as strings.
    • The model and make of a mobile are not modifiable
    • All mobiles are made by Nokia (i.e. the make is the same for all mobiles)

  • Write a constructor for the class.
    • If you were not able to write a default constructor, what do you think is the reason for this inability?
    • Are there any attributes that cannot be initialized inside the constructor? What are they?

  • Add three methods (member functions) to the class:
    • First method should be called ring which displays on the screen "ring! ring! ring!". This method should not change any of the attributes values.
    • Second method prints on the screen the mobile's description (colour, make and model of the mobile.)
    • Last method is called changeCover, which sets the colour of the mobile to a given colour.

  • Add another method (member function) called isTheSame which takes a Mobile object as a parameter. It should return true if the given Mobile object is the same as this mobile. Two mobiles are the same if they have the same make and model.

  • Test your class by creating a silver, Nokia, 6600 mobile object. Then send it a message to display its information.

Change the cover of the mobile to a red one, then again send it a message to display its information.

Create another black, Nokia, 3310 mobile object, then ask it if it was the same as the first mobile (the one you have created above).

  • Change the isTheSame method in question 4 to be a global function that is a friend of the class.
    • Do you need to change the parameters and why?
    • Change the test case in question 5 to reflect the modification of the function.

  • Write an Owner class, which contains two attributes: a name and a mobile. The class should contain a constructor which takes two parameters: a string representing the name, and a mobile. The attributes should be set to the parameters.
    • If the compiler objects on having a Mobile attribute, what do you think is the reason and how can you overcome this problem?

  • Add the following methods to the Owner class:
    • A method that displays the owner's details. In addition to the owner's name, the details of his mobile should be also displayed.
    • A method that returns the mobile as an object.
    • A method that sets the owner's mobile to a given mobile.

  • Write a copy constructor for the owner class

  • Test your programming using the following scenario:

Johnny Bravo has a black, Nokia 3330 mobile. His mobile no longer operates properly so he went to a mobile store and bought a new blue LG mobile, model 700. A month later, he got bored of the old blue cover so he exchanged it with a new purple one.

هذا الموضوع مغلق.

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