Latihan 4.3
1. DEV C++
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
int nilai[3],a,min,maks;
cout<<"masukan berapa nilai yang mw di masukan : ";
cin>>min;
for(a=1;a<=min;a++){
cout<<"Masukkan nilai ke-"<<a<<":";
cin>>nilai[a];
}
maks = nilai[1];
for(a=1;a<=min;a++){
if(nilai[a] > maks){
maks = nilai[a];
}
}
cout<<"nilai maksimum adalah : "<<maks<<endl;
getch();
return 0;
}
Latihan 4.4
1. DEV C++
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int a[20], i, j, k ,n;
cout<<" masukan jumlah array : ";
cin>>n;
cout<<" masukkan aray "<<n<<" elemen : \n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"aray adalah : ";
for(i=0;i<n;i++){
for(j=i+1;j<n;){
if(a[j]==a[i]){
for(k=j;k<n;k++){
a[k]=a[k+1];
}
n--;
}
else{
j++;
}
}
}
for(i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(int argc, char** argv) {
char nama [50], golongan, pendidikan;
float lembur, tunjab, tunpen, gapok, gatot;
int jamker;
cout<<"\tPROGRAM HITUNG GAJI KARYAWAN";
cout<<"\n============================================"<<endl;
cout<<"keterangan : "<<endl;
cout<<" (SMA = 1, D1= 2, D3 = 3, S1=
4)"<<endl<<endl;
cout<<"\n\nNama Karyawan : ";gets(nama);
cout<<"Golongan Jabatan[1/2/3] :
";cin>>golongan;
cout<<"Pendidikan[1,2,3] :
";cin>>pendidikan;
cout<<"Jumlah jam kerja : ";cin>>jamker;
gapok = 300000;
cout<<"\nKaryawan Yang Bernama "<<nama;
switch (golongan)
{
case '1':
tunjab = gapok*0.05;
break;
case '2':
tunjab = gapok*0.1;
break;
case '3':
tunjab = gapok*0.15;
break;
default:
tunjab = 0;
}
switch (pendidikan)
{
case '1':
tunpen = gapok*0.025;
break;
case '2':
tunpen = gapok*0.05;
break;
case '3':
tunpen = gapok*0.2;
break;
case '4':
tunpen = gapok*0.3;
break;
default:
tunpen = 0;
}
if (jamker < 8 || jamker > 24)
{
lembur = 0;
}
else
lembur = (jamker - 8)*3500;
gatot = tunjab + tunpen + lembur + gapok;
cout<<"\n\nHonor Yang Diterima";
cout<<"\n\tTunjangan Jabatan Rp. "<<tunjab;
cout<<"\n\tTunjangan Pendidikan Rp.
"<<tunpen;
cout<<"\n\tHonor Lembur Rp. "<<lembur;
cout<<"\n\t --------------- +";
cout<<"\n\tGaji Total Rp. "<<gatot;
return 0;
}