Pemrograman Sistem Unix dan Linux
Soal :
#1
Buatlah/tulis skrip Bash di linux menggunakan perintah {if.. else..} untuk membuat pilihan menu daftar sembako dengan harga, terdapat 2 input, input pertama: nomor sembako, input kedua: jumlah item, hasl output: harga yang harus dibayar.
Buatlah/tulis skrip Bash di linux menggunakan perintah {if.. else..} untuk membuat pilihan menu daftar sembako dengan harga, terdapat 2 input, input pertama: nomor sembako, input kedua: jumlah item, hasl output: harga yang harus dibayar.
#1bin/bash
Clear
echo “Daftar Sembako “;
echo “……………….. “;
echo “1.Beras “;
echo “2.Gula Pasir “;
echo “3.Minyak makan “;
echo “4.Telur “;
echo “5.Sarden “;
echo “6.Exit “;
read –P “Pilihan anda [1-6] : “pil
;
if [$pil –aq 1] ;
then
echo “Banyak
kilo gram ;
read jum
let bayar = jum *10000;
elif [$angka eq-2]
;
them
echo “Banyak
kilo gram ;
read jum
let bayar = jum *5000;
elif [$angka eq-3]
;
them
echo “Banyak
liter ;
read jum
let bayar = jum *7000;
elif [$angka eq-4]
;
them
echo “Banyak
butir ;
read jum
let bayar = jum *10000;
elif [$angka eq-5]
;
them
echo “Banyak
kaleng ;
read jum
let bayar = jum *12000;
elif [$angka eq-6]
;
then
exit 0
else
echo “Maaf
stok Kosong”
exit
fi
echo “ Harga bayar : Rp $bayar”
echo “THX
Hasil
[Putri@linux$].belanja.sh
Daftar Sembako
………………..
1.Beras
2.Gula pasir
3.Telur
5.Sarden
0.exit
Input > Pilihan
anda = 1
Input > Banyak
kilo = 2
Output > Harga
bayr = Rp.20000
#2
Di
pemograman Linux sangat dikenal pustaka/library ncurses, ncurses adalah pustaka
pemrograman yang menyediakan antarmuka pemrograman aplikasi (API) yang memungkinkan
programmer untuk menulis antarmuka pengguna (UI) berbasis teks dengan cara yang
bebas terminal. Ini adalah toolkit untuk mengembangkan perangkat lunak aplikasi
"mirip GUI " yang berjalan di bawah emulator terminal . Ini juga
mengoptimalkan perubahan layar, untuk mengurangi latensi yang dialami saat
menggunakan shell remote. Buatlah skrip membuat Jendela/Windows sederhana
dengan fungsi box( ), berikan penjelasan sedikit algoritma-nya.
#2includ <nurses.h>
WINDOWS *create_newwin
(int height, int width, int starty, int startx);
Void destroy_win
(WINDOW *local_win);
Int main(int
argv[])
{ WINDOW *my_win;
Int startx, starty, width, height;
Int ch;
Initcr(); /*Strat
curses mode */
cbreak(); /*Line
buffring disabled, Pass on
*everty thing to me */
Keypad (stdscr,TRUE); /*I need that nifty F1 */
height : 6;
width : 20;
starty : (LINES - height) /4;
/*calculating for a center Palocemet */
startx : (COLS - width /4; /* of the
window */
printw : (“Press
F1 to exit”);
refresh () ;
my_win : create-newwin (height,
width,starty,startx);
while ((ch = getch () ) ! = KEY_F (1))
{ switch
(ch)
{ case
KEY_LEFT :
destroy_win (my_win);
my_win = create_newwin (height,
width,starty,--statx);
break;
case KEY_RIGHT :
destroy_win (my_win);
my_win = create_newwin
(height, width,starty,--statx);
break;
case KEY_UP :
destroy_win (my_win);
my_win = create_newwin
(height, width,starty,--statx);
break;
case KEY_DOWN :
destroy_win (my_win);
my_win = create_newwin
(height, width,starty,--statx);
break;
}
}
edwin (); /*End curses mode */
return 0;
}
WINDOW *create_newwin (int height, int width, int
starty, int startx)
{ WINDOW *local_win;
Local_win = newwin (height, width,
starty,startx);
Box(local_win, 0 , 0); /* 0, 0 gives default characcters
*for
the vertical and horizontal
*lines */
Wrefresh(local_win); /*show the box */
return local_win;
}
Void destroy_win(WINDOW *local_win)
{
/*box
(local_win, ‘ ‘, ‘ ‘); : This won’t produce the desired
*result of erasing the window. It will leave
it’s four corners
*and so an ugly remnant of window.
*/
Wborder
(local_win,‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘,);
/* The parameters taken are
*1.
Win: the window on which to operate
*2.
Is : character to be used for the left side of the window
*3.
Rs : character to be used for the right side of the window
*4.
Ts : character to be used for the top side of the window
*5.
Bs : character to be used for the bottom side of the window
*6.
Tl : character to be used for the top left corner of the window
*7.
Tr : character to be used for the top right corner of the window
*8.
Bl : character to be used for the battom left corner of the window
*9.
Br : character to be used for the battom right corner of the window
*/
Wrefresh(local_win) ;
Delwin(locawin);
Sekian
Semoga bermanfaat
Komentar
Posting Komentar