ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

کلاس زمان با استفاده از Flag درخواست کمک

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
mojgandombe
مهمون يكي دو روزه


Joined: 19 Apr 2008
Posts: 2
Location: iran/ semnan

PostPosted: Sun Apr 20, 2008 12:59 pm    Post subject: کلاس زمان با استفاده از Flag درخواست کمک Reply with quote

سلام دوستان . سوال من این بود: با استفاده ازC برنامه ای بنویسید که بتوان کلاس ایجاد کرد و آنگاه از Flag به عنوان پارامتر Error استفاده کنید. مثلا کلاس زمان رو به این صورت بدیم:
00و00و00
اگه ورودی این بود 60و60و24 آن را حفظ کند. ولی اگه ورودی رو اینجوری دادیم:
65و70و29 Error بده و زمان را صفر کنه
من جوابشو پیدا کردم ولی 2تا مشکل داره . 1- اینکه این برنامه به زبان C++ هست ولی ما باید به زبان C بنویسیم.
2- اینکه با استفاده از Flag نیست. لطفا اگه میتونین کمکم کنین.

فونتش یه کم قاطی شد. شرمنده



# include <iostream.h>
# include <conio.h>
Class time
Public:
Time ();
Void setTime (int, int, int); //set hour, minute, second
Void printMilitary(); // print Military time format
Void printStandard(); // print Standard time format
Private:
Int hour; //0-23
Int minute ; //0-59
Int second; //0-59
} ;
//**********
// member finction for time class
//time constructor initializes each data member to zero.
// ensure all timr object start in a consistent state.
Time:: time () {hour= minute = second-0; }
Void time :: setTime (int h, int m, int s)
{
Hour=(h>=0 && h<24) ? h:0;
Minute= (m>=0 && m<60) ? m:0;
Second= (s>=0 && s<60)? S:0;}
//print time in Military format
Void time : print military()
{count << (hour<10 ? "0": "")<< hour<< ":"
<<(minute < 10? "0": "")<< minute; }
//***************
Void time : printStandard()
{ count << (hour==0 || hour==12) ? :hour%12
<< ":" <<(minute <10 ? "0": "")<< minute
<< ":" <<(second < 10 ? "0": "")<< second
<< (hour<12 ? "Am": "Pm");}
//*****************
Int main ()
{ clrscr();
Count << "The initial military time in ";
t.printMilitary();
count << "\n the initial standard time is" ;
t.printStandard();
t.setTime (13,27,6);
count << endl;
count << "Military time after set Time is" ;
t.printStandard();
t.setTime (99,99,99); // attempt invalid seetings
count << "\n\n after attempting invalid settinfs:\n"
<< "Military Time:" ;
Count << "\n standard time : ";
t.printStandard();
getch ();
return 0 ;}

[/code]
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Mon Apr 21, 2008 8:12 pm    Post subject: Reply with quote

سلام کاری نداره . یه کم کار کنی روش در میاد .
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum