#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
struct maha
{
char nama[30];
int id;
int pilih;
long jumlah;
char search1[30];
int search2;
}siswa[20];
enum jawab
{
benar, salah
}ketemu;
void Urut(int a, maha siswa[20])
{
int i, j, l;
maha temp;
for (i=0;i<a;i++)
{
for (j=i+1;j<a;j++)
{
for (l=0;l<30;l++)
{
if (siswa[i].nama[l] < siswa[j].nama[l])
{
break;
}
else if (siswa[i].nama[l] > siswa[j].nama[l])
{
temp=siswa[i];
siswa[i]=siswa[j];
siswa[j]=temp;
break;
}
}
}
}
}
void voting(int a, maha siswa[20])
{
int i;
ketemu=salah;
for (i=0;i<a;i++)
{
if(siswa[i].id==siswa[20].pilih)
{
siswa[i].jumlah++;
printf("\nID-%d terpilih....",siswa[20].pilih);
ketemu=benar;
printf("\n");
}
}
if(ketemu==salah)
{
printf("\nID-%d yang Anda pilih tidak tersedia...\n",siswa[20].pilih);
}
}
void searching(int a, maha siswa[])
{
char plh;
int i, j;
search:
clrscr();
ketemu = salah;
printf("+---+------------------------------+----------+\n");
printf("|No.|Nama |ID |\n");
printf("+---+------------------------------+----------+\n");
for(i=0;i<a;i++)
{
printf("|%-3d|%-30s|%-10d|", i+1, siswa[i].nama, siswa[i].id);
printf("\n");
}
printf("+---+------------------------------+----------+\n\n");
printf("Untuk Melihat Hasil Poling\n");
printf("Searching Berdasarkan : \n");
printf("1. Nama\n");
printf("2. ID\n");
printf("3. Exit\n");
printf("Pilih : ");
scanf("%s",&plh);
if(plh=='1')
{
for(int k=0;k<30;k++)
{
siswa[20].search1[k]=0;
}
gets(siswa[20].search1);
printf("Masukkan Nama : ");
gets(siswa[20].search1);
printf("\nYang Anda Cari : \n");
for(i=0;i<a;i++)
{
for (j=0;j<30;)
{
if (siswa[i].nama[j] == siswa[20].search1[j])
{
if(j==29 && siswa[i].nama[29] == siswa[20].search1[29])
{
printf("+---+------------------------------+----------+-------------|\n");
printf("|No.|Nama |ID |Hasil Voting |\n");
printf("+---+------------------------------+----------+-------------|\n");
printf("|%-3d|%-30s|%-10d|%-13d|", i+1, siswa[i].nama, siswa[i].id, siswa[i].jumlah);
printf("\n");
printf("+---+------------------------------+----------+-------------|\n");
printf("Press any key to continue . . . ");
getch();
ketemu = benar;
break;
}
j++;
}
else if(siswa[i].nama[j] != siswa[20].search1[j])
{
break;
}
}
}
if(ketemu == salah)
{
printf("Tidak Ditemukan\n\n");
printf("Press any key to continue . . . ");
getch();
}
goto search;
}
else if(plh=='2')
{
printf("Masukkan ID : ");
scanf("%d",&siswa[20].search2);
printf("\nYang Anda Cari : \n");
ketemu = salah;
for(i=0;i<a;i++)
{
if(siswa[i].id==siswa[20].search2)
{
printf("+---+------------------------------+----------+-------------|\n");
printf("|No.|Nama |ID |Hasil Voting |\n");
printf("+---+------------------------------+----------+-------------|\n");
printf("|%-3d|%-30s|%-10d|%-13d|", i+1, siswa[i].nama, siswa[i].id, siswa[i].jumlah);
printf("\n");
printf("+---+------------------------------+----------+-------------|\n");
printf("Press any key to continue . . . ");
getch();
ketemu = benar;
break;
}
}
if(ketemu == salah)
{
printf("Tidak Ditemukan\n\n");
printf("Press any key to continue . . . ");
getch();
}
goto search;
}
else if(plh=='3')
{
clrscr();
gotoxy(25,10);
printf("Terima Kasih . . . !!!!!\n");
gotoxy(25,12);
printf("Wasalammu'alaikum, Wr, Wb....");
getch();
DestroyWindow(GetActiveWindow());
exit(0);
}
else
{
printf("Masukkan ANDA Salah!!!!");
getch();
goto search;
}
}
void main()
{
printf("\n\n ===============================================\n");
printf(" || MID PRAKTEK ALOGARITMA DAN PEMEROGRAMAN ||\n");
printf(" || PROGRAM VOTING ||\n");
printf(" ===============================================\n\n");
printf(" +---+---------------+---------------------------+\n");
printf(" |No.| NIM | Nama |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" | 1.| 09091001002 | Aulia Rahman Thoharsin |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" | 2.| 09091001006 | Lalitya Ivana |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" | 3.| 09091001014 | Very Chandra |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" | 4.| 09091001016 | Hardi Raharjo |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" | 5.| 09091001054 | Nyimas Amrina Rosyada |\n");
printf(" +---+---------------+---------------------------+\n");
printf(" Press any key to continue . . . ");
getch();
clrscr();
int x, i, y;
char input[10], id[10], r;
y=13;
printf("\n ===============================================\n");
printf(" || PROGRAM VOTING ||\n");
printf(" ===============================================\n\n");
printf("Masukkan Jumlah Peserta : ");
gets(input);
x=atoi(input);
printf("\n\n");
printf("Masukkan : \n");
printf("+---+------------------------------+----------+\n");
printf("|No.|Nama |ID |\n");
printf("+---+------------------------------+----------+\n");
for(i=0;i<x;i++)
{
gotoxy(0,y);
printf("|%-3d| | |\n",i+1);
printf("+---+------------------------------+----------+\n");
gotoxy(7,y);
gets(siswa[i].nama);
gotoxy(38,y);
gets(id);
siswa[i].id=atoi(id);
y++;
}
Urut(x, siswa);
getch();
urut:
printf("\n\nSetelah diurutkan berdasarkan nama : \n");
printf("+---+------------------------------+----------+\n");
printf("|No.|Nama |ID |\n");
printf("+---+------------------------------+----------+\n");
for(i=0;i<x;i++)
{
printf("|%-3d|%-30s|%-10d|", i+1, siswa[i].nama, siswa[i].id);
printf("\n");
}
printf("+---+------------------------------+----------+\n\n");
milih:
printf("Masukkan ID yang Anda dipilih: ");
scanf("%d",&siswa[20].pilih);
voting(x, siswa);
yakin:
printf("\n");
printf("Apakah Anda masih ingin memilih [y/n] : ");
scanf("%s",&r);
printf("\n");
if(r=='y' || r=='Y')
{
clrscr;
goto urut;
}
else if(r=='n' || r=='N')
{
searching(x, siswa);
}
else
{
printf("Masukkan Salah, jawab [y/n] . . . \n");
goto yakin;
}
}
Tidak ada komentar:
Posting Komentar