Pada dasarnya cara kerja di program ini Menggunakan fitur fitur :
#include <iostream> → pemakaian cout, cin, switch, dll.#include <stdio.h> → pemakaian FILE, scanf, dll.#include <windows.h> → pemakaian system("cls"), dll.#include <string.h> → pemakaian operasi string.#include <conio.h> → pemakaian goto, getch(), dll.prototypefungsi (return dan non return)
Cara Kerja Program :
- input tanggal lahir (Misal 20)
- input bulan lahir (Misal Juni)
- pada fungsi "int zodiak" Fungsi akan memilih jenis zodiak (jenis saya definisikan dengan numerik 1-12)
1 2 3 | else if ((tglLahir>=21&&tglLahir<=31)&&(blnLahir=="MEI")||(tglLahir>=1&&tglLahir<=21)&&(blnLahir=="JUNI")){ jenis=9; } |
- pada fungsi "void status" Fungsi akan mengubah jenis zodiak yang masih berupa numerik akan di ubah menjadi tipe string masuk ke variabel dari fungsi "struct zodiak".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | #include <iostream> #include <stdio.h> #include <windows.h> #include <string.h> #include <conio.h> using namespace std; //Made By CoolWolf //prototype int zodiak(int tglLahir, string blnLahir); void status(int jenis); struct zodiak{ string status; int tglLahir; char blnLahir[20]; }anda; int main(){ int jenis;string dot="."; char fileSifat[100], sifat[6000]; //pembacaan file sifat dan penampung nya char opsi; //option exit char statusZodiak[100]; char txt[]=".txt";//supporting buat format file FILE *readz; //Loading part (Hiasan :D ) cout<<"Loading"; for (int i=0;i<=2;){ for (int j=0;dot[j]!='\0';j++){ Sleep(1000); cout<<dot[j]; } i++; } system("cls"); //input cout<<"Masukkan tanggal lahir anda : ";cin>>anda.tglLahir; cout<<"Masukkan bulan lahir anda : ";cin>>anda.blnLahir; strupr(anda.blnLahir);//kapitalkan bulan supaya menghindari kesalahan upcase jenis=zodiak(anda.tglLahir, anda.blnLahir);//mengambil data dari fungsi zodiak system("cls"); status(jenis);//menggunakan fungsi untuk mengidentifikasikan jenis zodiak berdasarkan tanggal dan bulan lahir strcpy(statusZodiak, anda.status.c_str());//merubah tipe data status zodiak dari std::string ke char cout<<"Zodiak Anda :"<<statusZodiak<<endl;//menampilkan zodiak pengguna saat ini strcpy(fileSifat, statusZodiak); strcat(fileSifat, txt);//digunakan agar ketika membaca file langsung berdasarkan tipe zodiaknya getch(); //batas & handle //reading from files readz = fopen(fileSifat,"r"); if(readz != NULL) { while(fscanf(readz,"%[^#]\n",&sifat)!=EOF) printf("Sifat Zodiak anda :\n\n%s\n",sifat); fclose(readz); } else { cout<<"Error : File Missing !";//skenario buruk : File tidak ada. } getch(); keluar :// Jalan keluar program cout<<"Ingin Mencoba Lagi ? : (y/n)";cin>>opsi; if (opsi=='Y'||opsi=='y') return main(); else if (opsi=='N'||opsi=='n'){ system("cls"); cout<<"Terima Kasih !"<<endl; getch(); system("exit"); } else{ cout<<"Error : Kode yang anda masukkan salah !"; goto keluar; } return 0; } //fungsi untuk menentukan jenis (int) int zodiak(int tglLahir, string blnLahir){ int jenis; if ((tglLahir>=22&&tglLahir<=31)&&(blnLahir=="DESEMBER")||(tglLahir>=1&&tglLahir<=20)&&(blnLahir=="JANUARI")){ jenis=1; } else if ((tglLahir>=21&&tglLahir<=31)&&(blnLahir=="JANUARI")||(tglLahir>=1&&tglLahir<=19)&&(blnLahir=="FEBRUARI")){ jenis=2; } else if ((tglLahir>=20&&tglLahir<=28)&&(blnLahir=="FEBRUARI")||(tglLahir>=1&&tglLahir<=20)&&(blnLahir=="MARET")){ jenis=3; } else if((tglLahir>=21&&tglLahir<=31)&&(blnLahir=="MARET")||(tglLahir>=1&&tglLahir<=19)&&(blnLahir=="APRIL")){ jenis=4; } else if((tglLahir>=21&&tglLahir<=30)&&(blnLahir=="APRIL")||(tglLahir>=1&&tglLahir<=20)&&(blnLahir=="MEI")){ jenis=5; } else if ((tglLahir>=22&&tglLahir<=30)&&(blnLahir=="JUNI")||(tglLahir>=1&&tglLahir<=22)&&(blnLahir=="JULI")){ jenis=6; } else if ((tglLahir>=23&&tglLahir<=31)&&(blnLahir=="JULI")||(tglLahir>=1&&tglLahir<=23)&&(blnLahir=="AGUSTUS")){ jenis=7; } else if ((tglLahir>=24&&tglLahir<=31)&&(blnLahir=="OKTOBER")||(tglLahir>=1&&tglLahir<=22)&&(blnLahir=="NOVEMBER")){ jenis=8; } else if ((tglLahir>=21&&tglLahir<=31)&&(blnLahir=="MEI")||(tglLahir>=1&&tglLahir<=21)&&(blnLahir=="JUNI")){ jenis=9; } else if ((tglLahir>=24&&tglLahir<=31)&&(blnLahir=="AGUSTUS")||(tglLahir>=1&&tglLahir<=22)&&(blnLahir=="SEPTEMBER")){ jenis=10; } else if ((tglLahir>=23&&tglLahir<=30)&&(blnLahir=="SEMPEMBER")||(tglLahir>=1&&tglLahir<=23)&&(blnLahir=="OKTOBER")){ jenis=11; } else if ((tglLahir>=23&&tglLahir<=30)&&(blnLahir=="NOVEMBER")||(tglLahir>=1&&tglLahir<=21)&&(blnLahir=="DESEMBER")){ jenis=12; } else { jenis = 0; } return jenis; } //fungsi mengubah jenis zodiak yang masih berupa integer menajadi string. void status(int jenis){ switch(jenis){ case 1 : anda.status= "Capricorn-Kambing Jantan"; break; case 2 : anda.status= "Aquarius-Pembawa air"; break; case 3 : anda.status= "Pisces-Ikan"; break; case 4 : anda.status= "Aries-Domba Jantan"; break; case 5 : anda.status= "Taurus-Banteng"; break; case 6 : anda.status= "Cancer-Kepiting"; break; case 7 : anda.status= "Leo-Singa"; break; case 8 : anda.status= "Scorpio-Kalajengking"; break; case 9 : anda.status= "Gemini-Si Kembar"; break; case 10 : anda.status= "Virgo-Gadis"; break; case 11 : anda.status= "Libra-Timbangan"; break; case 12 : anda.status= "Sagitarius-Pemanah"; break; default : anda.status="Error ! : Zodiak Tidak Diketahui !"; } } |






0 komentar:
Posting Komentar