Skip to content

Commit e943c29

Browse files
committed
init commit
1 parent 4c8e72e commit e943c29

22 files changed

+2223
-0
lines changed

Sorting & Searching.cpp

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
#include <cstdlib>
4+
5+
using namespace std;
6+
int a[999];
7+
int b;
8+
int search;
9+
int temp;
10+
bool flag1 = false;
11+
12+
void input()
13+
{
14+
cout<<"Input jumlah bilangan: "; cin>>b;
15+
for(int i=0; i<b; i++)
16+
{
17+
cout<<"Input bilangan ke-"<<(i+1)<<": "; cin>>a[i];
18+
}
19+
system("CLS");
20+
cout<<"Bilangan tersimpan!"<<endl<<endl;
21+
}
22+
23+
void bubble()
24+
{
25+
for(int k=0; k<b; k++)
26+
{
27+
for(int j=(b-1); j>0; j--)
28+
{
29+
if(a[j]<a[j-1])
30+
{
31+
temp=a[j];
32+
a[j]=a[j-1];
33+
a[j-1]=temp;
34+
}
35+
}
36+
}
37+
for(int l=0; l<b; l++)
38+
{
39+
cout<<a[l]<<" ";
40+
}
41+
cout<<endl<<"Press any key to continue..."<<endl<<endl;
42+
getch();
43+
system("CLS");
44+
}
45+
46+
void selection()
47+
{
48+
int min, m;
49+
bool swap;
50+
for(m=0; m<b; m++)
51+
{
52+
swap=false;
53+
min=m;
54+
for(int n=(b-1); n>m; n--)
55+
{
56+
if(a[min]>a[n])
57+
{
58+
min=n;
59+
swap=true;
60+
}
61+
}
62+
if(swap)
63+
{
64+
temp=a[min];
65+
a[min]=a[m];
66+
a[m]=temp;
67+
}
68+
}
69+
for(int o=0; o<b; o++)
70+
{
71+
cout<<a[o]<<" ";
72+
}
73+
cout<<endl<<"Press any key to continue..."<<endl<<endl;
74+
getch();
75+
system("CLS");
76+
}
77+
78+
void insertion()
79+
{
80+
int key, pp;
81+
for(int p=1; p<b; p++)
82+
{
83+
key=a[p];
84+
for(pp=(p-1); pp>=0; pp--)
85+
{
86+
if(key<a[pp])
87+
{
88+
a[pp+1]=a[pp];
89+
}
90+
else break;
91+
}
92+
a[pp+1]=key;
93+
}
94+
for(int q=0; q<b; q++)
95+
{
96+
cout<<a[q]<<" ";
97+
}
98+
cout<<endl<<"Press any key to continue..."<<endl<<endl;
99+
getch();
100+
system("CLS");
101+
}
102+
103+
void seq()
104+
{
105+
int find, r=0;
106+
bool found=false;
107+
cout<<"Input bilangan yang ingin dicari: "; cin>>find;
108+
while(r<b)
109+
{
110+
if(find==a[r])
111+
{
112+
cout<<"Bilangan "<<a[r]<<" ditemukan!"<<endl;
113+
found=true;
114+
break;
115+
}
116+
r++;
117+
}
118+
if(!found)
119+
{
120+
cout<<"Bilangan "<<find<<" tidak ditemukan!"<<endl;
121+
}
122+
cout<<"Press any key to continue..."<<endl<<endl;
123+
getch();
124+
system("CLS");
125+
}
126+
127+
void bin()
128+
{
129+
int find, min=0, max=b, mid, s=b;
130+
bool found=false;
131+
cout<<"Input bilangan yang ingin dicari: "; cin>>find;
132+
while(s!=0)
133+
{
134+
mid=(min+max)/2;
135+
if(find==a[mid])
136+
{
137+
cout<<"Bilangan "<<a[mid]<<" ditemukan!"<<endl;
138+
found=true;
139+
break;
140+
}
141+
else if(find<a[mid])
142+
{
143+
max=mid-1;
144+
}
145+
else if(find>a[mid])
146+
{
147+
min=mid+1;
148+
}
149+
s=s/2;
150+
}
151+
if(!found)
152+
{
153+
cout<<"Bilangan "<<find<<" tidak ditemukan!"<<endl;
154+
}
155+
cout<<"Press any key to continue..."<<endl<<endl;
156+
getch();
157+
system("CLS");
158+
}
159+
160+
int menu_utama()
161+
{
162+
int menu;
163+
utama:
164+
cout<<"Menu: "<<endl;
165+
cout<<"(1) Input bilangan"<<endl;
166+
cout<<"(2) Bubble sort"<<endl;
167+
cout<<"(3) Selection sort"<<endl;
168+
cout<<"(4) Insertion sort"<<endl;
169+
cout<<"(5) Sequential search"<<endl;
170+
cout<<"(6) Binary search (harus sort dulu)"<<endl;
171+
cout<<"(0) Keluar"<<endl;
172+
173+
A:
174+
while(true)
175+
{
176+
switch((menu=getch()))
177+
{
178+
case 48:
179+
return 0;
180+
181+
case 49:
182+
input();
183+
goto utama;
184+
185+
case 50:
186+
bubble();
187+
goto utama;
188+
189+
case 51:
190+
selection();
191+
goto utama;
192+
193+
case 52:
194+
insertion();
195+
goto utama;
196+
197+
case 53:
198+
seq();
199+
goto utama;
200+
201+
case 54:
202+
bin();
203+
goto utama;
204+
205+
default:
206+
cout<<"Menu yang dimasukkan salah, coba lagi"<<endl;
207+
goto A;
208+
}
209+
}
210+
}
211+
212+
int main()
213+
{
214+
menu_utama();
215+
return 0;
216+
}

Tentier - Fungsi & Prosedur.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
4+
using namespace std;
5+
6+
int a;
7+
int b;
8+
int hasil;
9+
10+
//Function
11+
int tambah (int a, int b)
12+
{
13+
return a + b;
14+
}
15+
16+
//Prosedur
17+
void kurang (int a, int b)
18+
{
19+
hasil = a - b;
20+
cout<<"Hasil pengurangan: "<<hasil;
21+
}
22+
23+
//Main Program
24+
int main()
25+
{
26+
cout<<"Masukkan nilai A: ";
27+
cin>>a;
28+
cout<<"Masukkan nilai B: ";
29+
cin>>b;
30+
cout<<endl;
31+
32+
cout<<"Hasil penjumlahan: "<<tambah(a, b)<<endl;
33+
kurang(a, b);
34+
35+
getch();
36+
}

Tugas 01 - Data Diri.CPP

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
#include <string.h>
4+
5+
using namespace std;
6+
7+
int main()
8+
9+
{
10+
char nama[20];
11+
int nim;
12+
char alamat[30];
13+
char programstudi[20];
14+
int berat_badan;
15+
16+
cout << "Halo!" << endl;
17+
18+
cout << "Masukkan nama Anda: ";
19+
cin.getline(nama, 20);
20+
21+
cout << "Masukkan NIM Anda: ";
22+
cin >> nim;
23+
24+
cout << "Masukkan alamat Anda: ";
25+
cin.getline(alamat, 30);
26+
27+
cout << "Masukkan program studi Anda: ";
28+
cin >> programstudi;
29+
30+
cout << "Masukkan berat badan Anda, jangan bohong!: ";
31+
cin >> berat_badan;
32+
33+
cout << endl;
34+
35+
cout << "Nama lengkap Anda adalah " << nama << endl;
36+
cout << "NIM Anda " << nim << endl;
37+
cout << "Anda berdomisili di " << alamat << endl;
38+
cout << "Program studi Anda " << programstudi << ", masuk setengah terpaksa akibat tuntutan orang tua" << endl;
39+
cout << "Anda tidak ingat berat badan Anda ya? Sayang Sekali" << endl;
40+
41+
getch();
42+
return 0;
43+
}

Tugas 02 - Mesin Kasir Sederhana.CPP

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
#include <string.h>
4+
#include <math.h>
5+
6+
using namespace std;
7+
8+
int main()
9+
10+
{
11+
char namabarang[20];
12+
int harga;
13+
int jumlah;
14+
int total;
15+
int pembayaran;
16+
int kembali;
17+
18+
cout << "Halo!" << endl;
19+
20+
cout << "Masukkan nama barang: ";
21+
cin.getline(namabarang, 20);
22+
23+
cout << "Masukkan harga satuan: ";
24+
cin >> harga;
25+
26+
cout << "Masukkan jumlah barang: ";
27+
cin >> jumlah;
28+
29+
total = harga * jumlah;
30+
31+
cout << "Total harga: " << total;
32+
33+
cout << endl;
34+
35+
cout << "Masukkan jumlah pembayaran: ";
36+
cin >> pembayaran;
37+
38+
kembali = (pembayaran - total);
39+
40+
cout << "Kembali: " << kembali;
41+
42+
getch();
43+
return 0;
44+
}

Tugas 03 - Perbandingan Bilangan.CPP

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
#include <math.h>
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
int a;
10+
int b;
11+
12+
cout << "Masukkan nilai A= ";
13+
cin >> a;
14+
15+
cout << "Masukkan nilai B= ";
16+
cin >> b;
17+
18+
if (a > b)
19+
{
20+
cout << a;
21+
}
22+
23+
if (a < b)
24+
{
25+
cout << b;
26+
}
27+
28+
getch();
29+
return 0;
30+
}

0 commit comments

Comments
 (0)