OOPp (Bài 3)(Ngày) constructor desstructor getter-setter bài tậ

//.h #pragma once #include<iostream> using namespace std; class Ngay { int date,month,year; public: Ngay(void); Ngay(int ); Ngay(int ,int ); Ngay(int ,int ,int ); Ngay(const Ngay &); ~Ngay(void); void Xuat(); }; //.cpp #include "Ngay.h" Ngay::Ngay(void) { date =1; month=1; year=1; } Ngay::Ngay(int a) { year=a; month=1; date=1; } Ngay::Ngay(int a,int b) { month=b; year=a; date=1; } Ngay::Ngay(int a,int b,int c) { if(c<0) { date=1; } else{ date=c; } month=b; year=a; } Ngay::Ngay(const Ngay &a) { date=a.date; month=a.month; year=a.year; } void Ngay::Xuat() { cout<<date<<"/"<<month<<"/"<<year; cout<<endl; } Ngay::~Ngay(void) { } //main() #include"Ngay.h" int main() { Ngay a; a.Xuat(); Ngay b(2013); b.Xuat(); Ngay c(2013,5); c.Xuat(); Ngay d(2013,2,3); d.Xuat(); Ngay e(2013,1,31); e.Xuat(); Ngay f(2013,2,-8); f.Xuat(); Ngay g(b); g.Xuat(); Ngay h=d; h.Xuat(); system("pause"); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.