Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
using namespace std;
class rock;
class ball {
int m; //質量
int s; //表面積
public:
ball(int x, int y)
{
m = x;
s = y;
}
int get_m()
{
return m;
}
friend int greater(ball b, rock r);
};
class rock {
int v; //体積
int m; //質量
public:
rock(int a, int b)
{
v = a;
m = b;
}
int get_m()
{
return m;
}
friend int greater(ball b, rock r);
};
int greater(ball b, rock r)
{
//質量を引き算
return b.m - r.m;
}
int main() {
ball b(1023, 2345);
rock r(118, 320);
cout << "ball:" << b.get_m() << endl;
cout << "rock:" << r.get_m() << endl;
int t;
t = greater(b, r); //ボールと岩の質量差
cout << "ボールと岩の質量差:" << t << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment