Buat algoritma dan program untuk menghitung konversi dari m ke cm dan inchi
Analisis::
- input : misalkan m (mewakili meter)
- proses :
1 meter = 100 cm
1 inci = 2.54 cm
cm = m*100
inci= m*100/2.54
-output : tulis (cm, inci)
flowchart
misalkan nilai meter = 5
C++
#include <cstdlib>
#include <iostream>
using namespace std;
class Konversi{
public:
void input();
int proses();
void output();
private :
int meter;
float hasil, cm, inci;
protected:
};
void Konversi :: input(){
cout<<"Masukan nilai meter :";
cin>>meter;
}
int Konversi :: proses(){
//cout<<"nilai cm= "<<endl;
cm=meter*100;
// cout<<"nilai inci= "<<endl;
inci=meter*100/2.54;
}
void Konversi :: output(){
cout<<"nilai cm :";
cout<<cm;
cout<<endl;
cout<<"nilai inci :"<<endl;
cout<<inci;
cout<<endl;
}
int main(int argc, char *argv[])
{
Konversi run;
run.input();
run.proses();
run.output();
system("PAUSE");
return EXIT_SUCCESS;
}
0 comments:
Post a Comment