At this time I will discuss about the two-dimensional array which calculates the amount of data, calculate the average and then create a display like a table using two-dimensional array. Hmmm ... this is my lab assignment, I pengeen for this to all my friends. Please check it out ...:)
Algoritma :
Procedure array_penjualan(input : a,b,c,d,e ; char ; data ; integer ; output : total,jumlah ; integer , rata ; double)
Deklarasi
a,b,c,d,e : char of array (input)
data,total,jumlah : integer of array
rata : double of array
Deskripsi
read(a,b,c,d,e)
for i <= 0 to 5 do
for j <= 0 to 5 do
data[i][j]
endfor
endfor
for i <= 0 to 5 do
total[i]=0
jumlah[i]=0
for i <= 0 to 5 do
total[i]=total[i]+data[i][j]
jumlah[i]=jumlah[i]+data[j][i]
endfor
endfor
rata[0]=0
jumlah[5]=0
for i <= 0 to 5 do
rata[i]=(rata[i]+(jumlah[i]/5))
jumlah[5]=jumlah[5]+jumlah[i]
endfor
Berikut kode programnya :
#include <iostream.h>
#include <conio.h>
class penjualan{
public:
friend ostream& operator<<(ostream&, penjualan&);
void cetak_nama();
void masuk_data();
void hitung();
penjualan();
private:
char a[50],b[50],c[50],d[50],e[50];
int data[100][100];
int total[50],jumlah[50];
double rata[50];
};
penjualan::penjualan(){
cout<<"Data Sales"<<endl;
}
void penjualan::cetak_nama(){
int k=1;
cout<<"Masukkan Nama "<<k<<"=";cin>>a;
cout<<"Masukkan Nama "<<k+1<<"=";cin>>b;
cout<<"Masukkan Nama "<<k+2<<"=";cin>>c;
cout<<"Masukkan Nama "<<k+3<<"=";cin>>d;
cout<<"Masukkan Nama "<<k+4<<"=";cin>>e;
}
void penjualan::masuk_data(){
for(int i=0; i<5; i++)
for(int j=0; j<5; j++){
cout<<"Masukkan data ke ["<<i+1<<"] ["<<j+1<<"] :";
cin>>data[i][j];
}
}
void penjualan::hitung(){
for(int i=0; i<5; i++){
total[i]=0;
jumlah[i]=0;
for(int j=0; j<5; j++){
total[i]=total[i]+data[i][j];
jumlah[i]=jumlah[i]+data[j][i];
}}
rata[0]=0;
jumlah[5]=0;
for(int i=0; i<5; i++){
rata[i]=(rata[i]+(jumlah[i]/5));
jumlah[5]=jumlah[5]+jumlah[i];
}
}
ostream& operator<<(ostream& out,penjualan& m){
out<<"No\tNama\tJan\tFeb\tMar\tApr\tMei\tTotal"<<endl;
out<<"1.";
out<<"\t";
for(int i=0; i<strlen(m.a); i++){
out<<m.a[i];
}
out<<"\t";
for(int i=0; i<5; i++){
out<<m.data[0][i]<<"\t";
}
out<<m.total[0];
out<<endl;
out<<"2.";
out<<"\t";
for(int i=0; i<strlen(m.b); i++){
out<<m.b[i];
}
out<<"\t";
for(int i=0; i<5; i++){
out<<m.data[1][i]<<"\t";
}
out<<m.total[1];
out<<endl;
out<<"3.";
out<<"\t";
for(int i=0; i<strlen(m.c); i++){
out<<m.c[i];
}
out<<"\t";
for(int i=0; i<5; i++){
out<<m.data[2][i]<<"\t";
}
out<<m.total[2];
out<<endl;
out<<"4.";
out<<"\t";
for(int i=0; i<strlen(m.d); i++){
out<<m.d[i];
}
out<<"\t";
for(int i=0; i<5; i++){
out<<m.data[3][i]<<"\t";
}
out<<m.total[3];
out<<endl;
out<<"5.";
out<<"\t";
for(int i=0; i<strlen(m.e); i++){
out<<m.e[i];
}
out<<"\t";
for(int i=0; i<5; i++){
out<<m.data[4][i]<<"\t";
}
out<<m.total[4];
out<<endl;
out<<"\ttotal\t";
for(int i=0; i<5; i++){
out<<m.jumlah[i]<<"\t";
}
out<<m.jumlah[5];
out<<endl;
out<<"\trata2\t";
for(int i=0; i<5; i++){
out<<m.rata[i]<<"\t";
}
out<<"Tot Penj 5 Bln";
out<<endl;
}
int main()
{
penjualan z;
z.cetak_nama();
z.masuk_data();
z.hitung();
cout<<z;
system("PAUSE");
return EXIT_SUCCESS;
}
explanation:
The above program is a program of two-dimensional array which is contained within the function calculates the amount of data and averages. In this program, the excess can create a view in tabular form. As the data that we usually see. But in the above example is sales data sales.
0 komentar:
Posting Komentar