Ders 5: C++ ile Tarih Belirleme

 Ders 5: C++ ile Tarih Belirleme

Lesson 5: Date Determination with C++

Mehmet Keçeci

04.04.2000

11. Örnek: Tarih Belirleme

#include <iostream>
#include <ctime>

using namespace std;

 

class Tarih {
int gun, ay, yil;
int toplamgun;
static bool is_valid(int, int, int);
static bool is_leap(int y) {
return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
}
static int gunler[][13];
static int yillar[2];
static const char *sgun[];
static const char *say[];
static const int yiltabani = 1700;
static const int faktor = 3;
void toplamgunler();
void revTarih(int toplamgunler1);
public:
Tarih(int, int, int);
Tarih();
int get_yil_gun()const;
int get_hafta_gun()const;
int get_gun()const {return gun;}
int get_ay()const {return ay;}
int get_yil()const {return yil;}
Tarih &operator+=(int n);
Tarih &operator-=(int n);
Tarih &operator++();
Tarih operator++(int);
Tarih &operator–();
Tarih operator–(int);

 

friend std::ostream &operator<<(std::ostream &, const Tarih &);
friend std::istream &operator<<(std::istream &, Tarih &);
friend bool operator<(const Tarih &, const Tarih &);
friend int operator-(const Tarih &, const Tarih &);
};

 

class KotuTarih{};

 

//GLOBAL fonksiyon dekrerasyonu
bool operator>(const Tarih &, const Tarih &);
bool operator>=(const Tarih &, const Tarih &);
bool operator<=(const Tarih &, const Tarih &);
bool operator==(const Tarih &, const Tarih &);
bool operator!=(const Tarih &, const Tarih &);
Tarih operator+(const Tarih &, int);
Tarih operator+(int, const Tarih &);
Tarih operator-(const Tarih &, int);

 

int Tarih::gunler[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};

 

int Tarih::yillar[] = {365, 366};

 

const char *Tarih::say[] = {“”, “Ocak”, “Subat”, “Mart”, “Nisan”, “Mayis”,
“Haziran”, “Temmuz”, “Agustos”, “Eylul”,”Ekim”, “Kasim”, “Aralik”};

 

const char *Tarih::sgun[] = {“Pazartesi”, “Sali”, “Carsamba”, “Persembe”,
“Cuma”, “Cumartesi”, “Pazar”};

 

Tarih::Tarih(int g, int a, int y)
{
if (!is_valid(g, a, y))
throw KotuTarih();

gun = g;
ay = a;
yil = y;
toplamgunler();
}

 

Tarih::Tarih()
{
time_t timer = time(0);
tm *tp = localtime(&timer);
gun = tp->tm_mday;
ay = tp->tm_mon + 1;
yil = tp->tm_year + 1900;
toplamgunler();
}

 

int Tarih::get_yil_gun()const
{
int yilgun = gun;

for (int k = 1; k < ay; ++k)
yilgun += gunler[is_leap(yil)][k];

return yilgun;
}

 

int Tarih::get_hafta_gun()const
{
return (toplamgun + faktor) % 7;
}

 

Tarih &Tarih::operator+=(int n)
{
revTarih(toplamgun + n);
return *this;
}

 

Tarih &Tarih::operator-=(int n)
{
revTarih(toplamgun – n);
return *this;
}

 

Tarih &Tarih::operator++()
{
return *this += 1;
}

 

Tarih Tarih::operator++(int)
{
Tarih retval(*this);
++*this;

return retval;
}

 

Tarih &Tarih::operator–()
{
return *this -= 1;
}

 

Tarih Tarih::operator–(int)
{
Tarih retval(*this);
–*this;

return retval;
}

 

void Tarih::toplamgunler()
{
toplamgun = 0;

for (int k = yiltabani; k < yil; ++k)
toplamgun += yillar[is_leap(k)];

toplamgun += get_yil_gun();
}

 

void Tarih::revTarih(int toplamgunler1)
{
toplamgun = toplamgunler1;
yil = yiltabani;

while (toplamgunler1 > yillar[is_leap(yil)])
toplamgunler1 -= yillar[is_leap(yil++)];
ay = 1;

 

while (toplamgunler1 > gunler[is_leap(yil)][ay])
toplamgunler1 -= gunler[is_leap(yil)][ay++];

gun = toplamgunler1;
}

 

bool Tarih::is_valid(int d, int m, int y)
{
if (y < yiltabani)
return false;

if (m < 1 || m > 12)
return false;

 

return m > 0 && m <= gunler[is_leap(y)][m];
}

 

ostream &operator<<(ostream &os, const Tarih &r)
{
return os << r.gun << ” ” << Tarih::say[r.ay] << ” ” << r.yil
<< ” ” << Tarih::sgun[r.get_hafta_gun()];
}

 

istream &operator<<(istream &is, Tarih &r)
{
int g, a, y;
is >> g >> a >> y;

 

if (!Tarih::is_valid(g, a, y))
throw KotuTarih();

r.gun = g;
r.ay = a;
r.yil = y;

 

r.toplamgunler();
return is;
}

 

bool operator<(const Tarih &d1, const Tarih &d2)
{
return d1.toplamgun < d2.toplamgun;
}

 

bool operator>(const Tarih &d1, const Tarih &d2)
{
return d2 < d1;
}

 

bool operator>=(const Tarih &d1, const Tarih &d2)
{
return !(d1 < d2);
}

 

bool operator<=(const Tarih &d1, const Tarih &d2)
{
return !(d2 > d1);
}

 

int operator-(const Tarih &d1, const Tarih &d2)
{
return d1.toplamgun – d2.toplamgun;
}

 

Tarih operator+(const Tarih &d, int n)
{
return Tarih(d) += n;
}

 

Tarih operator+(int n, const Tarih &d)
{
return d + n;
}

 

Tarih operator-(const Tarih &d, int n)
{
return Tarih(d) -= n;
}

 

int main()
{
Tarih d1(27, 2, 2005);
Tarih d2(d1 + 25);

while (d1 < d2)
cout << d1++ << endl;

return 0;
}

(Visited 8 times, 1 visits today)
Mehmet Keçeci on FacebookMehmet Keçeci on GithubMehmet Keçeci on GoogleMehmet Keçeci on InstagramMehmet Keçeci on LinkedinMehmet Keçeci on PinterestMehmet Keçeci on RssMehmet Keçeci on TwitterMehmet Keçeci on VimeoMehmet Keçeci on WordpressMehmet Keçeci on Youtube
Mehmet Keçeci
Physicist
Mehmet Keçeci (Kececi, Kecheci)
PhD. Student in Physics, 2001-3+2018 (Thesis Term): Fizik doktora öğrencisi, Tez dönemi.
Master of Science in Physics (MSc.): Fizik Bilim Uzmanı (1998-2001)
Occupational Safety Specialist, OSS: İş Güvenliği Uzmanı, İGU, 2016
Portion of Lesson is finished 2001-2003 (PhD. Doctorate - Physics)
Physicist: Fizikçi

Mefumetto Kecheji
メフメット ケチェジ
めふめつと けちえじ
محمت (محمد) كچه‌جى
Мехмет Кечеджи

Research Areas: Quantum Field Theory (QFT), Instanton, Conformal Field Theory (CFT), High Energy Physics (HEP), Particle Physics, High Magnetic Fields, Hydrocarbons Behaviour, Biophysics, Astrophysics, Cosmology, Cosmogony, Bioinformatics, Nanotechnology, Programming Languages, Web Servers, Information Technology (IT), Software, Operating Systems (OSs), History of Science and Technology, Philosophy of Science, Ethics, Science and Technology Management, Leadership, Morals and Religion, Interdisciplinary Relationship, Health Information System (HIS), Occupational Safety, Data Bases, Big Data, Superconductivity, Medical Physics, Radioactivity, Internet of Things (IoTs), Mathematical Physics, Electronics, Intelligent Systems, Education, Physics Education, Philosophy of Physics, Book/e-Book Publish & Edit, CMS, SEO, E-Learning, LMS, L&D, Open Digital Badges, Blockchain, Cryptocurrency.

Affiliation Scientific Journals, Duty at International Scientific Publications: Reviewer

International Scientific Programs: Member of Technical Program Committee (TPC)

International Papers: 2n-Dimensional at Fujii Model Instanton-Like Solutions and Coupling Constant's Role between Instantons with Higher Derivatives. Turkish Journal of Physics
Turk. J. Phys., 35, (2011), 173-178. Mehmet Keçeci
DOI: 10.3906/fiz-1012-66

Online CV (Keçeci Model CV)
1. https://issuu.com/hiperteknoloji/docs/cv-mk (English: Keçeci Model CV, updated: Güncellenen)
2. https://www.kotobee.com/ebook/mkececi#/loading (English: Keçeci Model CV)
3. https://education.microsoft.com/Story/Lesson?token=v9eGC (English)
4. https://education.microsoft.com/Story/Lesson?token=k0o4P (Turkish)
5. https://1drv.ms/o/s!AhhtzpemsW4-hGelP3_wPK3xU9al (English)
6. https://1drv.ms/o/s!AhhtzpemsW4-hGvMecE0bYVR2I3N (Turkish)
7. https://www.youtube.com/watch?v=jq2r7-suRkw
8. https://vimeo.com/218462945
9. http://fliphtml5.com/bookcase/fxth
10. https://mix.office.com/watch/iqdf24j1efu4
11. https://docs.google.com/presentation/d/1ZR8BapjoTxcyuY-YuPFUUZvtHTiJRawEFNsn0f2XjX4/pub
12. https://sway.com/2CKhCaImWnWPz83I
13. https://docs.com/kececi/6848/kececi-model-cv
14. https://www.slideshare.net/hiperteknoloji/kececi-model-cv
15. https://issuu.com/hiperteknoloji/docs/cv-mk
16. https://education.microsoft.com/Status?token=EeDJmtL6

Leave a Comment