[[확인문제 1]]
>ACC.h<
#ifndef _ACC_H_
#define _ACC_H_
class ACC
{
public:
int accID;
char pw[5];
char name[20];
int bal;
void menu(int &sel);
void mkacc();
void save();
void withdraw();
void balance();
};
#endif
>main.cpp<
#include "ACC.h"
#include <iostream>
int main()
{
ACC reval = {1111};
int choice;
while(1)
{
reval.menu(choice);
switch(choice)
{
case 1:
reval.mkacc();
break;
case 2:
reval.save();
break;
case 3:
reval.withdraw();
break;
case 4:
reval.balance();
break;
case 5:
exit(1);
}
}
return 0;
}
>acc.cpp<
#include "ACC.h"
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using std::cin; using std::cout; using std::endl;
void ACC::menu(int &sel)
{
system("cls");
cout << "\n[ 메 뉴 선 택 ]\n\n";
cout << "1. 계좌등록\n";
cout << "2. 입 금\n";
cout << "3. 출 금\n";
cout << "4. 잔액조회\n";
cout << "5. 종 료\n";
cout << "\n\n선택 : [ ]\b\b";
cin >> sel;
}
void ACC::mkacc()
{
system("cls");
cout << "\n\n\t\t[ 계 좌 등 록 ]\n\n";
cout << "계좌번호 : " << accID << endl;
cout << "이 름 : ";
cin >> name;
cout << "비밀번호(4자리) : ";
cin >> pw;
cout << "입 금 액 : ";
cin >> bal;
cout << "\n\n\n\t\t계좌 등록 완료!" << "\n\n\t\t아무키나 누르면 메뉴로 돌아갑니다.";
getch();
}
void ACC::save()
{
system("cls");
int inmoney;
cout << "\n\n\t[ 입\t금 ]\n\n";
cout << "입금액 : ";
cin >> inmoney;
cout << "\n\n\n\t\t[" << inmoney << "]원 입금완료!\n\n";
cout << "\t\t아무키나 누르면 메뉴로 돌아갑니다.";
bal += inmoney;
getch();
}
void ACC::withdraw()
{
system("cls");
int outmoney;
cout << "\n\n\t[ 출\t금 ]\n\n";
cout << "출금액 : ";
cin >> outmoney;
if(outmoney <= bal)
{
cout << "\n\n\n\t\t[" << outmoney << "]원 출금 완료!\n\n";
bal -= outmoney;
}
else
{
cout << "\n\n\n\t\t잔액이 부족합니다.\n\t\t";
cout << "[" << name << "]회원님의 잔액은 [" << bal << "]원 입니다.";
}
cout << "\n\n\t\t아무키나 누르면 메뉴로 돌아갑니다.";
getch();
}
void ACC::balance()
{
system("cls");
cout << "\n\n\t[ 잔 액 조 회 ]\n\n";
cout << "계좌번호 : " << accID << endl;
cout << "\n\n\n\t\t[" << name << "]회원님의 잔액은 [" << bal << "]원 입니다.\n\n";
cout << "\t\t아무키나 누르면 메뉴로 돌아갑니다.";
getch();
}
[[확인문제 2]]
>TRI.h<
#ifndef _Triangle_H_
#define _Triangle_H_
class Triangle
{
public:
int base, height;
void SetArea(int baset, int heightt);
double GetArea();
};
#endif
>main.cpp<
#include "TRI.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int base, height;
cout << "\n *** 삼각형 넓이 구하기 ***\n\n";
cout << "밑변 : ";
cin >> base;
cout << "높이 : ";
cin >> height;
Triangle tri;
tri.SetArea(base, height);
cout << "삼각형의 넓이는 " << tri.GetArea() << "입니다\n";
return 0;
}
>TRI.cpp<
#include "TRI.h"
#include <iostream>
void Triangle::SetArea(int baset, int heightt)
{
base = baset;
height = heightt;
}
double Triangle::GetArea()
{
return (base*height)/2.0;
}
[[확인문제 3]]
>Calc.h<
#ifndef _Calc_H_
#define _Calc_h_
class Cal
{
public:
int sum;
void Init();
void RangeSum(int num1, int num2);
int GetrangeSum();
};
#endif
>main.cpp<
#include "Calc.h"
#include <iostream>
using std::cin; using std::cout; using std::endl;
int main()
{
int su1, su2;
cout << "두 수를 입력 하시오 : ";
cin >> su1 >> su2;
Cal ca;
ca.Init();
ca.RangeSum(su1, su2);
cout << endl << su1 << " ~ " << su2 << "의 합은 ["
<< ca.GetrangeSum() << "]입니다.\n";
return 0;
}
>Calc.cpp<
#include "Calc.h"
#include <iostream>
void Cal::Init()
{
sum =0;
}
void Cal::RangeSum(int num1, int num2)
{
if (num1 > num2)
{
int temp;
temp = num1;
num1 = num2;
num2 = temp;
}
for(int i = num1; i<=num2; i++)
{
sum += i;
}
}
int Cal::GetrangeSum()
{
return sum;
}
'과제모음' 카테고리의 다른 글
[C++]객체지향2 (0) | 2010.01.22 |
---|---|
[C++]객체지향(OOP) (0) | 2010.01.22 |
[C++]동적할당3 (0) | 2010.01.22 |
[C++]구조체와 클래스 (0) | 2010.01.22 |
[C++]클래스 (0) | 2010.01.22 |