검색결과 리스트
♪C++/소스에 해당되는 글 4건
- 2018.09.19 c++ stack
- 2018.09.18 c++ oop프로젝트 8장
- 2017.11.10 열혈강의 3장 연습문제 3-1 3-2
- 2017.10.09 성우 1장 OOP 단계별 프로젝트
글
c++ stack
#include<iostream>
using namespace::std;
template<typename T>
class Stack
{
T arr[5];
int index;
int front;
public:
Stack() : index(0) {};
void Push(T num)
{
arr[index++] = num;
}
void Pop()
{
cout << arr[--index] << endl;
}
void Empty()
{
}
};
int main()
{
Stack<int> st;
st.Push(10);
st.Push(20);
st.Push(30);
st.Pop();
st.Pop();
st.Pop();
}
'♪C++ > 소스' 카테고리의 다른 글
c++ oop프로젝트 8장 (0) | 2018.09.18 |
---|---|
열혈강의 3장 연습문제 3-1 3-2 (0) | 2017.11.10 |
성우 1장 OOP 단계별 프로젝트 (0) | 2017.10.09 |
설정
트랙백
댓글
글
c++ oop프로젝트 8장
#include <iostream>
#include <cstring>
using namespace std;
const int NAME_LEN = 20;
enum { MAKE = 1, DEPOSIT, WITHDRAW, INQUIRE, EXIT };
class Account
{
int id; // 계좌번호
int balance; // 잔 액
char *name; // 고객이름
public:
Account(int id, char *name, int balance);
Account(const Account& _Account);
~Account();
int getID() const; //계좌조회
virtual void AddMoney(int money); //입금
void MinMoney(int money); //출금
int getBalance() const; //잔액조회
char* getName() const; //이름
virtual void ShowAllData();
};
Account::Account(int id, char *name, int balance) {
this->id = id;
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
this->balance = balance;
}
Account::Account(const Account& _Account)
{
this->id = _Account.id;
this->name = new char[strlen(_Account.name) + 1];
strcpy(this->name, _Account.name);
this->balance = _Account.balance;
}
Account::~Account()
{
delete name;
}
int Account::getID() const
{
return id;
}
void Account:: AddMoney(int money)
{
this->balance += money;
}
int Account:: getBalance() const
{
return balance;
}
void Account:: MinMoney(int money)
{
balance -= money;
}
char* Account:: getName() const
{
return name;
}
void Account::ShowAllData()
{
cout << "ID : " << id << endl;
cout << "이름 : " <<name << endl;
cout << "잔액 : " << balance << endl;
}
//신용계좌 입금시 1프로 추가
class FaithAccount : public Account
{
public:
FaithAccount(int id, char *name, int balance) : Account(id, name, balance + balance * 0.01)
{
}
void AddMoney(int money)
{
Account::AddMoney(money + money * 0.01);
}
};
//기부계좌 입금액 1프로 기부 기부총액 저장
class ContriAccount : public Account
{
int contri_sum; //기부금 합
public:
ContriAccount(int id, char *name, int balance) : Account(id, name, balance - balance * 0.01)
{
contri_sum += balance * 0.01;
}
void AddMoney(int money)
{
Account::AddMoney(money - money * 0.01);
contri_sum += money * 0.01;
}
void ShowAllData()
{
Account::ShowAllData();
cout << "총기부액 : " << contri_sum << endl;
}
};
class AccManger
{
Account* pArr[100]; // Account 저장을 위한 배열
int index; // 저장된 Account 수
public:
AccManger() :index(0)
{};
void ShowMenu(void); // 메뉴출력
void MakeAccount(void); // 계좌개설을 위한 함수
void DepositMoney(void); // 입 금
void WithdrawMoney(void); // 출 금
void Inquire(void); // 잔액조회
};
int main(void)
{
int choice;
AccManger ac;
while (1)
{
ac.ShowMenu();
cout << "선택: ";
cin >> choice;
cout << endl;
switch (choice)
{
case MAKE:
ac.MakeAccount();
break;
case DEPOSIT:
ac.DepositMoney();
break;
case WITHDRAW:
ac.WithdrawMoney();
break;
case INQUIRE:
ac.Inquire();
break;
case EXIT:
return 0;
default:
cout << "Illegal selection.." << endl;
}
}
return 0;
}
void AccManger::ShowMenu(void)
{
cout << "-----Menu------" << endl;
cout << "1. 계좌개설" << endl;
cout << "2. 입 금" << endl;
cout << "3. 출 금" << endl;
cout << "4. 계좌정보 전체 출력" << endl;
cout << "5. 프로그램 종료" << endl;
}
void AccManger::MakeAccount(void)
{
int id;
char name[NAME_LEN];
int balance;
int sel;
cout << "1. 일반계좌 개설" << endl;
cout << "2. 신용계좌 개설" << endl;
cout << "3. 기부계좌 개설" << endl;
cout << ">>";
cin >> sel;
cout << "[계좌개설]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "이 름: "; cin >> name;
cout << "입금액: "; cin >> balance;
cout << endl;
if (sel == 1)
pArr[index++] = new Account(id, name, balance);
else if (sel == 2)
pArr[index++] = new FaithAccount(id, name, balance);
else if (sel == 3)
pArr[index++] = new ContriAccount(id, name, balance);
else
cout << "오류"<<endl;
}
void AccManger::DepositMoney(void)
{
int money;
int id;
cout << "[입 금]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "입금액: "; cin >> money;
for (int i = 0; i<index; i++)
{
if (pArr[i]->getID() == id)
{
pArr[i]->AddMoney(money);
cout << "입금완료" << endl << endl;
return;
}
}
cout << "유효하지 않은 ID 입니다." << endl << endl;
}
void AccManger::WithdrawMoney(void)
{
int money;
int id;
cout << "[출 금]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "출금액: "; cin >> money;
for (int i = 0; i<index; i++)
{
if (pArr[i]->getID() == id)
{
if (pArr[i]->getBalance()<money)
{
cout << "잔액부족" << endl << endl;
return;
}
pArr[i]->MinMoney(money);
cout << "출금완료" << endl << endl;
return;
}
}
cout << "유효하지 않은 ID 입니다." << endl << endl;
}
void AccManger::Inquire(void)
{
for (int i = 0; i<index; i++)
{
pArr[i]->ShowAllData();
}
}
'♪C++ > 소스' 카테고리의 다른 글
c++ stack (0) | 2018.09.19 |
---|---|
열혈강의 3장 연습문제 3-1 3-2 (0) | 2017.11.10 |
성우 1장 OOP 단계별 프로젝트 (0) | 2017.10.09 |
설정
트랙백
댓글
글
열혈강의 3장 연습문제 3-1 3-2
#include<iostream>
using namespace std;
class Calculator
{
private:
float sum;
int add_num;
int min_num;
int div_num;
int mul_num;
public:
void Init()
{
sum=0;
add_num=0;
min_num=0;
div_num=0;
mul_num=0;
}
float Add(float s1,float s2)
{
add_num++;
sum=s1+s2;
return sum;
}
float Min(float s1,float s2)
{
min_num++;
sum=s1-s2;
return sum;
}
float Div(float s1,float s2)
{
div_num++;
sum=s1/s2;
return sum;
}
float mul(float s1,float s2)
{
mul_num++;
sum=s1*s2;
return sum;
}
void ShowOpCount()
{
cout<<"덧셈 :"<<add_num<<" 뺼셈 : "<<min_num<<" 나눗셈 : "<<div_num<<" 곱셈 : "<<mul_num<<endl;
}
};
int main(void)
{
Calculator cal;
cal.Init();
cout<<"3+5="<<cal.Add(3,5)<<endl;
cout<<"3/5="<<cal.Div(3,5)<<endl;
cout<<"12*4="<<cal.Min(12,4)<<endl;
cout<<"12/4="<<cal.Div(12,4)<<endl;
cal.ShowOpCount();
return 0;
}
#include<iostream>
#include<string>
using namespace std;
class Printer{
private:
char str[100];
public:
void SetString(char *string);
void ShowString();
};
void Printer::SetString(char *string)
{
strcpy(str,string);
}
void Printer::ShowString()
{
cout<<str<<endl;
}
int main()
{
Printer pnt;
pnt.SetString("Hello world!");
pnt.ShowString();
pnt.SetString("I love C++");
pnt.ShowString();
return 0;
return 0;
}
'♪C++ > 소스' 카테고리의 다른 글
c++ stack (0) | 2018.09.19 |
---|---|
c++ oop프로젝트 8장 (0) | 2018.09.18 |
성우 1장 OOP 단계별 프로젝트 (0) | 2017.10.09 |
설정
트랙백
댓글
글
성우 1장 OOP 단계별 프로젝트
/*
* 윤성우 1장 OOP 단계별 프로젝트
*/
#include <iostream>
#include <cstring>
using namespace std;
const int NAME_LEN=20;
void ShowMenu(void); // 메뉴출력
void MakeAccount(void); // 계좌개설을 위한 함수
void DepositMoney(void); // 입 금
void WithdrawMoney(void); // 출 금
void ShowAllAccInfo(void); // 잔액조회
enum {MAKE=1, DEPOSIT, WITHDRAW, INQUIRE, EXIT};
typedef struct
{
int accID; // 계좌번호
int balance; // 잔 액
char cusName[NAME_LEN]; // 고객이름
} Account;
Account accArr[100]; // Account 저장을 위한 배열
int accNum=0; // 저장된 Account 수
int main(void)
{
int choice;
while(1)
{
ShowMenu();
cout<<"선택: ";
cin>>choice;
cout<<endl;
switch(choice)
{
case MAKE:
MakeAccount();
break;
case DEPOSIT:
DepositMoney();
break;
case WITHDRAW:
WithdrawMoney();
break;
case INQUIRE:
ShowAllAccInfo();
break;
case EXIT:
return 0;
default:
cout<<"Illegal selection.."<<endl;
}
}
return 0;
}
void ShowMenu(void)
{
cout<<"-----Menu------"<<endl;
cout<<"1. 계좌개설"<<endl;
cout<<"2. 입 금"<<endl;
cout<<"3. 출 금"<<endl;
cout<<"4. 계좌정보 전체 출력"<<endl;
cout<<"5. 프로그램 종료"<<endl;
}
void MakeAccount(void)
{
int id;
char name[NAME_LEN];
int balance;
cout<<"[계좌개설]"<<endl;
cout<<"계좌ID: "; cin>>id;
cout<<"이 름: "; cin>>name;
cout<<"입금액: "; cin>>balance;
cout<<endl;
accArr[accNum].accID=id;
accArr[accNum].balance=balance;
strcpy(accArr[accNum].cusName, name);
accNum++;
}
void DepositMoney(void)
{
int money;
int id;
cout<<"[입 금]"<<endl;
cout<<"계좌ID: "; cin>>id;
cout<<"입금액: "; cin>>money;
for(int i=0; i<accNum; i++)
{
if(accArr[i].accID==id)
{
accArr[i].balance+=money;
cout<<"입금완료"<<endl<<endl;
return;
}
}
cout<<"유효하지 않은 ID 입니다."<<endl<<endl;
}
void WithdrawMoney(void)
{
int money;
int id;
cout<<"[출 금]"<<endl;
cout<<"계좌ID: "; cin>>id;
cout<<"출금액: "; cin>>money;
for(int i=0; i<accNum; i++)
{
if(accArr[i].accID==id)
{
if(accArr[i].balance<money)
{
cout<<"잔액부족"<<endl<<endl;
return;
}
accArr[i].balance-=money;
cout<<"출금완료"<<endl<<endl;
return;
}
}
cout<<"유효하지 않은 ID 입니다."<<endl<<endl;
}
void ShowAllAccInfo(void)
{
for(int i=0; i<accNum; i++)
{
cout<<"계좌ID: "<<accArr[i].accID<<endl;
cout<<"이 름: "<<accArr[i].cusName<<endl;
cout<<"잔 액: "<<accArr[i].balance<<endl<<endl;
}
}
'♪C++ > 소스' 카테고리의 다른 글
c++ stack (0) | 2018.09.19 |
---|---|
c++ oop프로젝트 8장 (0) | 2018.09.18 |
열혈강의 3장 연습문제 3-1 3-2 (0) | 2017.11.10 |