Analisis Masalah:Tabel Input-Proses-Output
Contoh Kasus: carilah konversi suhu dari Celcius menjadi reamur, fahrenheit, dan kelvin
Inputnya :Masukan besar suhu celcius
Process: Rß 4 / 5 * C
F ß 9 / 5 *C + 32
K ßC +273
K ßC +273
Output: Hasilnya
Algorithm Design:Flowchart
Program C++:
#include <iostream>
#include <string>
using namespace std;
class Konversi{
friend ostream& operator<<(ostream&, Konversi&);
friend istream& operator>>(istream&, Konversi&);
public:
Konversi(){};
void suhu_R(){R = 4/5.0*C;}
void suhu_F(){F = 9/5.0*C+32;}
void suhu_K(){K = C+273;}
private:
float C,R,F,K;
};
istream& operator>>(istream& in, Konversi& input){
cout<<"Program Konversi Suhu dari Celcius menjadi Reamur, Fahrenheit, dan Kelvin"<<endl;
cout<<"Masukan besar suhu Celcius :";in>>input.C;
return in;
}
ostream& operator<<(ostream& out, Konversi& output){
cout << output.C<<" derajat Celcius = "<<output.R<<" derajat Reamur" << endl;
cout << output.C<<" derajat Celcius = "<<output.F<<" derajat Fahrenheit "<< endl;
cout << output.C<<" derajat Celcius = "<<output.K<<" derajat Kelvin" << endl;
return out;
}
int main()
{ Konversi x;
cin>>x;
x.suhu_R();
x.suhu_F();
x.suhu_K();
cout<<x;
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
0 komentar:
Posting Komentar