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

[مخالف - عنوان غير مناسب :]class

مغلق
بدأه انثى خجوله في 15 أكتوبر 2011 · 3 رد · 302 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اتمنى تكونوا بصحه وعافيه

اتمنى شرح لهذاا السوال

مشكورين

Write a class named Car that has the following member variables:

yearModel, make, speed. In addition the class should have the following

constructor and the other member functions

constructor-accept the cars year model make as arguments. an assign to

the objects year, make also assign speed 0 to speed member.

Accessors to get the values stored in an object's yearModel make, speed

accelerate- should add 5 to the speed member variable each time it is

called.

brake- subtract 5 from speed each time it is called.

Demonstrate the class in a program that creates a Car object and then

calls the accelerate function five times. After each call to the accelerate

function get the current speed of the car and display it. Then call the brake

function five times after each call to the brake fuction, get the current

speed. of the car and display it. :blush:

−1
#2

لأجل هذا وجدت مواقع الترجمه.

مدونتي: C++ Tips and Tricks

#3

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

السؤال بسيط و شرحه هو حله :-)

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

نحتاج بـ Class و Constructor لهذا الكلاس و 3 متغيرات و توابع للحصول على قيم هذه المتغيرات.

هذا هو شرحه أما حله كالتالي (و أتمني ان لا يتأثر الحل من C# )

#include <iostream>
using namespace std;

class Car
{
private:
	// private variables
	int yearModel;
	int speed;
	int make;

public:
	// class constructor
	Car (int carYearModel, int carMake)
	{
		yearModel = carYearModel;
		make = carMake;
		speed = 0;
	}

	// accessors to access private variables.
	int YearModel()
	{
		return yearModel;
	}

	int Make()
	{
		return make;
	}

	int Speed()
	{
		return speed;
	}


	int Accelerate()
	{
		speed += 5;
		return 0;
	}

	int Break()
	{
		( speed > 5 )? speed -= 5 : speed = 0;
		return 0;
	}
};

int main()
{
	Car myCar(2000,2005);

	for (int i=0; i<5; i++)
	{
		myCar.Accelerate();
		cout<<"\nSpeed: "<< myCar.Speed();
	}

	for (int i=0; i<5; i++)
	{
		myCar.Break();
		cout<<"\nSpeed: "<< myCar.Speed();
	}

	cout<<endl;
	return 0;
}

و ألقي نظرة بالامثلة هنا لتعرفي الحل بنفسك قبل التسليم بالاستاذة:

(هنا)

(هنا)

(هنا)

(هنا)

(بالمناسبة لا أعلم لماذا الاساتذة في الجامعات يتركون اللغة العربية و يكتبون باللغة الانكليزية ممتلئ بالاخطاء! )

السلام عليكم

تم تعديل هذه المشاركة بواسطة موليان في 15 أكتوبر 2011 في 22:47

2

..:: رَبِّ زِدْني عِلْمًا ::..

#4

الأخ الكريم/الأخت الكريمة

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

مرحباً بكم في منتدى الفريق العربي للبرمجة

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

قواعد طرح المشاركات

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

==

معلش أخ موليان ...

logo1.png تطبيق طمأنينة ، نسخة بيتا على أندرويد

عبدالله الشمّري - Al-Shammari

CodingAlone.com

twitter @abshammeri

abshammeri AT gmail.com

github : abshammeri

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

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