is the design of this program well or bad??

November 27, 2010 at 20:50:42
Specs: Macintosh
is the design of this program well or bad?? because it works almost the same to find the errors but
still iam not sure thats it is a quiet good; thank you

#include <iostream.h>
#include <stdlib.h>

class airtime {
private:
int hours;
int minutes;
public:
void set_time() {
while(1) {
char dum;
int h, m;
cout << "enter time format ( 2:30 ) : ";
cin >> h >> dum >> m;

if (h <0 || h >23) {
cout << "\n hours must be (0 to 23)" << endl;
cin.clear(ios::failbit);
exit(-1);
}
hours =h;

if (m <0 || m >59) {
cout << "\n minutes must be (0 to 59)" << endl;
cin.clear(ios::failbit);
exit(-1);
}
minutes =m;

if ( cin.good() ) {
cin.ignore(10, '\n');
break;
}

cin.ignore(10, '\n');
cout << "\nError incorrect input!!!" << endl;
}
}

void dis_time() {
cout << "\n the time is " << hours << " : " << minutes << endl;
}
};
//////////////////////////////////////////
int main (int argc, char * const argv[]) {
airtime at1;
at1.set_time();
at1.dis_time();
return 0;
}


See More: is the design of this program well or bad??

Report •


#1
November 28, 2010 at 10:40:09
exit(-1);
Why are you terminating your program with -1? If you want to use exit(..) here, terminate with 0. Why are you notifying system about user’s mistakes? User’s mistakes aren’t system errors, so, you shouldn’t notify system about them. You should handle them. You should notify system, only about system errors.
I don’t know anything about program design. Hopefully, someone would help you.

.....................................
_Adnan_


Report •

#2
November 28, 2010 at 14:33:28
thank you,
for exit(-1) or (0) i dont know i just changing a practice form my book, so i don't know the different between -1 or 0, if you can tell me please ?

about the notifying system about user's mistake, that was the question of the book and this was my first chapter of mistakes and set errors ....blablabla
so maybe i will get there (what r u tell me about in a few chapters i hope)
well ........ thank you


Report •

#3
November 29, 2010 at 07:20:26
You can use EXIT_SUCCESS and EXIT_FAILURE macros instead of 0 and -1.
exit( 0 ) , exit( -1 ).
exit( EXIT_SUCCESS ), exit( EXIT_FAILURE ).

.....................................
_Adnan_


Report •

Related Solutions


Ask Question