program Array dan contoh penerapannya

tugas pertemuan 9

1). menampilkan nama bulan

scriptnya :

#include <iostream>

#include <conio.h>

#include <iomanip>

#include <string>

 

using namespace std;

 

int main()

{

string A[4][3]={“Januari”,”Februari”,”Maret”,”April”,”Mei”,”Juni”,”Juli”,”Agustus”,”September”,”October”,”November”,”Desember”};

int i,j;

 

cout<<”   Program nama bulan”<<endl;

cout<<”       Tahun 2018   “<<endl;

cout<<“======================”<<endl;

for(i=0; i<4; i++)

{

for(j=0; j<3; j++)

{

cout<<setiosflags (ios::left)<<setw(10)<<A[i][j];

}

cout<<endl;

}

return 0;

}

outputnya :

ganti.png

2).membuat program penjualan sederhana

scriptnya :

/**< penjualan array dimensi 2 */
#include <iostream>
#include <iomanip>
#include <conio.h>

using namespace std;

int main()
{

int i,j;
int data_jual [4][4];
string nama_barang;
for(i=1; i<=3; i++)
{
for(j=1; j<=3; j++)
{
cout<< ” Data ke – “<<i<<” “<<j<<endl;
cout<< ” Nama Barang : “;
cin>> nama_barang;
cout<< ” Jumlah penjualan : “;
cin>> data_jual[i][j];
}
}
cout<<endl;
cout<< “hasil penjualan Barang”<<endl;
cout<< “—————————“<<endl;
cout<< “NO 2001 2002 2003″<<endl;
cout<< “—————————“<<endl;
for(i=1; i<=3; i++)
{
cout<< setiosflags(ios :: left)<<setw(3)<<i;
for(j=1; j<=3; j++)
{
cout<< setiosflags(ios :: right)<<setw(6);
cout<< data_jual [i][j];
cout<< ” “;
}
cout<<endl;
}
cout<< ” ————————– “<<endl;
getch();
return 0;
}

outputnya :

itu.png

 

sekian informasi dari saya terimakasih:-)

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s