Skip to content

Instantly share code, notes, and snippets.

@chomado
Last active August 29, 2015 14:04
Show Gist options
  • Save chomado/7c8451a4411774a2467d to your computer and use it in GitHub Desktop.
Save chomado/7c8451a4411774a2467d to your computer and use it in GitHub Desktop.
// doesn't work
#include <string>
#include <iostream>
class Human {
private:
std::string full_name;
int height;
int wight;
public:
Human(std::string name, int h, int w); // コンストラクタ
std::string name() { return full_name; }
int get_height() { return height; }
int get_weight() { return weight; }
void grow_fat(int dw);
void slim_off(int dw);
};
#include <string>
#include "a.h"
Human::Human(string name, int h, int w)
{
full_name = name;
height = h;
weight = w;
}
void Human::grow_fat(int dw)
{
weight += dw;
}
void Human::slim_off(int dw)
{
weight -= dw;
}
#include <iostream>
#include <string>
#include "a.h"
using namespace std;
void print_Human(string title, Human *p)
{
std::cout << title << p->name() << " "
<< p->get_height() << "com " << p->get_weight() << "kg" << std::endl;
}
int main()
{
Human chomado("chomado", 152, 45);
chomado.grow_fat(2);
print_Human("chomado = ", &chomado);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment