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

clock by using class

بدأه hanonah في 5 ديسمبر 2009 · 6 رد · 635 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

ابي المساعده بتصحيح الكود إذا كانت المدخلات للدقائق والثواني 60 او اكثر مايغير لي شي ابدا بالخانات الثانيه

اعتقد الخطأ عندي بالشرط ما اعرف ايش المشكله بالضبط وهذا الكود

//Date:1-12-2009
//perposs:clss of Time.
//file name: Homework4 in (( c:Windows\System32\Homework4.cpp )).
//Auther:hanonah

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

class Time
{
	private:

int Hours;
int Minutes;
int Seconds;


public:

Time():Hours(0),Minutes(0),Seconds(0)
{/* Empty body*/}

Time(int H , int M , int S);
void Show();
void Mang(Time);
};

//function prototype


Time :: Time(int H , int M , int S)
{ 	Hours=H;
   Minutes=M;
  	Seconds=S;
}


void Time::Show()
{
cout<<Hours<<":"<<Minutes<<":"<<Seconds<<(Hours < 12 ? " AM" : " PM");
}


void Time::Mang(Time T1)
{ 
  if(T1.Seconds>=60)
  { T1.Seconds-=60;
   	T1.Minutes++;}

  if(T1.Minutes>=60)
{T1.Minutes-=60;
   T1.Minutes++;}

}






void main()
{
float H,M,S;
Time T0,T2;

cout<<"Enter the Hours note that it is in 24 module: ";
cin>>H;

while(H>24)
{cout<<"You must inter the right houre"<<'\n';
cout<<"Enter the Hours note that it is in 24 module: ";
cin>>H;}


cout<<"Enter the Minutes: ";
cin>>M;

cout<<"Enter the Seconds: ";
cin>>S;

Time T1(H,M,S);


cout<<'\n';
  cout<<'\n';


cout<<"The Time is"<<'\n'<<'\n';




   T2.Mang(T1); 

   cout<<setw(20);T1.Show();

    cout<<'\n';
   cout<<'\n';

cout<<setw(30)<<"by hanonah ^_^";

cout<<'\n';
  cout<<'\n';


}

وشكرا ,,

تم تعديل هذه المشاركة بواسطة hanonah في 5 ديسمبر 2009 في 11:40

#2

الكود مو راضي يطلع معي بطريقة العرض ليش ؟؟

تم تعديل هذه المشاركة بواسطة hanonah في 5 ديسمبر 2009 في 11:19

#3

تفضلي التعديل

اتمنى ان يكون المطلوب

//Date:1-12-2009

//perposs:clss of Time.

//file name: Homework4 in (( c:Windows\System32\Homework4.cpp )).

//Auther:hanonah



#include<iostream.h>

#include<iomanip.h>

//using namespace std;



class Time

{

  	  	  private:



int Hours;

int Minutes;

int Seconds;





public:



Time():Hours(0),Minutes(0),Seconds(0)

{/* Empty body*/}



Time(int H , int M , int S);

void Show();

void Mang(Time);

};



//function prototype





Time :: Time(int H , int M , int S)

{   	Hours=H;

  	Minutes=M;

  	  	  Seconds=S;

}





void Time::Show()

{

cout<<Hours<<":"<<Minutes<<":"<<Seconds<<(Hours < 12 ? " AM" : " PM");

}





void Time::Mang(Time)

{

  if(Seconds>=60)

  {

  	 Minutes+=Seconds/60;

  	 Seconds=Seconds%60;

  	 }



  if(Minutes>=60)

{

  Hours+=Minutes/60;

  Minutes=Minutes%60;



  	}



  if(Hours>=24)

  	{

  	 Hours=Hours%24;

  	}



}













void main()

{

float H,M,S;



cout<<"Enter the Hours note that it is in 24 module: ";

cin>>H;



while(H>24)

{cout<<"You must inter the right houre"<<'\n';

cout<<"Enter the Hours note that it is in 24 module: ";

cin>>H;}





cout<<"Enter the Minutes: ";

cin>>M;



cout<<"Enter the Seconds: ";

cin>>S;



Time T1(H,M,S);





cout<<'\n';

  cout<<'\n';





cout<<"The Time is"<<'\n'<<'\n';









  	T1.Mang(T1);



  	cout<<setw(20);T1.Show();



  	 cout<<'\n';

  	cout<<'\n';



cout<<setw(30)<<"by hanonah ^_^";



cout<<'\n';

  cout<<'\n';





}

تحياتي

OMANI FOR EVER

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

post-12787-12780191801974.jpg

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

#4

مشكووور اخوي ~> Omani

البرنامج اشتغل والـout put تماام

الله يعطيك العافيهـ . .

smile.gif

تم تعديل هذه المشاركة بواسطة hanonah في 5 ديسمبر 2009 في 20:36

#5
hanonah كتب:

مشكووور اخوي ~> Omani

البرنامج اشتغل والـout put تماام

الله يعطيك العافيهـ . .

smile.gif

العفو اختي الكريمة .ولكن لي ملاحظة . بأن التوقيت إذا كان بنظام 24 ساعة فلا يمكن استخدام AM و PM لان التوقيت اصلا متوالي .

لاستخدام هذه الطريقة . يمكن تغيير دالة اظهار الوقت لتكون كالتالي :

void Time::Show()

{

if(Hours>12)

cout<<(Hours%12)<<":"<<Minutes<<":"<<Seconds<<" PM";

else

cout<<Hours<<":"<<Minutes<<":"<<Seconds<<" AM";

}

تحياتي

تم تعديل هذه المشاركة بواسطة omani في 5 ديسمبر 2009 في 20:51

OMANI FOR EVER

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

post-12787-12780191801974.jpg

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

#6

صحيح بس طلبات الدكتورهـ بس حسويه برضو بـنظام 12 افضل :)

حبيت أسأل كيف اخلي الساعه تطلع بخانتين يعني مثلا زي كذا

01:23:03 حاليا يطلع لي خانه واحده 1:23:3

؟؟

#7

حل مؤقت . لانني مازلت ابحث عن الطريقة الصحيحة لعملية الفورمات للارقام

void Time::Show()
{
 if(Hours>12)
 {
 ((Hours%12)<10)?cout<<"0"<<(Hours%12):cout<<(Hours%12);
 cout<<":";
 (Minutes<10)?cout<<"0"<<Minutes:cout<<Minutes;
 cout<<":";
 (Seconds<10)?cout<<"0"<<Seconds:cout<<Seconds;
 cout<<" PM";
 }
 else
 {
 (Hours<10)?cout<<"0"<<(Hours%12):cout<<(Hours%12);
 cout<<":";
 (Minutes<10)?cout<<"0"<<Minutes:cout<<Minutes;
 cout<<":";
 (Seconds<10)?cout<<"0"<<Seconds:cout<<Seconds;
 cout<<" AM";
 }

تحياتي

OMANI FOR EVER

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

post-12787-12780191801974.jpg

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

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