#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <ctime>
#include <algorithm>
using namespace std;
/*
//p.214 no.10
class Person{
string name;
public:
Person() { name=""; }
Person(string name){ this->name = name;}
string getName() { return name;}
void setName(string name) { this->name = name; }
};
class Family{
string name;
Person *p;
int Size;
public:
Family(string name, int Size);
void setName(int index, string name);
void show();
~Family();
};
Family::Family(string name, int Size){
this->name = name;
this->Size = Size;
p = new Person [Size];
}
Family::~Family(){
delete p;
}
void Family::setName(int index, string name) {
p[index].setName(name);
}
void Family::show() {
cout << name + " 가족은 다음과 같이 " << Size << "명 입니다." << endl;
for(int i=0; i<Size; i++) {
cout << p[i].getName() << '\t';
}
cout << endl;
}
int main(){
Family *simpson = new Family("Simpson", 3);
simpson->setName(0, "Mr. Simpson");
simpson->setName(1, "Mrs. Simpson");
simpson->setName(2, "Bart Simpson");
simpson->show();
delete simpson;
}
*/
/*
//p.215 no.11
class Container{
private:
int Size;
public:
Container() {Size = 10;}
void Fill() { Size = 10;}
void consume() {Size--; }
int getSize() { return Size; }
};
class CoffeeVendingMachine{
Container tong[3];
void Fill();
void selectEspresso();
void selectAmericano();
void selectSugarCoffee();
void show();
public:
void run();
};
void CoffeeVendingMachine::Fill(){
tong[0].Fill();
tong[1].Fill();
tong[2].Fill();
show();
}
void CoffeeVendingMachine::selectEspresso(){
tong[0].consume();
tong[1].consume();
}
void CoffeeVendingMachine::selectAmericano(){
tong[0].consume();
tong[1].consume();
tong[1].consume();
}
void CoffeeVendingMachine::selectSugarCoffee(){
tong[0].consume();
tong[1].consume();
tong[1].consume();
tong[2].consume();
}
void CoffeeVendingMachine::show(){
cout<< "커피 "<< tong[0].getSize() << ", ";
cout<< "물 "<< tong[1].getSize()<< ", ";
cout<< "설탕 "<< tong[2].getSize()<<endl;
}
void CoffeeVendingMachine::run(){
int n;
cout << "***** 커피자판기를 작동합니다. *****" << endl;
while(1){
if(tong[0].getSize()==0||tong[1].getSize()==0||tong[2].getSize()==0){
cout << "원료가 부족합니다." ;
break;
}
else{
cout << "메뉴를 눌러주세요(1:에스프레소, 2:아메리카노, 3:설탕커피, 4:잔량보기, 5:채우기)>>";
cin >> n;
if(n==1){
selectEspresso();
cout<< "에스프레소 드세요"<<endl;
}
else if(n==2){
selectAmericano();
cout<< "아메리카노 드세요"<<endl;
}
else if(n==3){
selectSugarCoffee();
cout<< "설탕커피 드세요"<<endl;
}
else if(n==4){show();}
else if(n==5){Fill();}
}
}
}
int main(){
CoffeeVendingMachine v;
v.run();
}
*/
/*
//p.216 no.12
class Circle{
int radius;
string name;
public:
void setCircle(string name, int radius);
double getArea();
string getName();
};
class CircleManaer{
Circle *p;
int Size;
public:
CircleManaer();
~CircleManaer();
void searchByName();
void searchByArea();
};
CircleManaer::CircleManaer(int Size){
cin>>Size;
circlearray[Size];
}
void setCircle
int main(){
}
*/
//p.217 no.13
class Histogram{
string text;
int arr[26];
public:
Histogram();
Histogram(string text);
void put(string text);
void putc(char c);
void print();
~Histogram();
};
Histogram::Histogram(){
}
Histogram::Histogram(string text){
this->text=text;
}
void Histogram::put(string text){
this->text+=text;
}
void Histogram::putc(char c){
this->text+=c;
}
Histogram::~Histogram(){
}
void Histogram::print(){
for(int i=0; i<26; i++)
arr[i] = 0;
cout << text << endl << endl;
//소문자화
for(int k=0; k<text.length(); k++) {
if(isalpha(text[k])) {
char c = tolower(text[k]);
arr[c - 'a']++;
}
}
int alpha=0;
for(int i=0; i<26; i++) alpha += arr[i];
cout << "총 알파벳 수 " << alpha << endl;
cout << endl;
for(int i=0; i<26; i++) {
cout << char('a'+i) << " (" << arr[i] << ")" << " : ";
for(int j=0; j<arr[i]; j++)
cout << '*';
cout << endl;}
}
int main(){
Histogram elvisHisto("Wise men sat, only fools rush in But I can't help, ");
elvisHisto.put("falling in love with you");
elvisHisto.putc('-');
elvisHisto.put("Elvis Presley");
elvisHisto.print();
}