Saturday, December 24, 2022

Algoritma dan Struktur Data Pertemuan 12

 

Assalamualaikum wr.wb                                                                                                                   

Nama: Muhamad Syarif Ramadhan

Nim  : 3420227001
Prodi: Teknik Informatika


Contoh 1

                                                Lampiran Contoh 1 sofware Borland C++






#include "stdio.h"     //Nama : Muhamad Syarif Raadhan

#include <iostream.h>  //NIM  : 3420227001

#include "conio.h"



void garis (int a)

{

int i;

printf("\n");

for (i=1;i<=a;i++) { printf("="); }

printf("\n");

}


void main()

{

struct data

   {

char nama [15];

char nim [15];

int nilai;

   };

data mahasiswa;

cout<<"Masukan Nama   : "; cin>>mahasiswa.nama;

   cout<<"NIM            : "; cin>>mahasiswa.nim;

cout<<"Nilai Total    : "; cin>>mahasiswa.nilai;

   garis (20);

cout<<"Data Mahasiswa "<<endl;

cout<<"Nama Mahasiswa : "<<mahasiswa.nama<<endl;

   cout<<"NIM            : "<<mahasiswa.nim<<endl;

cout<<"Nilai Total    : "<<mahasiswa.nilai<<endl;

   getch();

}

Contoh 2

                                                Lampiran Contoh 2 sofware Borland C++





#include "conio.h"        //Nama : Muhamad Syarif Ramadhan
#include <stdio.h>        //NIM  : 3420227001
#include "iostream.h"
#include <iomanip.h>

#define cetak cout
#define masuk cin

void garis ()
{
cetak<<"==================================================\n";
}

void judul ()
{
garis ();
cetak<<"\tPenggunaan Struktur Dengan Array\n";
garis();
}

char hasil (int nilai);

void main()
{
/*
Sebuah struct adalah sekelompok elemen data yang dikelompokkan bersama
di bawah satu nama. Unsur-unsur data, yang dikenal sebagai anggota,
dapat memiliki berbagai jenis tipe data dan panjang yang berbeda.
*/

   judul();
   struct {
char nim[10];
      char nama [25];
char ket [20];
int nilai;
} mhs [5];
int i, jml;
cetak<<"Masukan Jumlah Data: ";masuk>>jml;
for (i=1;i<=jml;i++) {
cout<<"Data Ke - "<<i<<endl;
cout<<"Masukan NIM : "; cin>>mhs[i].nim;
    cout<<"Masukan Nama : "; cin>>mhs[i].nama;
    cout<<"Masukan Nilai : "; cin>>mhs[i].nilai;
    cetak<<endl;
if (mhs[i].nilai >= 70)
    {strcpy (mhs[i].ket, "Lulus");}
    else
    {strcpy (mhs[i].ket, "Gagal");}
}
clrscr();
judul ();
cout<<"No  Nama      NIM          Nilai     Keterangan"<<endl;
garis();
for (i=1;i<=jml;i++) {
cetak<<setw (4) <<setiosflags (ios::left)<<i;
cetak<<setw (10) <<mhs[i].nama;
cetak<<setw (13) <<mhs[i].nim;
cetak<<setw (10) <<mhs[i].nilai;
cetak<<mhs[i].ket;
cetak<<endl;
}
garis ();
getch();
}

Contoh 3

                                                Lampiran Contoh 3 sofware Borland C++






#include <stdio.h>      //Nama : Muhamad Syarif Ramadhan
#include "iostream.h"   //Nim  : 3420227001
#include <conio.h>
#include "iomanip.h"

#define cetak cout
#define masuk cin
#define enter endl


void garis () {
cetak<<"================================================\n";
}

void judul () {
cetak<<"\t\tPENITIPAN HEWAN PELIHARAAN"<<enter;
cetak<<"\t\t"; putchar (34); cetak<<"MEAOW PET CARE";putchar (44); cetak<<enter;
   garis ();
}

float tobay (float total, float subtotal);

void main() {
char nm_pet [20];
char nm_pem [20];
int i,jml;

awal:
clrscr();
judul ();
cout<<"Nama Petugas : "; cin>>nm_pet;
   cout<<"Nama Pemilik : "; cin>>nm_pem;
cout<<"Jumlah Hewan : "; cin>>jml;
clrscr();
judul();
puts("Data Ke - ");
puts ("Kode Jenis Hewan [K/H] : ");
puts ("Kode Perawatan [1/2]   : ");
   puts ("Jumlah Hewan           : ");

struct {
char kd_hewan;
char kd_rawat;
int jml_hewan;
} masukan [5];

char jenis [5][10], rawat [5][10];
float harga [5], subtotal[5];
   float total=0;

   for (i=1;i<=jml;i++) {
gotoxy (27,5); clreol();
      gotoxy (27,6); clreol();
      gotoxy (27,7); clreol();
gotoxy (11,4); cout<<i;
gotoxy (27,5); cin>>masukan[i].kd_hewan;
      gotoxy (27,6); cin>>masukan[i].kd_rawat;
gotoxy (27,7); cin>>masukan[i].jml_hewan;

if (masukan[i].kd_hewan == 'K' || masukan[i].kd_hewan == 'k') {
      strcpy (jenis[i], "Kucing");
if (masukan[i].kd_rawat == '1') {
harga[i]=250000;
strcpy(rawat[i], "Lux");
} else {
harga [i]=300000;
strcpy(rawat[i], "Intensive");
         }
} else {
strcpy(jenis[i], "Hamster");
if (masukan[i].kd_rawat == '1') {
          harga [i]=150000;
strcpy(rawat[i],"Lux");
         } else {
harga [i]=100000;
strcpy(rawat[i],"Intensive");
         }
      }

//Hitung Subtotal
      subtotal[i] = masukan[i].jml_hewan * harga[i];

    //Hitung Total
total = tobay(total, subtotal[i]);

   }

clrscr();
judul ();
printf("Nama Petugas: %s\n", nm_pet);
   printf("Nama Pemilik: %s\n", nm_pem);
garis ();
cout<<"No  Jenis    Jenis       Biaya      Jumlah  Subtotal"<<endl;
cout<<"    Hewan    Perawatan   Perawatan  Hewan"<<endl;
garis ();
for (i=1;i<=jml;i++) {
cout<<setw(4) <<setiosflags (ios::left)<<i;
cout<<setw(9) <<jenis [i];
cout<<setw(12) <<rawat [i];
cout<<setw(11) <<harga [i];
cout<<setw(8) <<masukan[i].jml_hewan;
      cout<<setprecision (10) <<subtotal[i];
cout<<endl;
   }

garis ();
float ubay, ukem;
cout<<"\t\t\tTotal Bayar  : "<<setprecision (10) <<total<<endl;
   cout<<"\t\t\tUang Bayar   : "; cin>>ubay;
ukem = ubay - total;
cout<<"\t\t\tUang Kembali : "<<setprecision (10) <<ukem<<endl; goto akhir;

akhir:
char lagi;
cout<<"\t\tINPUT DATA LAGI [Y/N]: ";cin>>lagi;
if (lagi == 'Y' || lagi == 'y') { goto awal; } else { getch(); }
}

float tobay (float total, float subtotal) {
return total + subtotal;
}

Contoh 4

                                                Lampiran Contoh 4 sofware Borland C++

#include <iostream.h>   //Nama : Muahamad Syarif Ramadhan
#include "string.h"     //NIM  : 3420227001
#include <conio.h>


struct film {
char judul [20];
char tahun [4];
} aku, kamu;

void cetakfilm (film siapa);

void main() {
strcpy(aku.judul, "One Piece");
strcpy (aku.tahun, "2000");
cout<<"Judul Film Kamu  : "; cin>>kamu.judul;
   cout<<"Masukan Tahun    : "; cin>>kamu.tahun;
   cout<<"Film favorit aku adalah  : \n";
cetakfilm (aku);
cout<<"Film favorit kamu adalah :\n";
cetakfilm (kamu);
getch();
}
void cetakfilm (film siapa) {
cout<<siapa.judul;
cout<<" ("<<siapa.tahun<<")\n";
}


Terimakasih
Wassalamu'alaikum Wr. Wb.


Algoritma dan Struktur Data Pertemuan 11

Assalamualaikum wr.wb                                                                                                                   

Nama: Muhamad Syarif Ramadhan

Nim  : 3420227001
Prodi: Teknik Informatika


Contoh 1

                                                Lampiran Contoh 1 sofware Borland C++


 

 /* Program Membuat Garis Menggunakan Fungsi */


#include "stdio.h"         //Nama  : Muhamad Syarif Ramadhan

#include "iostream.h"      //NIM   : 3420227001

#include "conio.h"

#include "iomanip.h"


void garis() {

    printf ("\t----------------------------------------------------\n");

}


/* Program Utama */

void main() {

   garis(); //Memanggil Fungsi Garis

   cout << "\t|\t Belajar Algoritma Dan Strutur Data. \t   |" << endl;

   garis(); //Memanggil Fungsi Garis

   int a[5];

   a[0]=9; a[1]=90; a[2]=900; a[3]=9000; a[4]=90000;

   printf ("\t| Nilai A = %d\n", a[0]);

   gotoxy (60,4); cout << "|" << endl;

   printf ("\t| Nilai B = %d\n", a[1]);

   gotoxy (60,5); cout << "|" << endl;

   printf ("\t| Nilai C = %d\n", a[2]);

   gotoxy (60,6); cout << "|" << endl;

   printf ("\t| Nilai D = %d\n", a[3]);

   gotoxy (60,7); cout << "|" << endl;

   printf ("\t| Nilai E = %d\n", a[4]);

   gotoxy (60,8); cout << "|" << endl;

   getch();

}

Contoh 2

                                                Lampiran Contoh 2 sofware Borland C++


/*

***************************************

Penggunaan Prototype Pada Fungsi

***************************************

*/

#include "stdio.h"        //Nama  : Muhamad Syarif Ramadhan

#include <conio.h>        //NIM   : 3420227001

#include "iostream.h"     

#include <iomanip.h>


//Prototype Fungsi

float total(int hrg, int jml);


void garis() {

   cout << "===================================================================================" << endl;

}


void judul() {

   garis();

   cout << "\t\t\t\t SHAFA STORE PROGRAM" << endl;

   garis();

}


void main() {

   char name[20], goods[20];

   int price, jumbel;

   judul();

   cout << " Enter the Buyer's Name : "; cin >> name;

   cout << " Name of Goods          : "; cin >> goods;

   cout << " Price                  : "; cin >> price;

   cout << " Purchase Amount        : "; cin >> jumbel;

   garis();

   cout << " Thankyou " << name << " have shopped at our store." << endl;

   cout << " What you Buy is " << goods << " with price Rp. " << price << endl;

   cout << " The Amount you Buy is " << jumbel << " so Pay is";

   printf (" Rp. %.2f", total(price, jumbel));

   cout << endl;


   getch();

}


float total (int hrg, int jml) {

   return hrg * jml;

}


Contoh 3

                                                Lampiran Contoh 3 sofware Borland C++


/* Contoh Pemanggilan Fungsi By Value */


#include "stdio.h"           //Nama  : Muhamad Syarif Ramadhan

#include "iostream.h"        //NIM   : 3420227001

#include "conio.h"

#include "iomanip.h"


void tambah(int m, int n);

void garis();


void main() {

   int a, b;

   a = 9; b = 2;

   garis();

   cout << "\t||    Nilai Variable sebelum Fungsi digunakan" << endl;

   gotoxy (58,2); cout << "||" << endl;

   cout << "\t||    Nilai A adalah " << a << " Nilai B adalah " << b << endl;

   gotoxy (58,3); cout << "||" << endl;

   garis();

   // Pemanggilan Fungsi Tambah

   tambah (a, b);

   garis();

   cout << "\t||    Nilai Variable setelah Fungsi digunakan" << endl;

   gotoxy (58,8); cout << "||" << endl;

   cout << "\t||    Nilai A adalah " << a << " Nilai B adalah " << b << endl;

   gotoxy (58,9); cout << "||" << endl;


   getch();

}


void tambah(int m, int n){

   m += 3; n += 8;

   cout << "\t||    Nilai di dalam Fungsi Tambah." << endl;

   gotoxy (58,5); cout << "||" << endl;

   cout << "\t||    Nilai M adalah " << m << " Nilai N adalah " << n << endl;

   gotoxy (58,6); cout << "||" << endl;

}


void garis() {

   cout << "\t===================================================\n";

}


Contoh 4

                                                Lampiran Contoh 4 sofware Borland C++
/* Contoh Pemanggilan Fungsi By Reference */

#include "stdio.h"          //Nama  : Muhamad Syarif Ramadhan
#include "iostream.h"       //NIM   : 3420227001
#include "conio.h"
#include "iomanip.h"

void tambah(int *m, int *n);
void garis();

void main() {
   int a, b;
   a = 3; b = 5;
   garis();
   cout << "\t||  Nilai Variable sebelum Fungsi digunakan" << endl;
   gotoxy (70,2); cout << "||" << endl;
   cout << "\t||  Nilai A adalah " << a << " dan Nilai B adalah " << b << endl;
   gotoxy (70,3); cout << "||" << endl;
   garis();
   /*
    Pemanggilan Fungsi Tambah
    Nilai yang masuk ke Fungsi tambah bukan nilai dari Variable a dan b
    tetapi Alamat dari Variable a dan b
   */
   tambah (&a, &b);
   garis();
   cout << "\t||  Nilai Variable setelah Fungsi digunakan" << endl;
   gotoxy (70,8); cout << "||" << endl;
   cout << "\t||  Nilai A adalah " << a << " dan Nilai B adalah " << b << endl;
   gotoxy (70,9); cout << "||" << endl;

   getch();
}

void tambah(int *m, int *n){
   /*
      Nilai yang ada di Alamat m di tambah 5
      Hal ini akan merubah Nilai Variable a karena Variable a ada di alamat m
   */
   *m = *m + 5;
   /*
      Nilai yang ada di Alamat n di tambah 7
      Hal ini akan merubah Nilai Variable b karena Variable b ada di alamat n
   */
   *n += 7;
   cout << "\t||  Nilai di dalam Fungsi Tambah." << endl;
   gotoxy (70,5); cout << "||" << endl;
   cout << "\t||  Nilai M adalah " << m << " dan Nilai N adalah " << n << endl;
   gotoxy (70,6); cout << "||" << endl;
}

void garis() {
   cout << "\t===============================================================\n";
}

Terimakasih
Wassalamu'alaikum Wr. Wb.




Algoritma dan Struktur Data Pertemuan 10

  Assalamualaikum wr.wb                                                                                                                   

Nama: Muhamad Syarif Ramadhan

Nim  : 3420227001
Prodi: Teknik Informatika


Contoh 1

                                                Lampiran Contoh 1 sofware Borland C++

#include <conio.h>         // Nama  : Muhamad Syarif Ramadahan
#include "stdio.h"           // NIM   : 3420227001
#include <iostream.h>
#include "iomanip.h"

//Deklarasi Define
#define A 9
//Tidak perlu diakhiri dengan ; karena bukan pernyataan
#define B 2

void main() {
  int result;


  cout << "\t = = = = = = = = = = = = = = = = =" << endl;
  printf ("\t | Nilai dari A adalah     : %d\n", A);
  printf ("\t | Nilai dari B adalah     : %d\n", B);
  gotoxy (41,2); cout << " |" << endl;
  gotoxy (41,3); cout << " |" << endl;
  cout << "\t = = = = = = = = = = = = = = = = =" << endl;
  result = A * B;
  printf ("\t | Nilai dari A * B adalah : %d\n", result);
  gotoxy (41,5); cout << " |" << endl;
  cout << "\t = = = = = = = = = = = = = = = = =" << endl;

  getch();
}


Contoh 2

                                                                         Lampiran Contoh 2 sofware Borland C++


#include "conio.h"            // Nama  : Muhamad Syarif Ramadhan
#include <iostream.h>      // NIM   : 3420227001
#include "iomanip.h"

#define krwlbk {
#define krwltp }
#define exit cout
#define enter cin
#define hold getch()

void main ()
krwlbk
    int a, i=9;
    int nilai [9];
    exit << "\t|   Contoh Penggunaan #Define   |" << endl;
    cout << "\t= = = = = = = = = = = = = = = = =" << endl;
    for (a=0;a<i;a++)
    krwlbk
    exit << "\t| Masukan Nilai ke " << a << " -> "; enter >> nilai[a];
    gotoxy (41,3+a); exit << "|" << endl;
    krwltp

    cout << "\t= = = = = = = = = = = = = = = = =" << endl;
    exit << "\t|          Hasil Input          |" << endl;
    cout << "\t= = = = = = = = = = = = = = = = =" << endl;
    for (a=0;a<i;a++)
    {
       exit << "\t| Nilai ke " << a << " adalah " << nilai[a] << endl;
       gotoxy (41,15+a); exit << "|" << endl;
    }

   hold;
krwltp

Contoh 3


                                              Lampiran Contoh 3 file 'tampil.h' sofware Borland C++

#define output cout
#define key() main()
#define view printf
#define write puts
#define enter scanf
#define input cin
#define take gets
#define eraser() clrscr()
#define in if
#define except else
#define holdon getche()


                                                               Lampiran Contoh 3  sofware Borland C++





#include "stdio.h"       // Nama  : Muhamad Syarif Ramadhan
#include <iomanip.h>     // NIM   : 3420227001
#include "tampil.h"
#include <conio.h>
#include "iostream.h"

/*
    Dalam penulisan #include ada dua bentuk penulisan :
    #include *nama_file_header" atau #include <nama_file_header>
*/

void key()
start
  int i,n;

  write ("\t ==========================================");
  write ("\t       BINA SARANA INFORMATIKA [BSI]       ");
  write ("\t ==========================================");
  write ("\t\tData Jurusan                             ");
  write ("\t  A => Teknologi Informasi      (S1)       ");
  write ("\t  B => Rekayasa Perangkat Lunak (S1)       ");
  write ("\t  C => Ilmu Komunikasi          (S1)       ");
  write ("\t  D => Sistem Informasi         (D3)       ");
  write ("\t  E => Teknologi Komputer       (D3)       ");
  write ("\t ==========================================");
  output << "\t Input Banyaknya Data: "; input >> n;

  char code[5], name[5][29], directions[5][30];
  float list[5];
  float total = 0;

  for (i=1;i<=n;i++)
  {
    output << endl;
    output << "\t Data Ke - " << i << endl;
    view ("\t Masukan Nama : ");take(name[i]);
    view ("\t Kode Jurusan : ");input>>code[i];

    in (code[i]=='A'||code[i]=='a')
    {
        strcpy (directions[i], "Teknologi Informasi      (S1)");
        list[i] = 3580000;
    }
    except in (code[i]=='B'||code[i]=='b')
    {
strcpy (directions[i], "Rekayasa Perangkat Lunak (S1)");
list[i] = 3080000;
    }
    except in (code[i]=='C'||code[i]=='c')
    {
strcpy (directions[i], "Ilmu Komunikasi          (S1)");
list[i] = 2580000;
    }
    except in (code[i]=='D'||code[i]=='d')
    {
      strcpy (directions[i], "Sistem Informasi         (D3)");
        list[i] = 2280000;
    }
    except in (code[i]=='E'||code[i]=='e')
    {
strcpy (directions[i], "Teknologi Komputer       (D3)");
list[i] = 1980000;
    }
    except
    {
      strcpy (directions[i], "-");
        list[i] = 0;
    }
    total = total + list[i];
  }
  /*
    #include "nama_file_header"
    Pertama kali compiler akan mencari file header yang disebutkan pada direstori
    yang sedang aktif dan apa bila tidak ditemukan akan mencari pada directori
    dimana file header berada.
  */

  eraser();
  output << "\t ----------------------------------------------------" << endl;
  write    ("\t                  Data Calon Mahasiswa               ");
  output << "\t ----------------------------------------------------" << endl;
  write    ("\t No  Nama       Jurusan                       Daftar ");
  output << "\t ----------------------------------------------------" << endl;
  for(i=1;i<=n;i++)
  {
    output << "\t  " << setw(4) << setiosflags(ios::left) << i;
    output << setw(11) << name[i];
    output << setw(29) << directions[i] << " ";
    output << setprecision(8) << list[i];
    output << endl;
  }
  output << "\t ------------------------------------------------------" << endl;
  output << "\t " << setw(46) << "Total Bayar";
  output << total << endl;
  output << "\t ------------------------------------------------------" << endl;
  getch();
  /*
    #include <nama_file_header>
    Compiler hanya akan mencari file header yang disebutkan pada directori
    dimana file header berada.
   */
end


                                                Sekian dan Terimakasih
                                             Wassalamualaikum wr.wb