Anda di halaman 1dari 5

#include <iostream.

h>
#include <stdio.h>
#include <conio.h>
typedef struct TNode
{
int nim;
char nama[20];
int nilai;
TNode *next;
}TNode;
TNode *head;
void awal()
{
head=NULL;
}
int kosong()
{
if(head==NULL)
return 1;
else
return 0;
}
void
void
void
void
void
void
void
void
void
void
void
void

layar_isi();
tambah_depan();
tambah_akhir();
tambah_tengah();
hapus_depan();
hapus_akhir();
hapus_tengah();
cari_data();
cari_edit();
baca_maju();
baca_mundur();
judul_lap();

void main()
{
int pil;
do
{
clrscr();
gotoxy(5,2);cout<<"Menu Utama";
gotoxy(5,3);cout<<"----------";
gotoxy(5,5);cout<<"1. Tambah Data di Depan";
gotoxy(5,6);cout<<"2. Tambah Data di Akhir";
gotoxy(5,7);cout<<"3. Tambah Data di Tengah";
gotoxy(5,8);cout<<"4. Hapus Data di Depan";
gotoxy(5,9);cout<<"5. Hapus Data di Akhir";
gotoxy(5,10);cout<<"6. Hapus Data di Tengah";
gotoxy(5,11);cout<<"7. Cari Data";
gotoxy(5,12);cout<<"8. Cari dan Edit Data";
gotoxy(5,13);cout<<"9. Baca Data Maju";
gotoxy(5,14);cout<<"10. Baca Data Mundur";
gotoxy(5,15);cout<<"11. Keluar";

gotoxy(5,17);cout<<"Pilihan anda : ";cin>>pil;


switch (pil)
{
case 1: tambah_depan();break;
case 2: tambah_akhir();break;
case 3: tambah_tengah();break;
case 4: hapus_depan();break;
case 5: hapus_akhir();break;
case 6: hapus_tengah();break;
case 7: cari_data();break;
case 8: cari_edit();break;
case 9: baca_maju();break;
case 10: baca_mundur();break;
}
}while(pil!=11);
}
void layar_isi()
{
gotoxy(40,2);cout<<"Data Mahasiswa";
gotoxy(40,3);cout<<"--------------";
gotoxy(40,5);cout<<"1. NIM : ";
gotoxy(40,6);cout<<"2. Nama : ";
gotoxy(40,7);cout<<"3. Nilai : ";
}
void tambah_depan()
{
layar_isi();
TNode *baru;
baru=new TNode;
gotoxy(52,5);cin>>baru->nim;
gotoxy(52,6);cin>>baru->nama;
gotoxy(52,7);cin>>baru->nilai;
baru->next=NULL;
if(kosong()==1)
{
head=baru;
head->next=NULL;
}
else
{
baru->next=head;
head=baru;
}
}
void tambah_akhir()
{
layar_isi();
TNode *baru, *bantu;
baru=new TNode;
gotoxy(52,5);cin>>baru->nim;
gotoxy(52,6);cin>>baru->nama;
gotoxy(52,7);cin>>baru->nilai;
baru->next=NULL;
if(kosong()==1)
{
head=baru;

head->next=NULL;
}
else
{
bantu=head;
while(bantu->next!=NULL)
{
bantu=bantu->next;
}
bantu->next=baru;
}
}
void tambah_tengah()
{
}
void hapus_depan()
{
TNode *hapus;
if(kosong()==1)
{
gotoxy(40,5);cout<<("Data Belum Diisi..");
}
else
{
hapus=head;
head=head->next;
delete hapus;
gotoxy(40,5);cout<<("Data Sudah Terhapus..");
}
}
void hapus_akhir()
{
TNode *hapus, *bantu;
char ket[25];
if(kosong()==1)
{
strcpy(ket,"Data Belum Diisi..");
}
else
{
hapus=head;
while(hapus->next!=NULL)
{
hapus=hapus->next;
}
bantu=head;
while(bantu->next!=hapus)
{
bantu=bantu->next;
}
delete hapus;
strcpy(ket,"Data Sudah Terhapus..");
}
gotoxy(40,5);cout<<ket;
}

void hapus_tengah()
{
}
void cari_data()
{
}
void cari_edit()
{
}
void judul_lap()
{
gotoxy(30,10);cout<<"Daftar Mahasiswa";
gotoxy(30,11);cout<<"---------------------------------------------------";
gotoxy(30,12);cout<<"No. NIM
Nama
Nilai
Ket";
gotoxy(30,13);cout<<"---------------------------------------------------";
}
void baca_maju()
{
TNode *bantu;
int brs=1, i=1;
char ket[10];
judul_lap();
bantu=head;
while(bantu!=NULL)
{
gotoxy(30,13+brs);cout<<i;
gotoxy(35,13+brs);cout<<bantu->nim;
gotoxy(44,13+brs);cout<<bantu->nama;
gotoxy(63,13+brs);cout<<bantu->nilai;
if(bantu->nilai>=70)
strcpy(ket,"Lulus");
else
strcpy(ket,"Gagal");
gotoxy(73,13+brs);cout<<ket;
brs++;i++;
bantu=bantu->next;
}
gotoxy(30,13+brs);cout<<"-----------------------------------------------";
gotoxy(30,14+brs);cout<<"Data Habis... Tekan ENTER";
getch();
}
void baca_mundur()
{
TNode *bantu, *bantu1;
int brs=1, i=1;
char ket[10];
judul_lap();

bantu=head;
while(bantu->next!=NULL)
{
bantu=bantu->next;
}
do
{
bantu1=head;
while(bantu1->next!=bantu)
bantu1=bantu1->next;
gotoxy(30,13+brs);cout<<i;
gotoxy(35,13+brs);cout<<bantu->nim;
gotoxy(44,13+brs);cout<<bantu->nama;
gotoxy(63,13+brs);cout<<bantu->nilai;
if(bantu->nilai>=70)
strcpy(ket,"Lulus");
else
strcpy(ket,"Gagal");
gotoxy(73,13+brs);cout<<ket;
brs++;i++;
bantu->next=bantu1;
bantu=bantu1;
}while(bantu->next!=head);
gotoxy(30,13+brs);cout<<"-------------------------------------------------";
gotoxy(30,14+brs);cout<<"Data Habis... Tekan ENTER";
getch();
}