HW10
#include <iostream>
#include <cstring>
#pragma warning (disable : 4996)
using namespace std;
class Time {
private:
int hour;
int min;
public:
Time();
Time(int, int);
Time(double);
Time(const Time &tr);
Time plus(const Time &tr);
void setHour(int);
int getHour() const;
void setMin(int);
int getMin() const;
};
Time::Time(){
this->hour = 0;
this->min = 0;
}
Time::Time(int hour, int min) {
this->hour = hour;
this->min = min;
}
Time::Time(double time) {
this->hour = int(time);
this->min = int((time - double(this->hour)) * 60);
}
Time::Time(const Time &tr) {
this->hour = tr.hour;
this->min = tr.min;
}
Time Time::plus(const Time &tr) {
this->hour += tr.getHour();
this->min += tr.getMin();
if (this->min >= 60) {
this->hour += this->min / 60;
this->min %= 60;
}
return *this;
}
void Time::setHour(int hour) {
this->hour = hour;
}
void Time::setMin(int min) {
this->min = min;
}
int Time::getHour() const{
return this->hour;
}
int Time::getMin() const{
return this->min;
}
int main() {
Time a(3, 20), b;
cout << a.getHour() << "시간" << a.getMin() << "분" << endl;
b.setHour(4);
b.setMin(42);
cout << b.getHour() << "시간" << b.getMin() << "분" << endl;
Time res = a.plus(b);
cout << "두 시간을 더하면 : " << res.getHour() << "시간" << res.getMin() << "분" << endl;
return 0;
}
HW12
#include <iostream>
#include <cstring>
#pragma warning (disable : 4996)
using namespace std;
class Save {
private:
char name[20];
int capital;
int profit;
int tax;
int tot;
static double ratio;
public:
static double tax_ratio;
Save(const char *np = "아무개", int n = 0);
~Save() {};
void calculate();
static void set_ratio(double r);
char *getName() const;
int getCap() const;
int getPro() const;
int getTax() const;
int getTot() const;
double getRat() const;
double getTaxRat() const;
};
double Save::ratio = 0.2;
double Save::tax_ratio = 0.1;
Save::Save(const char *np, int n) {
if (np != NULL) {
strcpy(this->name, np);
}
this->capital = n;
}
void Save::calculate() {
this->profit = int(this->capital * this->ratio);
this->tax = int(this->profit * this->tax_ratio);
this->tot = int(this->capital + this->profit - this->tax);
}
void Save::set_ratio(double r){
Save::ratio = r;
}
char* Save::getName() const {
cout << "이름 : ";
return (char*)(this->name);
}
int Save::getCap() const {
cout << endl << "원금 : ";
return this->capital;
}
int Save::getPro() const {
cout << endl << "이자소득 : ";
return this->profit;
}
int Save::getTax() const {
cout << endl << "세금 : ";
return this->tax;
}
int Save::getTot() const {
cout << endl << "총금액 : ";
return this->tot;
}
double Save::getRat() const {
cout << endl << "이율 : ";
return this->ratio;
}
double Save::getTaxRat() const {
cout << endl << "세율 : ";
return this->tax_ratio;
}
int main() {
Save a("철이", 1000000), b("메텔", 2000000);
a.calculate();
cout << a.getName();
cout << a.getCap();
cout << a.getPro();
cout << a.getTax();
cout << a.getTot();
cout << a.getRat();
cout << a.getTaxRat() << endl << endl;
Save::tax_ratio = 0.15;
Save::set_ratio(0.25);
b.calculate();
cout << b.getName();
cout << b.getCap();
cout << b.getPro();
cout << b.getTax();
cout << b.getTot();
cout << b.getRat();
cout << b.getTaxRat() << endl << endl;
return 0;
}