Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

[Zadatak] Sutrasnji datum

[es] :: C/C++ programiranje :: C/C++ za početnike :: [Zadatak] Sutrasnji datum

[ Pregleda: 2281 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

stefannis

Član broj: 171819
Poruke: 3
*.exe-net.net.



Profil

icon [Zadatak] Sutrasnji datum21.03.2008. u 17:47 - pre 195 meseci
Interesuje me da li neko moze da mi pomogne ili vec posalje napravljen program u C++, program je prost, mislim ovako izgleda prosto ali treba dosta rada, treba mi recimo da u programu ukucam danasnji datum, znaci dan/mesec/godina i da mi izbaci koji ce datum sutra biti! Ali da se uzme u obzir i prestupne godine!
znaci recimo
Danasnji datum 21.3.2008
Sutrasnji datum 22.3.2008
Unapred HVALA!
 
Odgovor na temu

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 4902
*.dynamic.sbb.co.yu.

Jabber: xfiles@elitesecurity.org


+638 Profil

icon Re: [Zadatak] Sutrasnji datum21.03.2008. u 17:50 - pre 195 meseci
Ovako, Google: "c++ tommorow date"

Pa dobiješ recimo:
http://theos.in/windows-xp/how...m-to-calculate-tomorrows-date/
Code:

#include<iostream>

#define TRUE 1
#define FALSE 0

using namespace std;

class mydate{
   int day;
   int month;
   int year;
public:
   void readdate();
   int isLeapYear();
   string month2string();
   int exceedsDaysInMonth();
   void tommorow();
};

// Input date from user
void mydate::readdate(){
   cout << “Enter day (dd - 23 ) : “;
   cin >> day;
   cout << “Enter Month (mm - 04 ) : “;
   cin >> month;
   cout << “Enter year (yyyy - 2007 ) : “;
   cin >> year;
}
// make sure month days are correct
// return TRUE if days exceeds in a month
int mydate::exceedsDaysInMonth(){
  int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  if ( month < 1 || month > 12 || day > days[month-1])
     return TRUE;
  else
     return FALSE;
}
// convert numeric month into string
string mydate::month2string(){
   char *months[] = {“Jan”,“Feb”,“Mar”,“Apr”,“May”,“Jun”,“Jul”,“Aug”,“Sep”,“Oct”,“Nov”,“Dec”};
   if ( exceedsDaysInMonth() ) {
    if ( ! (month < 1 || month > 12) )
       return months[month-1];
    else
       return “Unknown month”;
   }
   else
    return “Unknown month”;
}
// return TRUE if a year is leap
int mydate::isLeapYear(){
   if ( (year % 4)  != 0 ){
      return FALSE;
   }
   else if ( (year % 400)  != 0 ){
      return TRUE;
   }
   else if ( (year % 100)  == 0 ){
      return FALSE;
   }
   else
   {
      return FALSE;
   }
}
// validate and calculate tommorows date
void mydate::tommorow(){
  int td, tm, ty;
  int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  if ( year < 0 ){
       cerr << year << ” is not a valid year” << endl;
       exit(1);
  }
  if ( exceedsDaysInMonth() ){
    if ( month == 2 && day == 29 ){
        if ( ! isLeapYear() ){
          cerr << year << ” is not a leap year, so Feb doesn’t have 29 days” << endl;
          exit(1);
        }
    }
    else
    {
      cerr << “Bad day value month - “ << month << ” (” << month2string();
      cerr <<  “) doesn’t have “ << day << ” days “<< endl;
      exit(1);
    }
  }
  // calculate tommorow
 td=day;
 tm=month;
 ty=year;
 td++;
 if ( td > days[month-1]){
   td=1;
   tm++;
   if ( tm > 12 )
    { ty++; tm=1; }
 }
 cout << “Valid date, found and tommorow is “ <<  td << “/” <<  tm << “/” <<  ty << endl;
}

// main
int main(){
  mydate date;
  date.readdate();
  date.tommorow();
  return 0;
}



... ili bez ručnog računanja, koje se obavlja unutar time_t:
http://forums.devshed.com/unix...35/tomorrow-s-date-406079.html
 
Odgovor na temu

stefannis

Član broj: 171819
Poruke: 3
*.exe-net.net.



Profil

icon Re: [Zadatak] Sutrasnji datum21.03.2008. u 19:35 - pre 195 meseci
Uff ako ovo radi znaci exxtra imas gajbu piva od mene
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: [Zadatak] Sutrasnji datum

[ Pregleda: 2281 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.