Rasprave u vezi Linux aplikacija.
Moderator/ica: Moderatori/ce
-
4ndY
- Moderator
- Postovi: 4060
- Pridružen/a: 15 svi 2008, 18:05
- Spol: M
- OS: Fedora/KDE
- Lokacija: Hamburg, DE
-
Kontakt:
Post
Postao/la 4ndY »
Malo sam popravio i preuredio kod da se dobije objektno-orijentirana verzija

(sad ste me zarazili pa moram nešto ić programirat

)
Kod: Označi sve
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Date {
public:
time_t rawtime;
tm* l_time;
short int l_day, l_month, l_year;
Date( void );
void askInput( void );
void askDate( void );
void convertToHuman( void );
void convertToSec( void );
void print( void );
void printDiff( void );
};
Date::Date( void ){
rawtime = time(NULL);
l_time = localtime( &rawtime );
}
void Date::convertToHuman( void ){
l_time = localtime( &rawtime );
l_day = l_time->tm_mday;
l_month = l_time->tm_mon + 1;
l_year = l_time->tm_year + 1900;
}
void Date::convertToSec( void ){
l_time->tm_mday = l_day;
l_time->tm_mon = l_month - 1;
l_time->tm_year = l_year - 1900;
rawtime = timelocal( l_time );
}
void Date::askInput( void ){
string correct;
print();
cout << "Is that date correct? Wtite 'no' to enter date manually. ";
correct = "Yes";
getline( cin, correct );
if (correct == "no") {
cout << "Please re-enter it " << endl;
askDate();
} else {
cout << "System date active. " << endl;
}
}
void Date::askDate( void ){
do {
cout << "Enter correct day (just number): ";
cin >> l_day;
} while ( l_day > 31 || l_day <= 0 );
do {
cout << "Enter correct month (just number): ";
cin >> l_month;
} while ( l_month > 12 || l_month <= 0 );
do {
cout << "Enter correct year (just number): ";
cin >> l_year;
} while ( l_year <= 0 );
convertToSec();
}
void Date::print( void ){
convertToHuman();
cout << "So it is: " << l_day << "." << l_month << "." << l_year << endl;
cout << "(formatted in DD.MM.YYYY)" << endl << endl;
}
void Date::printDiff( void ){
int minute = 60;
int hour = 60 * minute;
int day = 24 * hour;
int month = 730 * hour;
int year = 365 * day;
cout << "You have lived: " << endl;
cout << rawtime / year << " years" << endl;
cout << (rawtime % year) / month << " month(s)" << endl;
cout << (rawtime % year % month) / day << " day(s)" << endl << endl;
cout << "Which is" << endl;
cout << rawtime / month << " months" << endl;
cout << rawtime / day << " days" << endl;
cout << rawtime / hour << " hours" << endl;
cout << rawtime / minute << " minutes" << endl;
cout << rawtime << " seconds" << endl;
}
int main( void ) {
Date today, birth, diff;
cout << "Today's date" << endl;
today.askInput();
birth.l_day = birth.l_month = birth.l_year = 1;
cout << "Your birthday date" << endl;
birth.askDate();
diff.rawtime = today.rawtime - birth.rawtime;
diff.printDiff();
return 0;
}
A neutron walks into a bar; he asks the bartender, 'How much for a beer?' The bartender looks at him, and says 'For you, no charge.'
-
paupav
- Postovi: 42
- Pridružen/a: 29 lip 2013, 01:07
- Spol: M
- OS: Elementary OS Freya
Post
Postao/la paupav »
4ndY je napisao/la:Što ako je prijestupna godina ili ako si rođen u prijestupnoj? Falit će jedan dan zar ne? Slično je i sa brojem dana u mjesecu...
ovo je samo ovako za vježbu projekt

... da mi se da napravio bi i tu aplikaciju sa GUI-em
4ndY je napisao/la:Malo sam popravio i preuredio kod da se dobije objektno-orijentirana verzija

(sad ste me zarazili pa moram nešto ić programirat

)
Kod: Označi sve
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Date {
public:
time_t rawtime;
tm* l_time;
short int l_day, l_month, l_year;
Date( void );
void askInput( void );
void askDate( void );
void convertToHuman( void );
void convertToSec( void );
void print( void );
void printDiff( void );
};
Date::Date( void ){
rawtime = time(NULL);
l_time = localtime( &rawtime );
}
void Date::convertToHuman( void ){
l_time = localtime( &rawtime );
l_day = l_time->tm_mday;
l_month = l_time->tm_mon + 1;
l_year = l_time->tm_year + 1900;
}
void Date::convertToSec( void ){
l_time->tm_mday = l_day;
l_time->tm_mon = l_month - 1;
l_time->tm_year = l_year - 1900;
rawtime = timelocal( l_time );
}
void Date::askInput( void ){
string correct;
print();
cout << "Is that date correct? Wtite 'no' to enter date manually. ";
correct = "Yes";
getline( cin, correct );
if (correct == "no") {
cout << "Please re-enter it " << endl;
askDate();
} else {
cout << "System date active. " << endl;
}
}
void Date::askDate( void ){
do {
cout << "Enter correct day (just number): ";
cin >> l_day;
} while ( l_day > 31 || l_day <= 0 );
do {
cout << "Enter correct month (just number): ";
cin >> l_month;
} while ( l_month > 12 || l_month <= 0 );
do {
cout << "Enter correct year (just number): ";
cin >> l_year;
} while ( l_year <= 0 );
convertToSec();
}
void Date::print( void ){
convertToHuman();
cout << "So it is: " << l_day << "." << l_month << "." << l_year << endl;
cout << "(formatted in DD.MM.YYYY)" << endl << endl;
}
void Date::printDiff( void ){
int minute = 60;
int hour = 60 * minute;
int day = 24 * hour;
int month = 730 * hour;
int year = 365 * day;
cout << "You have lived: " << endl;
cout << rawtime / year << " years" << endl;
cout << (rawtime % year) / month << " month(s)" << endl;
cout << (rawtime % year % month) / day << " day(s)" << endl << endl;
cout << "Which is" << endl;
cout << rawtime / month << " months" << endl;
cout << rawtime / day << " days" << endl;
cout << rawtime / hour << " hours" << endl;
cout << rawtime / minute << " minutes" << endl;
cout << rawtime << " seconds" << endl;
}
int main( void ) {
Date today, birth, diff;
cout << "Today's date" << endl;
today.askInput();
birth.l_day = birth.l_month = birth.l_year = 1;
cout << "Your birthday date" << endl;
birth.askDate();
diff.rawtime = today.rawtime - birth.rawtime;
diff.printDiff();
return 0;
}
pošto sam uzeo da mjesec ima 30 dana svake godine se gupi po 5 dana... ako ti se da
