Treceți la conținutul principal

timpul cpp

// timpul.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include "time.h" 
#include "stdio.h"
#include "conio.h"
#include "iostream.h"
#include <stdlib.h>
#include "locale.h"
#include "string.h"
class cronometru
{private:
     clock_t start;
public:
 cronometru(){start=clock();}
 ~cronometru() 
 {clock_t stop=clock();
 cout<<"\n"<<"Durata executiei=";
 cout<<(double)(stop-start)/CLOCKS_PER_SEC;
 cout<<"secunde"<<"\n"<<endl;
 }
};

class Timp 
{private:
   int ora;
   int minut;
   int secunda;
   
public:
 //Constructor pornind de la trei intregi,validaind incadrare in intervalele posibile
 Timp(int o,int m,int s)
 {while((o<0)||(o>23)) {cout<<"Reintroduceti ora:";
                        cin>>o;}
                        ora=o;
     while((m<0)||(m>59)) {cout<<"Reintroduceti minutul:";
                        cin>>m;}
                        minut=m;
     while((s<0)||(s>59)) {cout<<"Reintroduceti secunda:";
                        cin>>s;}
                        secunda=s;
     }
 
    //Constuctor pornind de la timpul furnizat de sistem 
 Timp()
 {struct tm *ptr; 
  time_t lt;
     lt=time(NULL);
     ptr=localtime(&lt);
     ora=ptr->tm_hour;
     minut=ptr->tm_min;
     secunda=ptr->tm_sec;
    
 }

   



  friend ostream &operator <<(ostream &,Timp);  
  friend istream &operator>>(istream &, Timp &);
  friend double operator -(Timp &,Timp &);
  friend void afisare_tmp3();

  //Afisarea in formatul hh/mm/ss
  void afisare_tmp1()
 {if (ora<10)cout<<"0"<<ora<<"/";
                 else cout<<ora<<"/";
     if (minut<10) cout<<"0"<<minut<<"/";
                else cout<<minut<<"/";
     if (secunda<10)cout<<"0"<<secunda;
                else cout<<secunda;
  }


  //Afisarea in formatul hh:mm:ss AM sau PM 
  void afisare_tmp2()
  {if (ora<=12) cout<<"\n"<<ora<<":";
               else if (ora>12) cout<<"\n"<<(ora-12)<<":";
   if (minut<10) cout<<"0"<<minut<<":";
                else cout<<minut<<":";
   if (secunda<10)cout<<"0"<<secunda;
                else cout<<secunda;

   if (ora<=12) cout<<" AM";
               else if (ora>12) cout<<" PM";
  }
  

   //Avansarea ceasului cu un numar de minute
   void operator +(int min)
   {   int h=0;
    if(min>=60){h=min/60;min=min-h*60;}
    if (minut+min<=59) minut+=min;
                       else {minut=minut+min-60;ora++;
        } 
       ora+=h;        
      if (ora>=24) ora-=24;

   }

   //Dat inapoi ceas cu un numar de minute
   void operator -(int min)
   {   int h=0;
       if(min>=60) {h=min/60;min=min-h*60;}
  
    if (minut-min>=0) minut-=min;
                       else {minut=minut+60-min;ora--;}
           ora-=h;
        if (ora<0) ora+=24;

   } 
   
   //Avansarea ceasului cu un numar de ore:minute:secunde
   Timp operator +(Timp &t1)
   { 
    secunda=secunda+t1.secunda;
    if (secunda>=60) {secunda-=60;minut++;}
    minut+=t1.minut;
    if (minut>=60){minut-=60;ora++;};
    ora+=t1.ora;
    if (ora>=24) ora-=24;
    return *this;

   }
   
   //Dat inapoi ceas cu un numar de ore:minute:secunde
  Timp operator -(Timp &t1)
   {
    secunda=secunda-t1.secunda;
    if (secunda<0) {secunda+=60;minut--;}
    minut-=t1.minut;
    if (minut<0){minut+=60;ora--;}
    ora-=t1.ora;
    if (ora<0) ora+=24;
       return *this;   
   }

   //Preincrementare cu un minut
   void operator ++()
   {
 minut++;
   if (minut>=60){minut-=60;ora++;} 
   if (ora>=24) ora-=24;}
   
   //Postincrementare cu un minut
   void operator ++(int)
   {
 minut++;
   if (minut>=60){minut-=60;ora++;} 
   if (ora>=24) ora-=24;}
    
   //Predecrementare cu un minut
   void operator --()
   {
 minut--;
   if (minut<0){minut+=60;ora--;} 
   if (ora<24) ora+=24;}

   //Postdecrementare cu un minut
   void operator --(int)
   {
 minut--;
   if (minut<0){minut+=60;ora--;} 
   if (ora<24) ora+=24;}

                
};


 //Supraincarcarea operatorului << pt operatii de iesire Timp 
 ostream &operator <<(ostream &iesire,Timp t)
 {iesire<<iesire<<t.ora<<":"<<t.minut<<":"<<t.secunda<<endl;
 return iesire;}


 //Supraincarcarea operatorului >> pt operatii de intrare Timp
 istream &operator>>(istream &intrare, Timp &t)
 {cout<<"ora: ";intrare>>t.ora;
  cout<<"minut: ";intrare>>t.minut;
  cout<<"secunda: ";intrare>>t.secunda;
  return intrare;
 }

 //determinarea numarului de minute cuprinse intre doua momente
 double operator -(Timp &t1,Timp &t2)
 { 
 int a,b,c;
 a=t1.ora*3600+t1.minut*60+t1.secunda;
 b=t2.ora*3600+t2.minut*60+t2.secunda; 
 c=(a-b)/60;
 return c;
};


 struct fus {int decalaj;
          char *nume;};

//incarcarea unui vector cu numele si declajul fuselor orare
void fuse(fus f[45])
{ 
 f[0].decalaj=-720;f[0].nume="Eniwitok,Kwajalein";
 f[1].decalaj=-660;f[1].nume="Midway Island, Samoa";
 f[2].decalaj=-600;f[2].nume="Hawaii";
    f[3].decalaj=-540;f[3].nume="Alaska";
 f[4].decalaj=-480;f[4].nume="Pacific Time(US&Canada),Tijuana";
 f[5].decalaj=-420;f[5].nume="Arizona,Mountain Time(US&Canada)";
 f[6].decalaj=-360;f[6].nume="Central Time(US&Canada),Mexico City,Tegucigalpa,Saskatchewan";
 f[7].decalaj=-300;f[7].nume="Bogota,Lima,Quito,Eastern Time(US&Canada),Indiana(East)";
    f[8].decalaj=-240;f[8].nume="Atlantic Time(Canada),Caracas,La Paz,Santiago" ;
    f[9].decalaj=-210;f[9].nume="New Found Land";
    f[10].decalaj=-180;f[10].nume="Brasilia,Buenos Aires,Georgetown";
 f[11].decalaj=-120;f[11].nume="Mid Atlantic";
 f[12].decalaj=-60;f[12].nume="Azores,Cape Verde Is.";
 f[13].decalaj=0;f[13].nume="Greenwich Mean time: Dublin,Edinburgh,Lisbon,London";
 f[14].decalaj=60;f[14].nume="Amsterdam,Berlin,Rome,Stockholm,Vienna";
 f[15].decalaj=60;f[15].nume="Belgrad,Bratislava,Budapest,Prague";
 f[16].decalaj=60;f[16].nume="Brusseles,Copenhagen,Madrid,Paris";
 f[17].decalaj=60;f[17].nume="Sarajevo,Skopje,Sofia,Zagreb";
 f[17].decalaj=120;f[17].nume="Athens,Istanbul,Minsk";
  f[18].decalaj=120;f[18].nume="Bucharest";
  f[19].decalaj=120;f[19].nume="Cairo";
  f[20].decalaj=120;f[20].nume="Harare,Pretoria";
  f[21].decalaj=120;f[21].nume="Helsinki,Riga,Talin";
  f[22].decalaj=120;f[22].nume="Jerusalem";
        f[23].decalaj=180;f[23].nume="Bagdhad,Kuwait";
  f[24].decalaj=180;f[24].nume="Moscow,St.Petersburg";
  f[25].decalaj=180;f[25].nume="Nairobi";
  f[26].decalaj=210;f[26].nume="Tehran";
  f[27].decalaj=240;f[27].nume="Abu Dhabi,Muscat";
  f[28].decalaj=240;f[28].nume="Baku,Tbilisi";
  f[29].decalaj=270;f[29].nume="Kabul";
        f[30].decalaj=300;f[30].nume="Islamabad";
  f[31].decalaj=330;f[31].nume="Bombay,Calcutta,Madras,New Delhi";
        f[32].decalaj=360;f[32].nume="Astona,Almaty,Dhaka,Colombo";
  f[33].decalaj=420;f[33].nume="Bangkok,Jakarta";
  f[34].decalaj=480;f[34].nume="Beijing,Hong Kong";
  f[35].decalaj=480;f[35].nume="Perth";
  f[36].decalaj=480;f[36].nume="Singapore,Taipei";
  f[37].decalaj=540;f[37].nume="Osaka,Tokio,Seoul";
  f[38].decalaj=570;f[38].nume="Adelaide,Darwin";
  f[39].decalaj=600;f[39].nume="Brisbane,Canbera,Melbourne,Sidney";
        f[40].decalaj=600;f[40].nume="Vladivostock";
  f[41].decalaj=660;f[41].nume="Magadan,Solomon Is.,New Caledonia";
  f[42].decalaj=720;f[42].nume="Wellington,Fiji,Marshall Island";

        
}
//Afisarea timpului din principalele orase ale lumii
     void afisare_tmp3(char *oras)
  {fus f[45];
     int a,b,i;
     char *rez;
 fuse(f);
     struct tm *ptr; 
  time_t lt;
     lt=time(NULL);
  ptr=gmtime(&lt);
  i=0;rez=NULL;
    
   while ((i<43)&&(rez==NULL))
   {rez=strstr(f[i].nume,oras);
       i++;}
    Timp t(ptr->tm_hour,ptr->tm_min,ptr->tm_sec);
   if(rez!=NULL){a=f[i-1].decalaj;b=-a;
                if (a>0) t+a;
                    else if(a<0) t-b;
    
     t.afisare_tmp2();cout<<" "<<f[i-1].nume<<" "<<endl; 
  }
   else cout<<"Ati introdus gresit numele orasului"<<"\n";

}

//Decalajul orar intre doua orase 
int decalaj(const char *c1,const char *c2)
{char *rez1,*rez2;
int i=0,j=0;
fus f[45];
fuse(f);
rez1=NULL;

while ((i<43)&&(rez1==NULL))
{rez1=strstr(f[i].nume,c1);
i++;}

rez2=NULL;
while ((j<43)&&(rez2==NULL))
{rez2=strstr(f[j].nume,c2);
j++;}

if((rez1!=NULL)&&(rez2!=NULL)) return (f[i-1].decalaj-f[j-1].decalaj);
                               else return -1; 
}


void main()
{cronometru c;
 Timp t,t1;
 int min,min1;
 char oras[30],oras1[30],oras2[30];
 cout<<"\n"<<"Ora locala este: ";t1.afisare_tmp2(); 
 cout<<"\n"<<"Avansare ceas cu un numar de minute: ";cin>>min;
 t1+min;t1.afisare_tmp2();
 cout<<"\n"<<"Dat inapoi ceas cu un numar de minute: ";cin>>min1;
 t1-min1;t1.afisare_tmp2(); 
 cout<<"\n"<<"Avansare ceas c un nr de ore:min:sec ";
 cin>>t;
 (t1+t).afisare_tmp1();
 

 cout<<"\n"<<"Orasul pentru care doriti sa aflati ora<cu litera mare ex:Paris>: ";
 cin>>(oras);
 afisare_tmp3(oras);

 cout<<"\n"<<"Decalajul dintre"<<" "<<"orasul:";
 cin>>oras1;
 cout<<" si orasul: ";
 cin>>oras2;
 cout<<" este de:";
 if (decalaj(oras1,oras2)==-1) cout<<"\n"<<"Ati introdus gresit orasele!";
                              else if (decalaj(oras1,oras2)<0) cout<<(-decalaj(oras1,oras2))<<" minute";
                                               else  cout<<decalaj(oras1,oras2)<<" minute";


 


}

Comentarii

Postări populare de pe acest blog

WINDOWS 10 COMPUTER FREEZING PROBLEM SOLVED

good news : a BIOS UPDATE can resolve the problem but just for a Windows 7 on 64 bits o.s. and the system is not stable all the time. even after  bios update the system can freeze.
new info : u can try to low the screen brightness and see if this error appear so often after 
news: last info !!! maybe a virus. scann our system now with an antivirus i generate this error using other device ( a tablet pc) connected in the same network and the laptop i have this problem just freeze  http://thehackernews.com/2013/10/backdoor-found-in-chinese-tenda.html

news : if u use a tenda router this make couse all this problems



what i discover so far :
1.the electric company have many failure and affect the main ISP router/switch for building  also the router/switch installed by the ISP may be affected by overheating and will crash after a long utilisation on heat conditions 2.the router/switch of ISP affect any router of the user between this router and pc/laptop of client 3.the router and any other device of t…

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…