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

كود بالغه السى بلس بلس بستخدام الفنكشن والكلاس

بدأه سرمد الليل في 25 مارس 2010 · 4 رد · 935 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

انا حليت السوال وطالع لى الاوت بوت غير صحيح رياضيا وكامن لازم جمله شرط ولا عرفت احطها

وهذا السوال

:

Create a class called Time that includes three pieces of information as data members{an hour (type int), minute (type int) and second (type int)}.

• Provide a member function void set ( ) that set the three data members by user input,ensure that the value provided by user for the seconds and minutes in the range 0-59, and hours in range 0-23; if it is not, set the value to 0.For that Provide three member functions:

VoidValidateoHour(int);

VoidValidateMinute(int);

VoidValidateSecond (int);

• Provide a member function DisplayTimeInSeconds that output the time in seconds.

write a program that uses Time class to shows following sample.

ويفترض ان الاوت بوت يكون كذا

Sample output :

Enter The Time

Hours :2

Minutes :40

Seconds :30

The Time Is : 9630 Second

وهذى مجاولتى فى حل الكود

#include <iostream>

using namespace std;

class Time

{public:

void ValidateoHour(int h )

{

cout<<"Hours : ";

cin>>h;

}

void ValidateMinute(int m)

{cout<<"Minutes : ";

cin>>m;

}

void ValidateSecond (int s)

{

cout<<"Seconds : ";

cin>>s;

}};

void DisplayTimeInSeconds(int h,int m,int s)

{

cout<<(h*3600)+(m*60)+s;

}

int main()

{int a,b,h,m,s;

Time ti;

cout<<"Enter The Time\n";

ti.ValidateoHour(h);

ti.ValidateMinute(m);

ti.ValidateSecond (s);

cout<<"The Time Is : \n";

DisplayTimeInSeconds(h,m,s);

cout<<" Second";

return 0;

}

والمشكله عندى مثل ماقلت انى ماعرف وين احط جمله الشرط كذلك تحويل الى السكند يطلع الرقم خطا

#2

ممكن احد يرد على الموضوع

#3

تفضل اخي الكريم

#include <iostream>
using namespace std;

class Time
{
private:
 int h,m,s;

public:
	void set(int hh,int mm,int ss)
		{
			(hh>24||hh<0)?h=0:h=hh;
			(mm>59||mm<0)?m=0:m=mm;
			(ss>59||ss<0)?s=0:s=ss;
		}

	long int DisplayTimeInSeconds()
		{
		return ((h*3600)+(m*60)+s);
		}
};
int main()
{
	int h,m,s;
    Time ti;
    cout<<"Enter The Time\n";
   cin>>h>>m>>s;

   ti.set(h,m,s);

     cout<<"The Time Is : \n";
     cout<<ti.DisplayTimeInSeconds()<<" Second\n";
system("pause");
return 0;
}

تحياتي

1

OMANI FOR EVER

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

post-12787-12780191801974.jpg

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

#4

السوال مو طالب داخل السيت يكون فيه ثلاثه فنكشن

هذى محاولتى

#include <iostream>

using namespace std;

class Time

{private: int h,m,s;

public:

void set()

{ void ValidateoHour(int hh)

{cout<<"Hour";

(hh>24||hh<0)?h=0:h=hh;

}

void ValidateMinute(int mm)

{cout<<"Minute";

(mm>59||mm<0)?m=0:m=mm;

}

void ValidateSecond (int ss);

{cout<<"Second";

(ss>59||ss<0)?s=0:s=ss;

}

}

int DisplayTimeInSeconds()

{ return ((h*3600)+(m*60)+s);

}};

int main(){

int h,m,s;

Time ti;

cout<<"Enter The Time\n";

ti.set(h,m,s);

cout<<"The Time Is : \n";

cout<<ti.DisplayTimeInSeconds()

<<" Second\n";

return 0;

}

#5

وهذا التعديل

#include <iostream>
using namespace std;

class Time
{
private:
 int h,m,s;

public:
        void set(int hh,int mm,int ss)
                {

					h=hh;
					m=mm;
					s=ss;
                }
    void ValidateoHour(int hh)
		{
		  (hh>24||hh<0)?h=0:h=hh;
		}
	void ValidateMinute(int mm)
		{
		  (mm>59||mm<0)?m=0:m=mm;
		}

	void ValidateSecond (int ss)
		{
		  (ss>59||ss<0)?s=0:s=ss;
		}

        long int DisplayTimeInSeconds()
                {
                return ((h*3600)+(m*60)+s);
                }
};
int main()
{
        int h,m,s;
    Time ti;
    cout<<"Enter The Time\n";
   cin>>h>>m>>s;

   ti.set(h,m,s);
   ti.ValidateoHour(h);
    ti.ValidateMinute(m);
	ti.ValidateSecond (s);

     cout<<"The Time Is : \n";
     cout<<ti.DisplayTimeInSeconds()<<" Second\n";
system("pause");
return 0;
}

تحياتي

1

OMANI FOR EVER

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

post-12787-12780191801974.jpg

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

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…