Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by thuan ( 5 years ago )
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<time.h>
#include<math.h>
using namespace std;
class Date
{
private:
int day, month, year;
public:
Date()
{
this->day = 0;
this->month = 0;
this->year = 0;
}
Date(int day, int month, int year)
{
this->day = day;
this->month = month;
this->year = month;
}
Date(const Date &x)
{
day = x.day;
month = x.month;
year = x.year;
}
void input()
{
cout << "\tInput day: ";
cin >> day;
cout << "\tInput month: ";
cin >> month;
cout << "\tInput year: ";
cin >> year;
}
void output()
{
cout << day << "/" << month << "/" << year;
}
int getDay()
{
return day;
}
void setDay(int day)
{
this->day = day;
}
int getMonth()
{
return month;
}
int getYear()
{
return year;
}
int displayMonthPastToCurrent()
{
int n = 0;
time_t current_time;
struct tm local_time;
time(¤t_time);
localtime_s(&local_time, ¤t_time);
int yearCurrent = local_time.tm_year + 1900;
int monthCurrent = local_time.tm_mon + 1;
int dateCurrent = local_time.tm_mday;
if (this->day + dateCurrent >= 60)
n += 2;
else if (this->day + dateCurrent >= 30)
n++;
n += ((12 - this->month) + monthCurrent);
if (yearCurrent - this->year > 0)
n += ((yearCurrent - this->year > 0) * 12);
return n;
}
};
class bookBank
{
protected:
string name, cmnd, nameBook;
Date date;
float interest;
int n = date.displayMonthPastToCurrent();
public:
bookBank()
{
this->name = "Nguyen Van Thuan";
this->cmnd = "261644044";
this->nameBook = "Thuan Dep trai";
this->interest = 0;
}
bookBank(string name, string cmnd, string nameBook, float interest, int n, Date x)
{
this->name = name;
this->cmnd = cmnd;
this->nameBook = nameBook;
this->interest = interest;
this->n = n;
this->date = x;
}
virtual void Input()
{
rewind(stdin);
cout << "\nInput name: ";
getline(cin, name);
rewind(stdin);
cout << "Input cmnd: ";
getline(cin, cmnd);
rewind(stdin);
cout << "Input name book: ";
getline(cin, nameBook);
cout << "Input interest: ";
cin >> interest;
cout << "Input date month year creat book:\n";
date.input();
}
virtual void Output()
{
cout << "Name: " << name;
cout << "\nCMND: " << cmnd;
cout << "\nName book: " << nameBook;
cout << "\nDate month year creat book:";
date.output();
}
virtual float calculateInterest()
{
return 0;
}
};
class bookNoPerriod:public bookBank
{
public:
void Input()
{
bookBank::Input();
}
void Output()
{
bookBank::Output();
}
float calculateInterest()
{
return this->n * this->interest;
}
};
class bookPerriod:public bookBank
{
private:
int period;
public:
bookPerriod(string name, string cmnd, string nameBook, float interest, int n, Date x, int period)
{
this->name = name;
this->cmnd = cmnd;
this->nameBook = nameBook;
this->interest = interest;
this->n = n;
this->date = x;
this->period = period;
}
bookPerriod()
{
this->period = 0;
}
void Input()
{
bookBank::Input();
cout << "\nInput period: ";
cin >> period;
}
void Output()
{
bookBank::Output();
cout << "\nPeriod: " << period;
}
float calculateInterest()
{
if (this->n > 0)
return 0;
return this->period * this->n * this->interest;
}
};
class bank
{
private:
vector<bookBank*> listBookBank;
public:
void Menu()
{
bookBank* x=NULL;
while (true)
{
cout << "\n==========Menu==========";
cout << "\n1:Inut list book bank";
cout << "\n2: Output list book bank";
cout << "\n0: Exit";
int selectMenu;
do
{
cout << "\nInput select: ";
cin >> selectMenu;
if (selectMenu < 0 || selectMenu>2)
cout << "\t==>Please check again!\n";
} while (selectMenu < 0 || selectMenu>2);
if (selectMenu == 0)
break;
else if(selectMenu == 1)
{
int selectTypeBook;
//1: No period
//2: Period
do
{
cout << "\n======Menu Type book bank======";
cout << "\n1:No period";
cout << "\n2: Period";
cout << "\nInput type book bank: ";
cin >> selectTypeBook;
if (selectTypeBook < 0 || selectTypeBook>2)
cout << "\t==>Please check again!\n";
} while (selectTypeBook < 1 || selectTypeBook>2);
if (selectTypeBook == 1)
x = new bookPerriod;
else if (selectMenu == 2)
x = new bookNoPerriod;
x->Input();
listBookBank.push_back(x);
}
else if (selectMenu == 2)
{
cout << "\n=============List=============\n";
int length = listBookBank.size();
for (int i = 0; i < length; ++i)
{
cout << "\n====Info " << i + 1 << "====\n";
listBookBank[i]->Output();
}
}
}
}
};
int main()
{
/*Date d(20, 11, 2002);
Date d2(d);
Date d3;
d3 = d2;
d2.setDay(16);
d3.output();*/
bank b;
b.Menu();
cout << endl;
system("pause");
return 0;
}
Revise this Paste