#include <iostream>
#include <Math.h>
#include <conio.h>
#include <fstream>
#include <string.h>
using namespace std;
//--------------------------------------------------
// Class date bo sung cho chuc nang tinh lai
class Date {
private:
int d,m,y;
public:
Date() {
};
Date(int, int, int);
void refresh();
int SubDateToMonth(Date);
friend istream& operator >>(istream&i, Date &d);
friend ostream& operator <<(ostream&o, Date &d);
};
Date::Date(int a, int b, int c):d(a),m(b),y(c) {
};
void Date::refresh() {
switch(this->m) {
case 2: {
int max=(this->y%4==0)?28:29;
if(this->d>max) {
this->d=this->d-max;
this->m++;
this->refresh();
}
break;
}
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: {
if(this->d>31) {
this->d-=31;
this->m++;
if(this->m>12) {
this->m-=12;
this->y++;
}
this->refresh();
}
break;
}
case 4:
case 6:
case 9:
case 11: {
if(this->d>30) {
this->d=this->d-=30;
this->m++;
this->refresh();
}
break;
}
}
}
istream& operator >>(istream&i, Date &d) {
int day, month, year;
cout<<"Nhap ngay: ";
i>>d.d;
cout<<"Nhap thang: ";
i>>d.m;
cout<<"Nhap nam: ";
i>>d.y;
d.refresh();
return i;
}
ostream& operator <<(ostream&o, Date &d) {
o<<"ngay ";
o<<d.d;
o<<" thang ";
o<<d.m;
o<<" nam ";
o<<d.y;
return o;
}
int Date::SubDateToMonth(Date d) {
int temp = (this->y-d.y)*12;
temp+=this->m-d.m;
if(this->d<d.d) --temp;
return temp;
}
//-------------------------------------
// Class tai khoan
class TaiKhoan {
protected:
int id;
double soDu;
Date ngayLap;
public:
TaiKhoan() { };
TaiKhoan(int, double, Date);
virtual double TinhLai(Date )=0;
friend int main();
};
TaiKhoan::TaiKhoan(int a, double b, Date t):id(a),soDu(b),ngayLap(t) {
};
//---------------------------------
//Class Tai Khoan co ki han
class TaiKhoanKyHan: public TaiKhoan {
private:
float laisuat;
int kihan;
public:
TaiKhoanKyHan() {
};
TaiKhoanKyHan(int,double,Date,int);
double TinhLai(Date );
friend ostream& operator <<(ostream&o, TaiKhoanKyHan&tk);
};
TaiKhoanKyHan::TaiKhoanKyHan(int a,double b,Date t,int c):TaiKhoan(a,b,t), kihan(c) {
this->laisuat=0.015*this->kihan+((this->kihan-1)*0.003);
};
double TaiKhoanKyHan::TinhLai(Date t) {
int soThang = t.SubDateToMonth(this->ngayLap);
int soLanTinhLai = (int)soThang/kihan;
double lai = this->soDu*pow((1 + this->laisuat),soLanTinhLai) - this->soDu;
return lai;
};
ostream& operator <<(ostream&o, TaiKhoanKyHan&tk) {
o<<"ID: "<<tk.id<<endl;
o<<"So du: "<<tk.soDu<<endl;
o<<"Loai tai khoan: Tai khoan co ky han"<<endl;
o<<"Ky han: "<<tk.kihan<<" thang"<<endl;
o<<"Lai suat 1 chu ki: "<<tk.laisuat*100<<"%"<<endl;
o<<"Ngay lap: "<<tk.ngayLap<<endl;
o<<"----------------------"<<endl;
return o;
}
//----------------------------
// Class tai khoan k co ki han
class TaiKhoanKhongKyHan: public TaiKhoan {
private:
float laisuat = 0.01;
public:
TaiKhoanKhongKyHan() {
};
TaiKhoanKhongKyHan(int,double,Date);
double TinhLai(Date );
friend ostream& operator <<(ostream&o, TaiKhoanKhongKyHan&tk);
};
TaiKhoanKhongKyHan::TaiKhoanKhongKyHan(int a,double b,Date t):TaiKhoan(a,b,t) {
};
double TaiKhoanKhongKyHan::TinhLai(Date t) {
double lai = this->soDu*pow((1 + this->laisuat),t.SubDateToMonth(this->ngayLap)) - this->soDu;
return lai;
};
ostream& operator <<(ostream&o, TaiKhoanKhongKyHan&tk) {
o<<"ID: "<<tk.id<<endl;
o<<"So du: "<<tk.soDu<<endl;
o<<"Loai tai khoan: Tai khoan khong ky han"<<endl;
o<<"Lai suat 1 thang: "<<tk.laisuat*100<<"%"<<endl;
o<<"Ngay lap: "<<tk.ngayLap<<endl;
o<<"----------------------"<<endl;
return o;
}
//----------------------------
// Class quan li
class QuanLi {
private:
int n1,n2,idmax;
TaiKhoanKhongKyHan *t1;
TaiKhoanKyHan *t2;
Date now;
public:
QuanLi();
void Add(TaiKhoanKhongKyHan);
void Add(TaiKhoanKyHan);
void ShowKiHan();
void ShowKhongKiHan();
void TinhLai();
friend istream& operator >>(istream&i, QuanLi&ql);
friend int main();
};
QuanLi::QuanLi() {
this->idmax=1;
this->n1=0;
this->n2=0;
t1 = NULL;
t2 = NULL;
}
void QuanLi::Add(TaiKhoanKyHan tk) {
this->n2++;
TaiKhoanKyHan *temp = this->t2;
this->t2 = new TaiKhoanKyHan[this->n2];
for(int i=0; i<this->n2-1; i++) {
this->t2[i]=temp[i] ;
}
this->t2[this->n2-1] = tk;
}
void QuanLi::Add(TaiKhoanKhongKyHan tk) {
this->n1++;
TaiKhoanKhongKyHan *temp = this->t1;
this->t1 = new TaiKhoanKhongKyHan[this->n1];
for(int i=0; i<this->n1-1; i++) {
this->t1[i]=temp[i] ;
}
this->t1[this->n1-1] = tk;
}
istream& operator >>(istream&i, QuanLi&ql) {
double sodu;
Date date;
int kihan;
cout<<"------------"<<endl;
cout<<"ID: "<<ql.idmax<<endl;
cout<<"Nhap so du: ";
i>>sodu;
cout<<"Nhap ngay tao:"<<endl;
i>>date;
cout<<"Nhap ki han: ";
i>>kihan;
if(kihan==1) {
ql.Add(TaiKhoanKhongKyHan(ql.idmax,sodu,date));
++ql.idmax;
} else {
ql.Add(TaiKhoanKyHan(ql.idmax,sodu,date,kihan));
++ql.idmax;
}
return i;
};
//----------------------------
int main() {
QuanLi quanli;
bool cou = true;
while(cou) {
int choise;
system("cls");
cout<<"QUAN LI TAI KHOAN"<<endl;
cout<<"Vui long chon chuc nang: "<<endl;
cout<<"1. Them tai khoan"<<endl;
cout<<"2. Xem toan bo tai khoan"<<endl;
cout<<"3. Xem toan bo tai khoan khong ky han"<<endl;
cout<<"4. Xem toan bo tai khoan khong ky han"<<endl;
cout<<"5. Xem thong tin cua 1 tai khoan"<<endl;
cout<<"6. Xem lai cua 1 tai khoan"<<endl;
cout<<"7. Ket thuc chuong trinh"<<endl;
cout<<"8. Ghi file"<<endl;
cout<<"9. Doc file"<<endl;
cout<<"Chon: ";
cin>>choise;
switch(choise) {
case 1: {
system("cls");
int n;
cout<<"Nhap so luong tai khoan: ";
cin>>n;
for(int i=0; i<n; i++) cin>>quanli;
cout<<"Da nhap xong, nhan phim bat ki de tiep tuc";
getch();
break;
}
case 2: {
system("cls");
for(int i=0; i<quanli.n1; i++ ) {
cout<<quanli.t1[i];
};
for(int i=0; i<quanli.n2; i++ ) {
cout<<quanli.t2[i];
};
cout<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
case 3: {
system("cls");
for(int i=0; i<quanli.n1; i++ ) {
cout<<quanli.t1[i];
};
cout<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
case 4: {
system("cls");
for(int i=0; i<quanli.n2; i++ ) {
cout<<quanli.t2[i];
};
cout<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
case 5: {
system("cls");
int id;
begin:
cout<<endl<<"Nhap id: ";
cin>>id;
bool check = false;
for(int i = 0; i<quanli.n1; i++) {
if (quanli.t1[i].id==id) {
check=true;
cout<<quanli.t1[i];
break;
}
}
for(int i = 0; i<quanli.n2; i++) {
if (quanli.t2[i].id==id) {
check=true;
cout<<quanli.t2[i];
break;
}
}
if(!check) {
cout<<"Khong tim duoc id, id cao nhat la "<<quanli.idmax-1<<endl;
cout<<"Vui long chon lai id"<<endl;
getch();
goto begin;
}
cout<<endl<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
case 6: {
system("cls");
Date date;
int id;
cout<<"Ngay de tinh lai: ";
cin>>date;
begin1:
cout<<endl<<"Nhap id: ";
cin>>id;
static bool check = false;
for(int i = 0; i<quanli.n1; i++) {
if (quanli.t1[i].id==id) {
check=true;
cout<<quanli.t1[i];
cout<<"Lai tinh den "<<date<<" la: ";
cout<<quanli.t1[i].TinhLai(date)<<endl;
cout<<"----------------------";
break;
}
}
for(int i = 0; i<quanli.n2; i++) {
if (quanli.t2[i].id==id) {
check=true;
cout<<quanli.t2[i];
cout<<"Lai tinh den "<<date<<" la: ";
cout<<quanli.t2[i].TinhLai(date)<<endl;
cout<<"-----------------------";
break;
}
}
if(!check) {
cout<<"Khong tim duoc id, id cao nhat la "<<quanli.idmax-1<<endl;
cout<<"Vui long chon lai id"<<endl;
getch();
goto begin1;
}
cout<<endl<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
case 8: {
fstream input ("data.txt");
cout<<"check"; getchar();
input<<quanli.idmax<<"-"<<quanli.n1<<"-"<<quanli.n2<<"\n";
for(int i = 0; i<quanli.n1; i++ ){
input << quanli.t1[i].id << "- " <<quanli.t1[i].soDu <<" - "<<"\n";
}
cout<<"check";
for(int i = 0; i<quanli.n2; i++ ){
input << quanli.t2[i].id << "- " <<quanli.t2[i].soDu <<" - "<<"\n";
}
getchar();
input.close();
break;
}
case 7: {
cou = false;
break;
}
default: {
cout<<endl<<"Nhap sai!"<<endl<<"Nhan phim bat ki de tiep tuc";
getch();
break;
}
}
}
}
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.