Management Cluster (Bahasa C++)


Translasi program ke dalam bahasa pemrograman C

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>

#ifndef boolean_H

#define boolean_H

#define true 1

#define false 0

#define boolean unsigned char

#endif

#define nil NULL

#define NamaFile(P) (P)->NamaFile

#define mulai(P) (P)->mulai

#define panjang(P) (P)->panjang

#define next(P) (P)->next

#define first(L) (L).first

#define last(L) (L).last

#define nMaks 2048

//deklarasi tipe bentukan

typedef struct tElmList *address;

typedef struct tElmList{

char NamaFile[25];

int mulai;

int panjang;

address next;

} ElmList;

typedef struct{

address first;

address last;

} List;

typedef struct{

char T[nMaks+1];

int nEff;

int ukuran;

int mFormat;

} TabDisk;

//prototype

void CreateTab(TabDisk *Td);

void CreateList(List *L);

address ALokasi(char nama[25], int size, TabDisk Td);

void TampilanAwal();

void FormatPertama();

void Format(TabDisk *Td, int *M, int *sisaFormat);

void ProgressBar1();

void ProgressBar2();

void Menu();

void CreateFile(List *L, TabDisk *Td, char nama[25], int size, int *mSisa);

void Display(TabDisk Td);

void Dir(List L);

void DeAlokasi(address P);

void Delete(List *L, char del[25], TabDisk *Td);

void Help();

void FormatUlang(TabDisk *Td, List *L, int *mSisa);

void FormatTambah(TabDisk *Td, int *M, int mBaru, int                *sisaFormat);

//main driver

int main(){

//kamus

TabDisk MyDisk;

List MyList;

int i, m, nMenu;

int Konfirmasi;

char NAMA[25], del[25], tanya[25];

int N, sisaFormat, mSisa, mulaibaru;

//algoritma

clrscr();

CreateTab(&MyDisk);

CreateList(&MyList);

TampilanAwal();

awal:

FormatPertama();

gotoxy(2,16);

scanf(“%d”, &m);

if(m <= nMaks && m > 0){

Format(&MyDisk, &m, &sisaFormat);

ProgressBar1();

mSisa = m – MyDisk.nEff;

label:

clrscr();

Menu();

scanf(“%d”, &nMenu);

switch(nMenu){

case 1 : {

create:

clrscr();

printf(“Create File\n\n”);

printf(“Memori sisa yang bisa dipakai                                  %d\n\n”, mSisa);

printf(“Ukuran : “); scanf(“%d”, &N);

if(N <= mSisa){

printf(“Nama : “); scanf(“%s”, NAMA);

CreateFile(&MyList, &MyDisk, NAMA, N,                                            &mSisa);

}

else{

textcolor(4);

cprintf(“\n\nMasukan melebihi memori                               !\a\a”);

for(i=1; i <= 999999999; i++){

}

goto create;

}

break;

}

case 2 : {

clrscr();

printf(“Display\n\n”);

ProgressBar2();

clrscr();

Display(MyDisk);

textcolor(12);

printf(“\n\n\t\t\t\t\t\t\t”);cprintf(” X :                             Memori kosong “);

textcolor(14);

printf(“\n\t\t\t\t\t\t\t”);cprintf(” o :                           Memori terisi “);

break;

}

case 3 : {

clrscr();

printf(“Dir\n\n”);

Dir(MyList);

break;

}

case 4 : {

clrscr();

printf(“Delete\n\n”);

printf(“Masukan nama file : “); scanf(“%s”, del);

Delete(&MyList, del, &MyDisk);

break;

}

case 5 : {

clrscr();

printf(“Management Cluster Format”);

printf(“\n\nSisa Memori sebesar %d\n\n”,                          sisaFormat);

printf(“Apakah ingin memformat ulang                              (ya/tidak) ? “); scanf(“%s”, tanya);

if(strcmp(tanya, “Ya”) == 0 || strcmp(tanya,                    “ya”) == 0){

printf(“Format Ulang semua”);

FormatUlang(&MyDisk, &MyList, &mSisa);

FormatPertama();

gotoxy(2,16);

scanf(“%d”, &m);

if(m <= nMaks && m > 0){

Format(&MyDisk, &m, &sisaFormat);

ProgressBar1();

mSisa = m – MyDisk.nEff;

}

else{

gotoxy(10, 14);

textcolor(4);

cprintf(“\n\nMasukan melebihi memori                               !\a\a”);

for(i=1; i <= 999999999; i++){

}

goto awal;

}

}

else{

printf(“Format memori\n\n”);

printf(“Masukkan jumlah memori yang akan                                 ditambahkan : “);

mulaibaru=MyDisk.nEff+1;

scanf(“%d”, &m);

if(m <= nMaks){

FormatTambah(&MyDisk, &m, mulaibaru,                                    &sisaFormat);

ProgressBar1();

mSisa = mSisa + m;

}

else{

gotoxy(10, 14);

textcolor(4);

cprintf(“\n\nMasukan melebihi memori                                !\a\a”);

for(i=1; i <= 999999999; i++){

}

goto awal;

}

}

break;

}

case 6 : {

printf(“Menu 6”);

Help();

break;

}

case 7 : {

goto end;

}

default :

gotoxy(15, 14);

textcolor(12);

cprintf(“Perintah salah\a\a”);

for(i=1; i <= 999999999; i++){

}

goto label;

}

}

printf(“\n\n\n”);

printf(“\t\tEsc = Escape/Menu Utama – – – Q = Exit”);

Konfirmasi=getch();

if(Konfirmasi == 27){

goto label;

}

else if(Konfirmasi == 81){

goto end;

}

else{

gotoxy(10, 14);

textcolor(4);

cprintf(“\n\nMasukan melebihi memori !\a\a”);

for(i=1; i <= 999999999; i++){

}

goto awal;

}

getch();

end:

return 0;

}

//body of prototype 1

void CreateTab(TabDisk *Td){

/* I.S : Td tidak terdefinsi */

/* F.S : Td terdefinsi nEff=0 */

//kamus

//algoritma

(*Td).nEff=0;

(*Td).ukuran=0;

(*Td).mFormat=0;

}

//body of prototype 2

void CreateList(List *L){

/* I.S : L tidak terdefinisi */

/* F.S : L terdfinisi berisi first(L)=nil */

//kamus

//algoritma

first(*L)=nil;

last(*L)=nil;

}

//body of prototype 6

address Alokasi(char nama[25], int size, int start){

/* mengirirm sebuah alokasi sebesar ElmList */

//kamus

address P;

//algoritma

P=(address)malloc(sizeof(ElmList));

if(P != nil){

strcpy(NamaFile(P),nama);

panjang(P)=size;

mulai(P)=start;

next(P)=nil;

}

return(P);

}

//body of prototype 3

void TampilanAwal(){

/* I.S : Layar kososng */

/* F.S : Tampilan awal muncul di layar */

//kamus

char ProgressBar[]=”Please Wait . . .”;

int i, j;

//algoritma

clrscr();

printf(“\n\n”);

textcolor(12);

printf(“\t\t\t”);cprintf(“M.A.N.A.G.E.M.E.N.T

C.L.U.S.T.E.R”);

gotoxy(1,15);

printf(“\n\n\n”);

printf(“\t\t created By ..\n\n”);

printf(“\t\t Ervamadi Yudhistira\n”);

printf(“\t\t Hidayatullah\n”);

printf(“\t\t Ayuningtyas”);

gotoxy(30,10);

for(i=0; ProgressBar[i] != NULL; i++){

printf(“%c”, ProgressBar[i]);

for(j=0; j <= 99999999; j++){

}

}

gotoxy(30,10);

for(i=0; ProgressBar[i] != NULL; i++){

textcolor(2);

cprintf(“%c”, ProgressBar[i]);

for(j=0; j <= 999999999; j++){

}

}

}

//body of prototype 5

void FormatPertama(){

/*   I.S :                                         */

/*   F.S : Tampilan format pertama muncul di layar */

//kamus

int i, j, panjang;

//algoritma

clrscr();

printf(“Management Cluster Format”);

printf(“\n\nSilahan format memori terlebih dahulu !!\n\n”);

panjang=35;

for(i=1; i <= panjang; i++){

printf(“-“);

}

printf(“\n”);

for(i=1; i <= 3; i++){

printf(“|”);

for(j=1; j <= panjang-2 ; j++){

printf(” “);

}

printf(“|”);

printf(“\n”);

}

for(i=1; i <= panjang; i++){

printf(“-“);

}

gotoxy(2,7);

textcolor(12);

cprintf(”   Total Memori   : %d Byte”, nMaks);

gotoxy(1,13);

printf(“Masukan jumlah memori yang akan diformat .\n\n”);

printf(“——–\n”);

printf(“|      |\n”);

printf(“——–“);

}

//body of prototype

void Format(TabDisk *Td, int *M, int *sisaFormat){

/*I.S:Td terdefinisi sembarang tidak kosong*/

/*F.S:Td berisi karakter ‘F’ sebagai tanda memori diformat*/

//kamus

int i;

//algoritma

(*Td).mFormat = (*Td).mFormat + *M;

for(i=1; i <= (*Td).mFormat; i++){

(*Td).T[i]=70;

}

*sisaFormat = nMaks – (*Td).mFormat;

}

//body of prototype

void ProgressBar1(){

/* I.S : Kondisi layar kosong */

/* F.S : Tampilan Progress Bar 1 muncul di layar */

//kamus

char ProgressBar[]=”||||||||||||||||||||”;

int i, j;

//algoritma

clrscr();

gotoxy(30,14);

printf(“Harap Tunggu . .”);

gotoxy(30,15);

printf(“———————\n”);

gotoxy(30,16);

printf(“|”);

for(i=1; i <= 19; i++){

printf(” “);

}

printf(“|\n”);

gotoxy(30,17);

printf(“———————“);

gotoxy(31,16);

for(i=0; ProgressBar[i] != NULL; i++){

textcolor(14);

cprintf(“%c”, ProgressBar[i]);

for(j=0; j <= 99999999; j++){

}

}

clrscr();

gotoxy(30,15);

textcolor(12);

cprintf(“Proses berhasil\a”);

for(j=0; j <= 999999999; j++){

}

}

//body of prototype

void ProgressBar2(){

/* I.S : Kondisi layar kosong */

/* F.S : Tampilan Progress Bar 2 muncul di layar */

//kamus

int N, i, j, t;

//algoritma

gotoxy(35,21);

printf(“Loading . .”);

N=5;

for(i=1; i<=N; i++){

gotoxy(35,9+i);

for(j=5; j>=i; j–){

printf(“*”);

for(t=1; t < 99999999; t++){

}

}

printf(“\n”);

}

for(i=1; i<=N; i++){

gotoxy(35,14+i);

for(j=1; j<=i; j++){

printf(“*”);

for(t=1; t < 99999999; t++){

}

}

printf(“\n”);

}

for(i=1; i<=N; i++){

gotoxy(39+i,9+i);

for(j=N; j>=i; j–){

printf(“*”);

for(t=1; t < 99999999; t++){

}

}

printf(“\n”);

}

for(i=1; i<=N; i++){

gotoxy(45-i,14+i);

for(j=1; j<=i; j++){

printf(“*”);

for(t=1; t < 999999999; t++){

}

}

printf(“\n”);

}

}

//body of prototype 4

void Menu(){

/* I.S : menu belum tampil dilayar */

/* F.S : tampilan menu tampil di layar */

//kamus

//algoritma

printf(“Management Cluster\n\n”);

textcolor(12);

printf(“\t\t”);

cprintf(“//SELAMAT DATANG//”);

printf(“\n\n”);

printf(“\t\t1. Create\n”);

printf(“\t\t2. Display\n”);

printf(“\t\t3. Dir\n”);

printf(“\t\t4. Delete\n”);

printf(“\t\t5. Format\n”);

printf(“\t\t6. Help\n”);

printf(“\t\t7. Exit\n”);

printf(“\n\n\t\tPilihan Anda”);

printf(“\n\n\t\t——–\n”);

printf(“\t\t|      |\n”);

printf(“\t\t——–“);

gotoxy(20,17);

}

//body of prototype 7

void CreateFile(List *L, TabDisk *Td, char nama[25], int size, int *mSisa){

/* I.S : L dan Td terdefinisi sembarang mungkin kosong */

/* F.S : L dan Td di isi */

//kamus

address akhir;

address Px;

int i, start;

//algoritma

akhir=last(*L);

start = (*Td).nEff+1;

Px=Alokasi(nama, size, start);

(*Td).ukuran = (*Td).ukuran + size;

for(i=start; i <= (*Td).ukuran; i++){

(*Td).T[i]=65;

(*Td).nEff++;

}

*mSisa = (*Td).mFormat – (*Td).nEff;

if(first(*L) == nil){

first(*L)= Px;

last(*L) = Px;

}

else{

next(akhir)= Px;

last(*L)= Px;

}

}

//body of prototype

void Display(TabDisk Td){

/* I.S :Td terdefinisi sembarang tidak kosng */

/* F.S :semua elemen didalam Td dicetak dilayar */

//kamus

int i;

//algoritma

printf(“Display\n\n”);

for(i=1; i <= Td.mFormat; i++){

if(Td.T[i] == ‘F’){

textcolor(12);

cprintf(“X”);

}

else{

textcolor(14);

cprintf(“o”);

}

}

}

//body of prototype

void Dir(List L){

/* I.S :

F.S : */

//kamus

address awal;

int y;

//algoritma

awal=first(L);

gotoxy(1,3);

printf(“NamaFile”);

gotoxy(13,3);

printf(“Mulai”);

gotoxy(25,3);

printf(“Ukuran”);

y=4;

while(awal != nil){

gotoxy(2,y+1); printf(“%s”,NamaFile(awal));

gotoxy(15,y+1); printf(“%d”,mulai(awal));

gotoxy(27,y+1); printf(“%d”,panjang(awal));

printf(“\n”);

awal=next(awal);

y++;

}

}

//body of prototype

void DeAlokasi(address P){

/* I.S : P terdefinisi tidak kosng */

/* F.S : P terhapus */

//kamus

//algoritma

free(P);

}

//body of prototype

void Delete(List *L, char del[25], TabDisk *Td){

/* I.S :

F.S : */

//kamus

address awal;

address pred;

boolean ketemu;

int start, size, i;

//algoritma

awal=first(*L);

pred=nil;

ketemu=false;

while(awal != nil && !ketemu){

if(strcmp(NamaFile(awal), del) == 0){

ketemu=true;

}

else{

pred=awal;

awal=next(awal);

}

}

if(ketemu){

start=mulai(awal);

size=panjang(awal);

for(i=start; i <= start + (size-1); i++){

(*Td).T[i]=70;

}

if(awal == first(*L) && awal == last(*L)){

first(*L)=nil;

last(*L)=nil;

DeAlokasi(awal);

}

else{

if(awal == first(*L)){

first(*L)=next(awal);

DeAlokasi(awal);

}

else{

if(awal == last(*L)){

last(*L)=pred;

DeAlokasi(awal);

}

else{

next(pred)=next(awal);

DeAlokasi(awal);

}

}

}

}

else{

printf(“File tidak ditemukan .”);

}

}

//body of prototype

void Help(){

/* I.S : */

/* F.S :  */

//kamus

//algoritma

clrscr();

printf(“Management Cluster Help\n\a”);

printf(“\n\n”);

printf(“Menu Utama\n”);

printf(“\t Pilih menu dengan memasukan nomor yang

tertera di samping menu kemudian tekan

Enter.\n\n”);

printf(“Keterangan-Menu\n”);

printf(“\t 1. Create      – Membuat file baru\n”);

printf(“\t 2. Display          – Menampilkan isi file\n”);

printf(“\t 3. Dir               – Menampilkan

informasi file (nama dan ukuran)\n”);

printf(“\t 4. Delete       – Menghapus file\n”);

printf(“\t 5. Format       – Format memori\n”);

printf(“\t 6. Help        – Bantuan\n”);

printf(“\t 7. Exit        – Keluar program\n”);

}

//body of prototype

void FormatUlang(TabDisk *Td, List *L, int *mSisa){

/* I.S : */

/* F.S : */

//kamus

address awal, pred;

//algoritma

(*Td).nEff=0;

(*Td).ukuran=0;

(*Td).mFormat=0;

*mSisa=(*Td).mFormat;

awal=first(*L);

while(awal != nil){

pred=awal;

first(*L)=next(pred);

awal=first(*L);

DeAlokasi(pred);

}

}

//body of prototype

void FormatTambah(TabDisk *Td, int *M, int mBaru, int

*sisaFormat){

/* I.S : Td terdefinisi sembarang tidak kosong */

/* F.S : Td berisi karakter ‘F’ sebagai tanda memori diformat */

//kamus

int i;

//algoritma

(*Td).mFormat = (*Td).mFormat + *M;

for(i=mBaru; i <= (*Td).mFormat; i++){

(*Td).T[i]=70;

}

*sisaFormat = nMaks – (*Td).mFormat;

}

 

“Ingin meningkatkan traffic pengunjung dan popularity web anda secara cepat dan tak terbatas…?…

Serahkan pada saya…, Saya akan melakukannya untuk anda GRATISSSS…!..Klik disini-1 dan disini-2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: