On this new label,,, I specialize to describe the issues contained in the textbook.
in each chapter, I take one issue, I identified the problem, and then create a flowchart outlining the program.
for the program I'm using dev c + + created by overloading.
for this first article, I will discuss about the first meeting (sequence).
to the material I took from the dictates of algorithms and programming.
in each chapter, I take one issue, I identified the problem, and then create a flowchart outlining the program.
for the program I'm using dev c + + created by overloading.
for this first article, I will discuss about the first meeting (sequence).
to the material I took from the dictates of algorithms and programming.
Analysis of the problem :
- determine the input: alas, tinggi
- determine data type : int a, int t, float luas;
- the process of calculate the area : luas = a*t/2
flowchart and a program to calculate the area of a triangle
#include <cstdlib>
#include <iostream>
using namespace std;
class segitiga {
friend istream& operator>>(istream&, segitiga&);
friend ostream& operator<<(ostream&, segitiga&);
public :
void hasil(){
luas = a*t/2;
}
private :
int a,t;
float luas;
};
istream& operator>>(istream& in, segitiga& datar){
cout<<"Menghitung luas segitiga"<<endl;
cout<<"masukkan alas = ";
in>>datar.a;
cout<<"masukkan tinggi = ";
in>>datar.t;
return in;
}
ostream& operator<<(ostream& out, segitiga& bangun){
bangun.hasil();
out<<"luas segitiga = "<<bangun.luas<<endl;
return out;
}
int main()
{
segitiga A;
cin>>A;
cout<<A;
system("PAUSE");
return 0;
}
Tidak ada komentar:
Posting Komentar