C++/프로그램 연습

은행계좌 파일나눠서 써보기 (account.h, account.cpp, main.cpp)

appmaster 2020. 9. 30. 15:07
using namespace std;

class Account {
private:
	int number;
	string name;
	double balance;

public:
	Account();
	Account(int createNumber, string createName, int createBalance);
	void display();
	void set_deposit(int money);
	void set_withdraw(int money);
	void set_addInterst();

};
#include <stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include "account.h"

using namespace std;


Account::Account() {
	number = 0;
	name = "";
	balance = 0;
}

Account::Account(int createNumber, string createName, int createBalance) {
	number = createNumber;
	name = createName;
	balance = createBalance;
}


void Account::display() {
	cout << "계좌번호 : " << number << " 이름 : " << name << " 잔고 : " << balance <<"\n";
}

void Account::set_deposit(int money) {
	balance += money;
}

void Account::set_withdraw(int money) {
	balance -= money;
}

void Account::set_addInterst() {
	balance = (balance * 0.03)+balance;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
#include "account.h"

using namespace std;

int main(void) {
	Account act1(1543, "loveyou", 5000);
	Account act2(1684, "metoo", 2000);

	act1.display();
	act2.display();

	act1.set_deposit(100000);
	act1.set_deposit(200000);

	act2.set_deposit(50000);

	act1.set_addInterst();
	act2.set_addInterst();

	act1.set_withdraw(50000);
	act2.set_withdraw(10000);

	act1.display();
	act2.display();

	return 0;
}

'C++ > 프로그램 연습' 카테고리의 다른 글

Tower 실습하기  (0) 2020.09.30
은행계좌 만들기  (0) 2020.09.30
커피 주문하기  (0) 2020.09.30