Algorithm/C++

열혈 C++ 프로그래밍 OOP 단계별 프로젝트 01단계

Printemp 2023. 5. 26.

아직 C++과 관련해서 특별히 공부한 게 많지 않은 지금, C 스타일로 구현하는 것을 목표로 한다.

 

/*
* Banking System Ver 0.1
*/

#include <iostream>

#define count 1

struct ac
{
	int ID=0;
	char name[100]={0};
	int amount=0;
};
ac account[100] {};

void MakeAccount(int &a, char b[], int &c);
void deposit();
void withdraw();
void account_fuc();

int main()
{
	int num;
	int i=0;
	while(1)
	{
		std::cout<<"-----Menu_____"<<std::endl;
		std::cout<<"1. 계좌개설"<<std::endl;
		std::cout<<"2. 입  금"<<std::endl;
		std::cout<<"3. 출  금"<<std::endl;
		std::cout<<"4. 계좌정보 전체 출력"<<std::endl;
		std::cout<<"5. 프로그램 종료"<<std::endl;
		std::cout<<"선택: ";
		std::cin>>num;
	
			if(num==1)
		{
			MakeAccount(account[i].ID, account[i].name, account[i].amount);
			i++;
		}
		else if(num==2)
		{
			
			deposit();
		}
		else if(num==3)
		{
			withdraw();
		}
		else if(num==4)
		{
			account_fuc();
		}
		else if(num==5)
			break;
	
	}
	
	return 0;
	
}
void MakeAccount(int &a, char b[], int &c)
{
	std::cout<<"[계좌개설]"<<std::endl;
	std::cout<<"계좌ID: ";
	std::cin>>a;
	std::cout<<"이  름: ";
	std::cin>>b;
	std::cout<<"입금액: ";
	std::cin>>c;
}
void deposit()
{
	int acID=0;
	int ac=0;
	int am=0;
	std::cout<<"[입  금]";
	std::cout<<"계좌ID: ";
	std::cin>>acID;
	while(1)
	{
		if(account[ac].ID==acID)
			break;
		else
			ac++;
	}
	std::cout<<"입금액: ";
	std::cin>>am;
	account[ac].amount+=am;
	std::cout<<"입금완료"<<std::endl;
	
}
void withdraw()
{
	int acID=0;
	int ac=0;
	int am=0;
	std::cout<<"[입  금]";
	std::cout<<"계좌ID: ";
	std::cin>>acID;
	while(1)
	{
		if(account[ac].ID==acID)
			break;
		else
			ac++;
	}
	std::cout<<"출금액: ";
	std::cin>>am;
	account[ac].amount-=am;
	std::cout<<"출금완료"<<std::endl;
}
void account_fuc()
{
	int i=0;
	while(1)
	{
		if(account[i].ID==0)
			break;
		else
		{
			std::cout<<"계좌ID: "<<account[i].ID<<std::endl;
			std::cout<<"이름: "<<account[i].name<<std::endl;
			std::cout<<"잔액: "<<account[i].amount<<std::endl;
			i++;
		}
		
	}
}

댓글

💲 추천 글