Analisis Masalah:Tabel Input-Proses-Output
Contoh Kasus:Mencari rata -rata bilangan bulat positif
Inputnya : Masukan nilai a
Process: jumlah ß jumlah+b
i ß i +1
Output: rata: "+rata"
Algorithm Design:Flowchart
Program C++:
#include <iostream>
#include <string>
using namespace std;
class Rata {
public:
void input();
void output();
private:
int a,b,i;
int jumlah;
float rata; };
void Rata::input(){
cout<<"Masukan nilai a :";cin >> a;
cout<<endl; }
void Rata::output(){
jumlah =0;
i =1;
while (!(i>a)){
cout<<"Masukan nilai b :";cin >> b;
jumlah =jumlah+b;
i =i+1; }
cout<<endl;
rata =jumlah/a;
cout << "Rata : "<<rata << endl;}
int main()
{ Rata Hasil;
Hasil.input();
Hasil.output();
system ("PAUSE");
return EXIT_SUCCESS; }
0 komentar:
Posting Komentar