C언어 kg->g
VER.0
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class KgToG
{
private:
int kg, g;
public:
void getKg();
void calcKgToG();
void prnKgToG();
};
void KgToG::getKg()
{
cout << "몇 kg? : ";
cin >> kg;
}
void KgToG::calcKgToG()
{
g = kg * 1000;
}
void KgToG::prnKgToG()
{
cout << kg << "kg -> " << g << "g"<< endl;
}
int main()
{
KgToG my;
my.getKg();
my.calcKgToG();
my.prnKgToG();
}
VER.1
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class KgToG
{
private:
int kg, g;
public:
void getKg();
void calcKgToG();
void prnKgToG();
void clear();
};
void KgToG::getKg()
{
cout << "몇 kg? : ";
cin >> kg;
}
void KgToG::calcKgToG()
{
g = kg * 1000;
}
void KgToG::prnKgToG()
{
cout << kg << "kg -> " << g << "g"<< endl;
}
void KgToG::clear()
{
kg = 5;
}
int main()
{
KgToG my,your;
my.getKg();
my.calcKgToG();
my.prnKgToG();
your.clear();
your.calcKgToG();
your.prnKgToG();
}
VER.2
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class KgToG
{
private:
int kg, g;
public:
void getKg();
void calcKgToG();
void prnKgToG();
void clear();
};
void KgToG::getKg()
{
cout << "몇 kg? : ";
cin >> kg;
}
void KgToG::calcKgToG()
{
g = kg * 1000;
}
void KgToG::prnKgToG()
{
cout << kg << "kg -> " << g << "g"<< endl;
}
void KgToG::clear()
{
kg = 5;
}
int main()
{
KgToG my,your;
int n;
cout << "몇 kg?";
cin >>n;
KgToG k3(n);
k3.getKg();
k3.calcKgToG();
k3.prnKgToG();
my.getKg();
my.calcKgToG();
my.prnKgToG();
your.clear();
your.calcKgToG();
your.prnKgToG();
}