Advertisement
GianAkbar20

Untitled

Dec 13th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. // variable global bosku
  8. // untuk laptop :
  9. string laptop[] = {"Acepp ", "Leknovo ", "Msg "};
  10. int hargaLaptop[] = {700, 850, 980};
  11.  
  12. // untuk kipas:
  13. string kipas[] = {"Politeron", "Cosmas ", "Mayuko "};
  14. int hargaKipas[] = {500, 800, 890};
  15.  
  16. //untuk televisi
  17. string televisi[] = {"Philis ", "Shorp ", "Sany "};
  18. int hargaTelevisi[] = {900, 850, 600};
  19.  
  20. //untuk fungsi
  21. string cartBarang[100];
  22. int cartHarga[100];
  23.  
  24. int kode,jumlah;
  25. int indeks = -1, indek = -1 , indek2 = -1;
  26. int jumlahBeli;
  27.  
  28. //pembayaran
  29. int bayar, total,hasil,hasil2;
  30.  
  31.  
  32. // data pembeli
  33. string namaPembeli;
  34. string nomerTelfon;
  35. string alamatPembeli;
  36. int kodePos;
  37. string kota;
  38.  
  39. // struk
  40. int maks[100],totalBarang;
  41.  
  42. // Function bray!
  43. time_t ambilWaktu;
  44. void ateam();
  45. void daftarLaptop(string laptop[], int hargaLaptop[]);
  46. void cartLaptop();
  47. void daftarKipas(string kipas[], int hargaKipas[]);
  48. void cartKipas();
  49. void daftarTelevisi(string televisi[], int hargaTelevisi[]);
  50. void cartTelevisi();
  51. void keranjang(int maks, string cartBarang[], int cartHarga[]);
  52. void pembayaran();
  53. void hapusDuplikat(string arr[]);
  54. void hapusDuplikat3(int arr[]);
  55. void hapusDuplikat2(int arr[]);
  56. void sixe(int *p);
  57. void struk();
  58.  
  59. int main(){
  60. system("clear");
  61.  
  62. awal:
  63.  
  64. cout << "Program Penjualan Barang Elektronik" << endl
  65. << endl;
  66. cout << "Silakan Pilih barang yg ingin anda beli" << endl;
  67. cout << "======================"<< endl;
  68. cout << "| No | Jenis Barang |" << endl;
  69. cout << "======================" << endl;
  70. cout << "| 1. | Laptop |" << endl;
  71. cout << "| 2. | Kipas Angin |" << endl;
  72. cout << "| 3. | Televisi |" << endl;
  73. cout << "======================" << endl;
  74.  
  75. char lanjut;
  76. int pilih;
  77. cout << "Input kode barang yg ingin anda beli: ";
  78. cin >> pilih;
  79.  
  80.  
  81. switch (pilih){
  82. case 1:
  83. cartLaptop();
  84. break;
  85. case 2:
  86. cartKipas();
  87. break;
  88. case 3:
  89. cartTelevisi();
  90. break;
  91. default:
  92. cout << "Maaf kode yg anda masukkan salah" << endl;
  93. goto awal;
  94. }
  95. ljnt:
  96. cout << endl;
  97. cout << "Apakah anda ingin membeli barang lagi?: " << endl;
  98. cout << "[Y] untuk membeli barang lagi" << endl;
  99. cout << "[N] untuk melanjutkan ke pembayaran" << endl;
  100. cout << "Silahkan ketik [y/n] ";
  101. cin >> lanjut;
  102. system("clear");
  103. lanjut:
  104. if (lanjut == 'Y' or lanjut == 'y'){
  105. goto awal;
  106. }
  107. else if (lanjut == 'N' or lanjut == 'n'){
  108. keranjang(indeks, cartBarang, cartHarga);
  109. pembayaran();
  110. struk();
  111. }
  112. else{
  113. cout << "Kode salah, Silahkan ulangi kembali" << endl;
  114. goto ljnt;
  115. }
  116.  
  117. ateam();
  118. return 0;
  119. }
  120.  
  121. void ateam(){
  122. cout << "Dibuat dengan "
  123. << "\342\230\272"
  124. << " oleh kelompok 8" << endl;
  125. cout << "Terima Kasih Telah Membeli Barang Di Toko Kami " << endl;
  126. cin.get();
  127. }
  128.  
  129. void daftarLaptop(string laptop[], int hargaLaptop[]){
  130. cout << endl;
  131. cout << "============================================================" << endl;
  132. cout << "Kode\t\tMerk Laptop\t\tHarga" << endl;
  133. cout << "============================================================" << endl;
  134. for (int i = 0; i < 3; i++){
  135. cout << " " << i << "\t\t" << laptop[i] << "\t\t"
  136. << "Rp. " << hargaLaptop[i] << ".000\t" << endl;
  137. }
  138. cout << "============================================================" << endl;
  139. cout << endl;
  140. }
  141.  
  142. void cartLaptop(){
  143. char lagi;
  144. do{
  145. daftarLaptop(laptop,hargaLaptop);
  146.  
  147. int kode;
  148.  
  149. input:
  150. cout << "Masukkan jumlah barang yg ingin anda beli: ";
  151. cin >> jumlahBeli;
  152.  
  153. cout << "Input kode barang yg ingin anda beli : ";
  154. cin >> kode;
  155.  
  156. for (int i = 1; i <= jumlahBeli; i++){
  157. if (kode >= 3){
  158. cout << "Kode yg anda masukkan salah" << endl;
  159. goto input;
  160. }
  161. else{
  162. cout << "\nBarang ke - " << i << endl;
  163. cout << "===========================================================================" << endl;
  164. cout << "Nama Barang : " << laptop[kode] << endl;
  165. cout << "Harga Barang : Rp. " << hargaLaptop[kode] << ".000" << endl;
  166. indeks = indeks + 1;
  167. indek = indeks;
  168. indek2 = indeks;
  169. maks[indek2] = jumlahBeli;
  170. cartBarang[indek] = laptop[kode];
  171. cartHarga[indeks] = hargaLaptop[kode];
  172. jumlah = jumlah + hargaLaptop[kode];
  173. cout << "Total harga : "
  174. << "Rp. " << jumlah << ".000" << endl;
  175. cout << "===========================================================================" << endl;
  176. }
  177. cout << endl;
  178. }
  179. }while(lagi == 'Y' || lagi == 'y');
  180.  
  181. }
  182.  
  183. void daftarKipas(string kipas[], int hargaKipas[]){
  184. cout << endl;
  185. cout << "====================================================================================" << endl;
  186. cout << "Kode\t\tMerk Kipas Angin\t\tHarga " << endl;
  187. cout << "====================================================================================" << endl;
  188. for (int i = 0; i < 3; i++)
  189. {
  190. cout << " " << i << "\t\t" << kipas[i] << "\t\t\t"
  191. << "Rp. " << hargaKipas[i] << ".000" << endl;
  192. }
  193. cout << "====================================================================================" << endl;
  194. cout << endl;
  195. }
  196.  
  197. void cartKipas(){
  198. char lagi;
  199. do{
  200. daftarKipas(kipas, hargaKipas);
  201.  
  202.  
  203. int kode;
  204.  
  205. input1 :
  206. cout << "Masukkan jumlah barang yg ingin anda beli: ";
  207. cin >> jumlahBeli;
  208. cout << "Input kode barang yg ingin anda beli : ";
  209. cin >> kode;
  210.  
  211. for (int i = 1; i <= jumlahBeli; i++)
  212. {
  213. if (kode >= 3)
  214. {
  215. cout << "Kode yg anda masukkan salah" << endl;
  216. goto input1;
  217. }
  218. else
  219. {
  220. cout << "\nBarang ke - " << i << endl;
  221. cout << "===========================================================================" << endl;
  222. cout << "Nama Barang : " << kipas[kode] << endl;
  223. cout << "Harga Barang :Rp. " << hargaKipas[kode] << ".000" << endl;
  224. indeks = indeks + 1;
  225. indek = indeks;
  226. indek2 = indeks;
  227. maks[indek2] =jumlahBeli;
  228. cartBarang[indek] = kipas[kode];
  229. cartHarga[indeks] = hargaKipas[kode];
  230. jumlah = jumlah + hargaKipas[kode];
  231. cout << "Total harga : "
  232. << "Rp. " << jumlah << ".000" << endl;
  233. cout << "===========================================================================" << endl;
  234. }
  235. cout << endl;
  236.  
  237. }
  238. }while(lagi == 'Y' || lagi == 'y');
  239.  
  240. }
  241.  
  242. void daftarTelevisi(string televisi[], int hargaTelevisi[]){
  243. cout << endl;
  244. cout << "===========================================================================" << endl;
  245. cout << "Kode\t\tMerk Televisi\t\tHarga " << endl;
  246. cout << "===========================================================================" << endl;
  247. for (int i = 0; i < 3; i++)
  248. {
  249. cout << " " << i << "\t\t" << televisi[i] << "\t\t\t"
  250. << "Rp. " << hargaTelevisi[i] << ".000\t" << endl;
  251. }
  252. cout << "===========================================================================" << endl;
  253. cout << endl;
  254. }
  255.  
  256. void cartTelevisi(){
  257. char lagi;
  258. do{
  259. daftarTelevisi(televisi, hargaTelevisi);
  260.  
  261. int kode;
  262.  
  263. input3:
  264. cout << "Masukkan jumlah barang yg ingin anda beli: ";
  265. cin >> jumlahBeli;
  266.  
  267. cout << "Input kode barang yg ingin anda beli : ";
  268. cin >> kode;
  269.  
  270. for (int i = 1; i <= jumlahBeli;i++){
  271. if (kode >= 3){
  272. cout << "Kode yg anda masukkan salah" << endl;
  273. goto input3;
  274. }
  275. else{
  276. cout << "Barang ke - " << i << endl;
  277. cout << "===========================================================================" << endl;
  278. cout << "Nama Barang : " << televisi[kode] << endl;
  279. cout << "Harga Barang : " << hargaTelevisi[kode] << ".000" << endl;
  280. indeks = indeks + 1;
  281. indek = indeks;
  282. indek2 = indeks;
  283. maks[indek2] = jumlahBeli;
  284. cartBarang[indek] = televisi[kode];
  285. cartHarga[indeks] = hargaTelevisi[kode];
  286. jumlah = jumlah + hargaTelevisi[kode];
  287. cout << "Total harga : "
  288. << "Rp. " << jumlah << ".000" << endl;
  289. cout << "===========================================================================" << endl;
  290. }
  291. cout << endl;
  292. }
  293. }while(lagi == 'Y' || lagi == 'y');
  294.  
  295. }
  296.  
  297. void sixe(int *p)
  298. {
  299. std::cout << "Length of array = " << (sizeof(p)/sizeof(*p)) << std::endl;
  300. }
  301.  
  302. void hapusDuplikat2(int arr[]){
  303. for(int i=0;i<=indeks;i++)
  304. {
  305. for(int j=i+1;j<=indeks;)
  306. {
  307. if(arr[i]==arr[j])
  308. {
  309. for(int k=j;k<=indeks;k++)
  310. {
  311. arr[k]=arr[k+1];
  312.  
  313. }
  314. indeks--;
  315. }
  316. else
  317. j++;
  318. }
  319. }
  320. }
  321. void hapusDuplikat3(int arr[]){
  322. for(int i=0;i<=indek2;i++)
  323. {
  324. for(int j=i+1;j<=indek2;)
  325. {
  326. if(arr[i]==arr[j])
  327. {
  328. for(int k=j;k<=indek2;k++)
  329. {
  330. arr[k]=arr[k+1];
  331.  
  332. }
  333. indek2--;
  334. }
  335. else
  336. j++;
  337. }
  338. }
  339. }
  340. void hapusDuplikat(string arr[]){
  341. for(int i=0;i<=indek;i++)
  342. {
  343. for(int j=i+1;j<=indek;)
  344. {
  345. if(arr[i]==arr[j])
  346. {
  347. for(int k=j;k<=indek;k++)
  348. {
  349. arr[k]=arr[k+1];
  350.  
  351. }
  352. indek--;
  353. }
  354. else
  355. j++;
  356. }
  357. }
  358. }
  359. void keranjang(int maks, string cartBarang[], int cartHarga[]){
  360. time(&ambilWaktu);
  361.  
  362. cout << endl;
  363. cout << "===========================================================================" << endl;
  364. cout << "Daftar Barang yg anda beli: " << endl;
  365. for (int i = 0; i <= maks; i++){
  366. cout << "\t\t" << i + 1 << ". " << cartBarang[i] << "\t\t\tRp. " << cartHarga[i] << ".000" << endl;
  367. }
  368. cout << "===========================================================================" << endl;
  369. cout << "\t\tTransaksi di lakukan pada: " << ctime(&ambilWaktu) << endl;
  370. cout << "\t\tTotal harga barang yg anda beli adalah: "
  371. << "Rp. " << jumlah << ".000" << endl;
  372. }
  373. void pembayaran(){
  374.  
  375. cout << endl << endl;
  376. cout << "\tSilakan mengisi form data terlebih dahulu" << endl;
  377. cout << "===========================================================================" << endl;
  378. cout << "Nama lengkap \t\t: ";
  379. cin.ignore(1);
  380. getline(cin, namaPembeli);
  381. cout << "\nNomer telfon \t\t: ";
  382. cin >> nomerTelfon;
  383. cout << "\nAlamat \t\t: ";
  384. cin.ignore(1);
  385. getline(cin, alamatPembeli);
  386. cout << "\nKota \t: ";
  387. getline(cin, kota);
  388. cout << "\nKode Pos \t: ";
  389. cin >> kodePos;
  390. cout << "===========================================================================" << endl;
  391. cout << endl;
  392. cout << "Silakan melakukan pembayaran atas barang yg anda beli" << endl;
  393. cout << "===========================================================================" << endl;
  394. cout << "Masukkan nominal uang yang ingin anda bayarkan: Rp. ";
  395. cin >> bayar;
  396. total = bayar - jumlah;
  397. }
  398. void struk(){
  399. system("clear");
  400. hapusDuplikat(cartBarang);
  401. hapusDuplikat3(maks);
  402. hapusDuplikat2(cartHarga);
  403. cout << endl;
  404. cout << "\t\t\tStruk Pembelian Barang" << endl;
  405. cout << endl;
  406. cout << "\t\t\tPt Enginio Client" << endl;
  407. cout << "\t\t\tJl Soekarno-Hatta 54 Jakarta" << endl;
  408. cout << "\t\t\t(021) 90903234" << endl;
  409. cout << "\t\t\t---------------------------------------------------" << endl;
  410. cout << "\t\t\t| No | Nama Barang | Harga Barang | Jumlah Barang|" << endl;
  411. cout << "\t\t\t---------------------------------------------------" << endl;
  412. for(int i = 0; i <= 2; i++)
  413. cout << "\t\t\t|" << setw(2) << i+1 << setw(4) << " | " << cartBarang[i] << " |" << setw(5) << "Rp. " << cartHarga[i] << ".000 |" << setw(3) << maks[i] << " |" << endl;
  414. cout << "\t\t\t---------------------------------------------------" << endl;
  415. cout << "\t\t\tNama Pembeli : " << namaPembeli << endl;
  416. cout << "\t\t\tNomer Telfon : " << nomerTelfon << endl;
  417. cout << "\t\t\tAlamat : " << alamatPembeli << endl;
  418. cout << "\t\t\tKota : " << kota << endl;
  419. cout << "\t\t\tKode Pos : " << kodePos << endl;
  420. for (int i = 0; i <= 2; ++i)
  421. {
  422. totalBarang += maks[i];
  423. }
  424. cout << "\t\t\tTotal Barang : " << totalBarang << endl;
  425. cout << "\t\t\tTotal Harga : Rp. " << jumlah << ".000" << endl;
  426. cout << "\t\t\tKembalian : Rp. " << total << ".000" << endl;
  427. cout << endl;
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement