154p no.10 다시 풀 것
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <ctime>
using namespace std;
/*
//150p.no.2
//independenceDay 출력이 문제 배열?
class Date{
public:
int x,y,z,n;
Date(string v);
Date(int year, int month, int day);
int getYear();
int getMonth();
int getDay();
char show();
};
Date::Date(int year, int month, int day){
x=year, y=month, z=day;
}
int Date::getYear(){
return x;
}
int Date::getMonth(){
return y;
}
int Date::getDay(){
return z;
}
Date::Date(string v){
int n = stoi(v);
}
char Date::show(){
cout<<n<<endl;
}
int main() {
Date birth(2014, 3, 20);
Date independenceDay("1945/8/15");
independenceDay.show();
cout<< birth.getYear()<<','<<birth.getMonth()<<','<< birth.getDay()<<endl;
}
*/
/*
//150p no.03
class Account{
string name;
int id;
int balance;
public:
Account(string n, int i, int bal);
void deposit(int money);
int withdraw(int money);
int inquiry();
string getOwner(){ return name; }
};
Account::Account(string n, int i, int bal){
name=n;
id=i;
balance=bal;
}
void Account::deposit(int money){
balance+=money;
}
int Account::withdraw(int money){
balance-=money;
}
int Account::inquiry(){
return balance;
}
int main(){
Account a("kitae", 1, 5000);
a.deposit(50000);
cout<<a.getOwner()<<"의 잔액은 "<< a.inquiry()<<endl;
int money = a.withdraw(20000);
cout<< a.getOwner()<<"의 잔액은 "<< a.inquiry()<<endl;
}
*/
/*
//151p no.04
class CoffeeMachine{
int coffee;
int water;
int sugar;
public:
CoffeeMachine(int cof, int wat, int sug);
void drinkEspresso();
void dirnkAmericano();
void drinkSugarCoffee();
void show();
void Fill();
};
CoffeeMachine::CoffeeMachine(int cof, int wat, int sug){
coffee=cof;
water=wat;
sugar=sug;
}
void CoffeeMachine::drinkEspresso(){
coffee-= 1;
water-=1;
}
void CoffeeMachine::dirnkAmericano(){
coffee-=1;
water-=2;
}
void CoffeeMachine::drinkSugarCoffee(){
coffee-=1;
water-=2;
sugar-=1;
}
void CoffeeMachine::show(){
cout<<"커피 머신 상태, 커피:"<< coffee<<" 물:"<<water<<" 설탕:"<<sugar<<endl;
}
void CoffeeMachine::Fill(){
coffee=10;
water=10;
sugar=10;
}
int main(){
CoffeeMachine java(5, 10, 3);
java.drinkEspresso();
java.show();
java.dirnkAmericano();
java.show();
java.drinkSugarCoffee();
java.show();
java.Fill();
java.show();
}
*/
/*
//151p no.05
class Random{
public:
Random();
int next();
int nextInRange(int low, int high);
};
Random::Random() {
srand((unsigned)time(0));
}
int Random::next() {
return rand();
}
int Random::nextInRange(int low, int high) {
int range=(high-low)+1;
return low + (rand() % range);
}
int main() {
Random r;
cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
for(int i=0; i<10; i++) {
int n = r.next();
cout << n << ' ';
}
cout << endl << endl << "-- 2에서 " << "4 까지의 랜덤 정수 10 개 --" << endl;
for(int i=0; i<10; i++) {
int n = r.nextInRange(2, 4);
cout << n << ' ';
}
cout << endl;
}
*/
/*
//152p no.06
class Random{
public:
Random();
int next();
int nextInRange(int low, int high);
};
Random::Random() {
srand((unsigned)time(0));
}
int Random::next() {
return rand();
}
int Random::nextInRange(int low, int high) {
int range=(high-low)+1;
return low + (rand() % range);
}
int main() {
Random r;
int i=0, k=0;
cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
while(i < 10){
int n = r.next();
if (n%2==0){
i++;
cout << n << ' ';
}
}
cout << endl << endl << "-- 2에서 " << "4 까지의 랜덤 정수 10 개 --" << endl;
while(k<10){
int n = r.nextInRange(2, 4);
if (n%2==0){
k++;
cout << n << ' ';
}
}
cout << endl;
}
*/
/*
//153p no.08
class Integer{
public:
int Integer;
void get();
void Set(int some);
void isEven();
};
int main(){
Integer n(30);
cout<<n.get()<<'';
n.Set(50);
cout<< n.get()<<'';
Integer m("300");
cout<<m.get<<'';
cout << m.isEven();
}
*/
/*
//153p no.09
class Oval{
int width;
int height;
public:
Oval();
Oval(int w, int h);
~Oval();
int getWidth();
int getHeight();
void Set(int w, int h);
void show();
};
Oval::Oval(){
width=height=1;
}
Oval::Oval(int w, int h){
width=w;
height=h;
}
Oval::~Oval(){
cout<< "Oval 소멸 : ";
show();
}
int Oval::getWidth(){
return width;
}
int Oval::getHeight(){
return height;
}
void Oval:: Set(int w, int h){
width = w; height = h;
}
void Oval::show(){
cout << "width = " << width << ", " << "height = " << height << endl;
}
int main(){
Oval a, b(3, 4);
a.Set(10, 20);
a.show();
cout<< b.getWidth()<<","<<b.getHeight()<< endl;
}
*/
/*
//154p no.10
class Add{
};
class Sub{
};
class Mul{
};
class Div{
};
int main(){
cout<<"두 정수와 연산자를 입력하세요>>";
cin>>a>>b>>c;
}
*/
/*
//155p no.11
class Box{
int width, height;
char Fill;
public:
Box(int w, int h){setSize(w,h); Fill='*';}
void setFill(char f) {Fill=f;}
void setSize(int w, int h) {width=w; height=h;}
void draw();
};
void Box::draw(){
for(int n=0; n<height; n++){
for(int n=0; n<height; n++){
cout<<Fill;
cout<<endl;
}
}
}
int main() {
Box b(10, 2);
b.draw();
cout<<endl;
b.setSize(7, 4);
b.setFill('^');
b.draw();
}
*/