/// .h
#pragma once
#include<iostream>
using namespace std;
class Thoi_Gian
{
private:
int gio,phut,giay;
public:
// khởi tạo mặc định
Thoi_Gian(void);
/// khởi tạo tham tham số truyền vào
Thoi_Gian(int ,int );
Thoi_Gian(int );
Thoi_Gian(int ,int ,int );
Thoi_Gian(const Thoi_Gian &);
~Thoi_Gian(void);
void xuat();
};
//.cpp
#include "Thoi_Gian.h"
Thoi_Gian::Thoi_Gian(void)
{
gio=0;
phut=0;
giay=0;
}
Thoi_Gian::Thoi_Gian(int a)
{
gio=a;
phut=0;
giay=0;
}
Thoi_Gian::Thoi_Gian(int a,int b)
{
gio=a;
phut=b;
giay=0;
}
Thoi_Gian::Thoi_Gian(int a,int b,int c)
{
gio=a;
phut=b;
giay=c;
}
void Thoi_Gian::xuat()
{
cout<<gio/10<<gio%10<<":"<<phut/10<<phut%10<<":"<<giay/10<<giay%10;
cout<<endl;
}
Thoi_Gian::Thoi_Gian(const Thoi_Gian &a)
{
gio=a.gio;
phut=a.phut;
giay=a.giay;
}
Thoi_Gian::~Thoi_Gian(void)
{
}
/main
#include"Thoi_Gian.h"
int main()
{
Thoi_Gian a;
a.xuat();
Thoi_Gian b(7);
b.xuat();
Thoi_Gian c(7,30);
c.xuat();
Thoi_Gian d(8,12,56);
d.xuat();
Thoi_Gian e(b);
e.xuat();
Thoi_Gian f=c;
f.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.