setionobengkulu

Just another WordPress.com site

Algorotma dan Struktur data

PERHITUNGAN PENCARIAN DATA

#include<iostream>

#include<string>

using namespace std;

void main()

{

string kode[10],nama[10],cari;

long int harga[10],pilih,rata,ketemu[10],jumlah=0;

string lagi=”Y”;//inisialisasi kondisi perulangan

int i=0;//indeks array mulai dari 0

while((lagi==”Y”) || (lagi==”y”)){

cout<<“>>>>>>INPUT DATA BARANG<<<<<<\n”;

cout<<“KODE BARANG :”;cin>>kode[i];

cout<<“NAMA BARANG :”;cin>>nama[i];

cout<<“HARGA BARANG :”;cin>>harga[i];

cout<<“>============================<\n”;

i++; //kenaikan indeks array

cout<<”    INPUT DATA LAGI(Y/T) :”;cin>>lagi;

cout<<“>=============================<\n”;

}

system(“cls”);

cout<<“=      1. PEMBELIAN      =\n”;

cout<<“=      2. DATA BARANG    =\n”;

cout<<“===============================\n”;

cout<<”           PILIH (1/2) : “;cin>>pilih;

if (pilih==1){  //pilih cari kode barang

cout<<“Masukkan kode barang  :”;cin>>cari;

int ketemu=0; //kode barang belum ketemu

for (int j=0;j<i;j++){

if (cari==kode[j]){

ketemu=1; //kode barang ketemu

cout<<“NAMA BARANG  :”<<nama[j];

cout<<“HARGA BARANG :”<<harga[j];

}

}

if (ketemu==0)

cout<<” KODE BARANG TIDAK DITEMUKAN !!!\n”;

}

if (pilih==2){  //pilih cari kode barang

for(int a=0;a<i;a++){

cout<<kode[a]<<” “<<nama[a]<<” “<<harga[a]<<endl;

jumlah=jumlah+harga[a];

}

}

cout<<“========================================\n”;

rata=jumlah/i;

cout<<rata;

if (ketemu==0)

cout<<” KODE BARANG TIDAK DITEMUKAN !!!\n”;

system(“pause”);

}

 

 

PERHITUNGAN JUMLAH RATA-RATA BARANG

#include<iostream>

using namespace std;

void main()

{

int n;

char kode[10];

long int harga,total=0;

float rata;

cout<<“masukkan jumlah barang :”;cin>>n;

cout<<“=========================\n”;

for(int i=1;i<=n;i++){

cout<<“masukkan kode barang :”;cin>>kode;

cout<<“masukkan harga barang :”;cin>>harga;

total=total+harga;

}

rata=total/n;

cout<<“===============================\n”;

cout<<“Rata-rata harga barang :Rp. “<<rata<<endl;

system(“pause”);

}

 

PERHITUNGAN JUMLAH RATA-RATA BARANG BERTIPE STRING

#include<iostream>

#include<string>

using namespace std;

void main()

{

int n;

string kode[10];//deklarasi variabel array bertipe string

long int harga[10],total=0;

float rata;

cout<<“Masukkan jumlah barang :”;cin>>n;

cout<<“============================\n”;

for(int i=0;i<n;i++){

cout<<“Masukkan kode barang  :”;cin>>kode[i];

cout<<“Masukkan harga barang :”;cin>>harga[i];

total=total+harga[i];

}

rata=total/n;

cout<<“=============================\n”;

cout<<“Rata-rata harga barang :Rp. “<<rata<<endl;

for(int i=0;i<n;i++)

cout<<kode[i]<<” + “<<harga[i]<<endl;

system(“pause”);

}

 

 

Menghitung volume

#include<iostream>

using namespace std;

void balok(){

float p,l,t;

float vbalok;

cout<<“masukkan panjang balok :”;cin>>p;

cout<<“masukkan lebar balok   :”;cin>>l;

cout<<“masukkan tinggi balok  :”;cin>>t;

vbalok=p*l*t;

cout<<“volume balok           :”<<vbalok<<endl;

}

void tabung(){

float r,t;

float vtabung;

cout<<“masukkan jari-jari tabung :”;cin>>r;

cout<<“masukkan tinggi tabung    :”;cin>>t;

vtabung=3.14*r*r*t;

cout<<“volume tabung             :”<<vtabung<<endl;

}

void bola(){

float r;

float vbola;

cout<<“masukkan jari-jari bola :”;cin>>r;

vbola=3.14*r*r*r*4/3;

cout<<“volume bola             :”<<vbola<<endl;

}

void exit(){

system(“exit”);

}

void main(){

awal:

double pilih;

cout<<“hitung volume\n”;

cout<<“1.balok\n2.tabung\n3.bola\n4.exit\n”;

cout<<“masukkan pilihan(1\2\3\4) :”;cin>>pilih;

cout<<“===============================\n”;

if(pilih==1){

balok();

}

else if(pilih==2){

tabung();

}

else if(pilih==3){

bola();

}

else if(pilih==4){

exit();

}

else

goto awal;

cout<<“==========================\n”;

system(“pause”);

}

#include<iostream>

using namespace std;

void main()

{

for(int i=3;i>=1;i–){

for(int j=4;j>=1;j–)

cout<<i;

cout<<endl;

}

system(“pause”);

}

 

 

 

PERULANGAN TERSARANG III

#include<iostream>

using namespace std;

void main()

{

for(int i=1;i<=4;i++)

for(int j=1;j<=4;j++)

cout<<i;

system(“pause”);

}

PERULANGAN TERSARANG III

#include<iostream>

using namespace std;

void main()

{

for(int i=3;i>=1;i–){

for(int j=4;j>=1;j–)

cout<<i;

cout<<endl;

}

system(“pause”);

}

 

Rumus segitiga

#include<iostream>

using namespace std;

void garis(){

cout<<“=====================\n”;

cout<<”   SELAMAT DATANG\n”;

}

int kuadrat(int a){

int hasil=a*a;

return(hasil);

}

float segitiga(int a,int t){

float luas;

luas=a*t*0.5;

return(luas);

}

float lingkaran(int r){

float luas;

luas=3.14*kuadrat(r);

return(luas);

}

void main(){

cout<<kuadrat(2);

garis();

int b;

cout<<” Masukkan sebuah bilangan :”;cin>>b;

cout<<” Nilai” <<b<<” * “<<b<<” = “<<kuadrat(b)<<endl;

int a,t,r;

cout<<“masukkan alas:”;cin>>a;

cout<<“masukkan tinggi:”;cin>>t;

cout<<” luas segitiga = “<<segitiga(a,t);

cout<<“masukkan jari-jari:”;cin>>r;

cout<<” luas lingkaran = “<<lingkaran(r);

system(“pause”);

}


PROGRAM MATRIKS

#include<iostream>

#include<string>

using namespace std;

void main()

{

int A[10][10],B[10][10],C[10][10],m,n,k,i,j;

cout<<“masukkan jumlah baris:”;cin>>m;

cout<<“masukkan jumlah kolom:”;cin>>n;

for(int i=1;i<=m;i++){

for(int j=1;j<=n;j++){

cout<<“A(<<i<<j<<) :”;cin>>A[i][j];

}

}

cout<<“=========================\n”;

cout<<“konstanta pengali :”;cin>>k;

for(int i=1;i<=m;i++)

for(int j=1;j<=n;j++)

B[i][j]=k*A[i][j];

for(int i=1;i<=m;i++)

for(int j=1;j<=n;j++)

C[i][j]=B[i][j]+A[i][j];

cout<<“matrik A  \n”;

for(int i=1;i<=m;i++){

for(int j=1;j<=n;j++)

cout<<A[i][j];

cout<<endl;

}

cout<<“matrik B \n”;

for(int i=1;i<=m;i++){

for(int j=1;j<=n;j++)

cout<<B[i][j];

cout<<endl;

}

cout<<“matriks C\n”;

for(int i=1;i<=m;i++){

for(int j=1;j<=n;j++)

cout<<C[i][j];

cout<<endl;

}

cout<<“=======================\n”;

cout<<“HASIL KALI MATRIKS A DAN B DITAMBAH C\n”;

for(int i=1;i<=m;i++)

for(int j=1;j<=n;j++)

cout<<A[i][j]<<” * “<<B[i][j]<<” + “<<C[i][j]<<

” = “<<A[i][j]*B[i][j]+C[i][j]<<endl;

system(“pause”);

}

 

fungsi

#include<iostream>

#include<string>

using namespace std;

void main()

{

int a,b,c;

cout<<“masukkan bilangan 1 :”;cin>>a;

cout<<“masukkan bilangan 2 :”;cin>>b;

cout<<“=========================\n”;

if(a>b)c=a;

if(a<b)c=b;

cout<<“nilai yang paling terbesar adalah:”<<c<<endl;

system(“pause”);

}

 

PROGRAM PERBANDINGAN ANTARA BILANGAN

#include<iostream>

#include<string>

using namespace std;

void main()

{

int bilangan,a,b,c,d,besar=0;

cout<<“masukkan bilangan A :”;cin>>a;

cout<<“masukkan bilangan B :”;cin>>b;

cout<<“masukkan bilangan C :”;cin>>c;

cout<<“masukkan bilangan D :”;cin>>d;

cout<<“=========================\n”;

for(int i=1;i<5;i++){

if(besar<a)

besar=a;

else if(besar<b)

besar=b;

else if(besar<c)

besar=c;

else if(besar<d)

besar=d;

}

cout<<“bilangan terbesar adalah:”<<besar<<endl;

system(“pause”);

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: