About Me

Assalamu Alaikum Warahmatullahi wabarakatu, sebelumnya saya selalu membahas tentang C++, nah kali ini tetap saya masih membahas tentang C++ tapi pertemuan kali ini saya ingin sharing hasil laporan matakuliah Algoritma  saya, yaitu pembuatan aplikasi pembelian ticket bioskop, nahh langsung saja lihat dibawa ini Source Code saya menggunakan bahasa program C++


PROGRAM BIOSKOP



#include <iostream.h>
 
#include <conio.h>
 
void main()
 
{
 
 int pil,a;
 
 do
 
 {
 
    clrscr();
 
   cout<<"::::::::::: SELAMAT DATANG DI SISTEM TERPADU WISATA CINEMA :::::::::::\n\n";
 
   cout<<"<-------------------------------------------->\n";
 
   cout<<" | oleh : Muh.Adhar (141111020) |\n";
 
   cout<<"<-------------------------------------------->\n\n";
 
   cout<<" -----------MENU-------------\n";
 
   cout<<"| 1. PEMBELIAN TIKET         |\n";
 
   cout<<"| 2. CEK SISA KURSI          |\n";
 
    cout<<"| 3. LAPORAN PENJUALAN TIKET |\n";
 
   cout<<"| 4. KELUAR                  |\n\n";
 
   cout<<"Masukkan pilihan anda : ";
 
   cin>>pil;
 
   switch (pil)
 
    {
 
        case 1:
 
      mulai:
 
      clrscr();
 
        int jenis,jumlah,total_tiket;
 
    char* jenis_txt;
 
      char ulang;
 
    cout<<":::::::> SELAMAT DATANG DI WISATA CINEMA <:::::::\n\n";
 
    cout<<"Harga tiket :\nDewasa\t: Rp. 20.000,-\nAnak\t: Rp. 15.000,-\n\n";
 
    cout<<"Silahkan input jenis tiket\n";
 
    cout<<"1 : Dewasa\n2 : Anak-anak\n\n";
 
    cout<<"Jenis : "; cin>>jenis;
 
    cout<<"\n\nSilahkan input jumlah tiket\n";
 
    cout<<"Jumlah : "; cin>>jumlah;
 
    if (jenis==1)
 
    {
 
        total_tiket=jumlah*20000;
 
        jenis_txt="Dewasa";
 
    }
 
    else if (jenis==2)
 
    {
 
        total_tiket=jumlah*15000;
 
        jenis_txt="Anak-anak";
 
    }
 
    else
 
    {
 
        cout<<"\n\nInput Jenis Salah, Mohon ulangi lagi";
 
        getch();
 
        goto mulai;
 
    }
 
    clrscr();
 
    cout<<":::::::> SELAMAT DATANG DI WISATA CINEMA <:::::::\n\n";
 
    cout<<"Jenis tiket      : "<<jenis_txt<<endl;
 
    cout<<"Jumlah pembelian : "<<jumlah<<"\n";
 
    cout<<"---------------------------------- \n";
 
    cout<<"TOTAL            : Rp. "<<total_tiket<<",-";
 
    getch();
 
      break;
 
      case 2:
 
        clrscr();
 
        int kursi_isi[4],kursi_kosong[4];
 
    cout<<"::::::::::::::::::  CEK SISA KURSI  ::::::::::::::::::\n\n";
 
    cout<<"PETUNJUK :\n-> Jumlah kursi di tiap Wisata adalah 50 kursi\n";
 
    cout<<"-> Silahkan masukkan jumlah kursi yang telah ditempati\n\n";
 
      a=0;
 
    do
 
    {
 
        cout<<"Wisata "<<a+1<<" : ";
 
        cin>>kursi_isi[a];
 
        a++;
 
    }
 
    while (a<4);
 
    for (a=0;a<4;a++)
 
        kursi_kosong[a]=50-kursi_isi[a];
 
    clrscr();
 
    cout<<"::::::::::::::::::  CEK SISA KURSI  ::::::::::::::::::\n\n";
 
        cout<<":\tSISA KURSI\t:\n";
 
    cout<<"-------------------------\n";
 
    for (a=0;a<4;a++)
 
    {
 
        cout<<"    Wisata "<<a+1<<" : "<<kursi_kosong[a];
 
        cout<<"\n-------------------------\n";
 
    }
 
      getch();
 
      break;
 
        case 3:
 
      clrscr();
 
        int wisata_anak[4],wisata_dewasa[4],total[4];
 
    cout<<":::::::::::  LAPORAN PENJUALAN TIKET  :::::::::::\n\n";
 
    for (a=0;a<4;a++)
 
    {
 
        cout<<"Silahkan masukkan data penjualan tiket Wisata "<<a+1<<" : ";
 
        cout<<"\nAnak-anak : "; cin>>wisata_anak[a];
 
        cout<<"Dewasa    : "; cin>>wisata_dewasa[a];
 
        cout<<endl;
 
    }
 
    for (a=0;a<4;a++)
 
        total[a]=wisata_anak[a]+wisata_dewasa[a];
 
      clrscr();
 
      cout<<":::::::::::  LAPORAN PENJUALAN TIKET  :::::::::::\n\n";
 
      cout<<"----------------- PENJUALAN ------------------\n";
 
    cout<<"\nWisata / Anak-anak / Dewasa / Total Penjualan\n";
 
    for (a=0;a<4;a++)
 
    {
 
        cout<<a+1<<"        "<<wisata_anak[a]<<"          "<<wisata_dewasa[a];
 
        cout<<"       "<<total[a]<<endl;
 
    }
 
      getch();
 
      break;
 
    }
 
 }
 
 while (pil!=4);
 
}





Hayy apa kabar, kembali lagi dengan saya konan kato ingin berbagi di blok saya tentang Linked Lists di bahasa programan C++, langsung saja lihat Source code C++ di bawah ini

Singly Linked Lists


/* definition of the list node class */
class Node
{
    friend class LinkedList;
private:
    int _value; /* data, can be any data type, but use integer for easiness */
    Node *_pNext; /* pointer to the next node */
   
public:
    /* Constructors with No Arguments */
    Node(void)
    : _pNext(NULL)
    { }
   
    /* Constructors with a given value */
    Node(int val)
    : _value(val), _pNext(NULL)
    { }
   
    /* Constructors with a given value and a link of the next node */
    Node(int val, Node* next)
    : _value(val), _pNext(next)
    {}
   
    /* Getters */
    int getValue(void)
    { return _value; }
   
    Node* getNext(void)
    { return _pNext; }
};

/* definition of the linked list class */
class LinkedList
{
private:
    /* pointer of head node */
    Node *_pHead;
    /* pointer of tail node */
    Node *_pTail;
   
public:
    /* Constructors with No Arguments */
    LinkedList(void);
    /* Constructors with a given value of a list node */
    LinkedList(int val);
    /* Destructor */
    ~LinkedList(void);
   
    /* Traversing the list and printing the value of each node */
    void traverse_and_print();
};

LinkedList::LinkedList()
{
    /* Initialize the head and tail node */
    _pHead = _pTail = NULL;
}

LinkedList::LinkedList(int val)
{
    /* Create a new node, acting as both the head and tail node */
    _pHead = new Node(val);
    _pTail = _pHead;
}

LinkedList::~LinkedList()
{
    /*
     * Leave it empty temporarily.
     * It will be described in detail in the example "How to delete a linkedlist".
     */
}

void LinkedList::traverse_and_print()
{
    Node *p = _pHead;
   
    /* The list is empty? */
    if (_pHead == NULL) {
        cout << "The list is empty" << endl;
        return;
    }
   
    cout << "LinkedList: ";
    /* A basic way of traversing a linked list */
    while (p != NULL) { /* while there are some more nodes left */
        /* output the value */
        cout << p->_value;
        /* The pointer moves along to the next one */
        p = p->_pNext;
    }
    cout << endl;
}

int main(int argc, const char * argv[])
{
    /* Create an empty list */
    LinkedList list1;
    cout << "Created an empty list named list1." << endl;
    /* output the result */
    cout << "list1:" << endl;
    list1.traverse_and_print();
   
    /* Create a list with only one node */
    LinkedList list2(10);
    cout << "Created a list named list2 with only one node." << endl;
    /* output the result */
    cout << "list2:" << endl;
    list2.traverse_and_print();
   
    return 0;
}

Circularly Linked Lists
 
 
#include <iostream>
using namespace std;

template <class T>
struct Node
{
  T data;
  Node * next;
  Node(T data) : data(data), next(NULL) {}
};

template <class T>
class CircularLinkedList
{
public:
  CircularLinkedList() : head(NULL) {}
  ~CircularLinkedList();
  void addNode(T data);
  void deleteNode(T data);
  template <class U>
  friend std::ostream & operator<<(std::ostream & os, const CircularLinkedList<U> & cll);
private:
  Node<T> * head;
};

template <class T>
CircularLinkedList<T>::~CircularLinkedList()
{
  if (head)
    {
      Node<T> * tmp = head;
      while (tmp->next != head)
        {
          Node<T> * t = tmp;
          tmp = tmp->next;
          delete(t);
        }
      delete tmp;
      head = NULL;
    }
}

template <class T>
void CircularLinkedList<T>::addNode(T data)
{
  Node<T> * t = new Node<T>(data);

  if (head == NULL)
    {
      t->next = t;
      head = t;
      return;
    }

  Node<T> * tmp = head;
  while (tmp->next !=  head)
    {
      tmp = tmp->next;
    }

  tmp->next = t;
  t->next = head;
}

template <class T>
void CircularLinkedList<T>::deleteNode(T data)
{
  Node<T> * tmp = head;
  Node<T> * prev = NULL;
  while (tmp->next !=  head)
    {
      if (tmp->data == data) break;
      prev = tmp;
      tmp = tmp->next;
    }

  if (tmp == head)
    {
      while (tmp->next != head)
        {
          tmp = tmp->next;
        }
      tmp->next = head->next;
      delete head;
      head = tmp->next;
    }
  else
    {
      prev->next = tmp->next;
      delete tmp;
    }
}

template <class U>
std::ostream & operator<<(std::ostream & os, const CircularLinkedList<U> & cll)
{
  Node<U> * head = cll.head;
  if (head)
    {
      Node<U> * tmp = head;
      while (tmp->next != head)
        {
          os << tmp->data << " ";
          tmp = tmp->next;
        }
      os << tmp->data;
    }
  return os;
}

int main()
{
  CircularLinkedList<int> cll;

  cll.addNode(1);
  cll.addNode(2);
  cll.addNode(3);
  cll.addNode(4);
  cll.addNode(5);

  cout << cll << endl;

  cll.deleteNode(3);
  cll.deleteNode(1);
  cll.deleteNode(5);

  cout << cll << endl;

  return 0;
}

Doubly Linked Lists 

#include<iostream>
using namespace std;

/* Linked list structure */
struct list {
 struct list *prev;
 int data;
 struct list *next;
} *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;

class linkedlist {
 public: 

  /* Function for create/insert node at the beginning of Linked list */
  void insert_beginning() {
   list *addBeg = new list;
   cout << "Enter value for the node:" << endl;
   cin >> addBeg->data;
   if(first == NULL) {
    addBeg->prev = NULL;
    addBeg->next = NULL;
    first = addBeg;
    last = addBeg;
    cout << "Linked list Created!" << endl;
   }
   else {
    addBeg->prev = NULL;
    first->prev = addBeg;
    addBeg->next = first;
    first = addBeg;
    cout << "Data Inserted at the beginning of the Linked list!" << endl;
   }
  }

  /* Function for create/insert node at the end of Linked list */
  void insert_end() {
   list *addEnd = new list;
   cout << "Enter value for the node:" << endl;
   cin >> addEnd->data;
   if(first == NULL) {
    addEnd->prev = NULL;
    addEnd->next = NULL;
    first = addEnd;
    last = addEnd;
    cout << "Linked list Created!" << endl;
   }
   else {
    addEnd->next = NULL;
    last->next = addEnd;
    addEnd->prev = last;
    last = addEnd;
    cout << "Data Inserted at the end of the Linked list!" << endl;
   }
  }

  /* Function for Display Linked list */
  void display() {
   node = first;
   cout << "List of data in Linked list in Ascending order!" << endl;
   while(node != NULL) {
    cout << node->data << endl;
    node = node->next;
   }
   node = last;
   cout << "List of data in Linked list in Descending order!" << endl;
   while(node != NULL) {
    cout << node->data << endl;
    node = node->prev;
   }
  }
 
  /* Function for delete node from Linked list */
  void del() {
   int count = 0, number, i;
   node = node1 = node2 = first;
   for(node = first; node != NULL; node = node->next)
    cout << "Enter value for the node:" << endl;
   count++;
   display();
   cout << count << " nodes available here!" << endl;
   cout << "Enter the node number which you want to delete:" << endl;
   cin >> number;
   if(number != 1) {
    if(number < count && number > 0) {
     for(i = 2; i <= number; i++)
      node = node->next;
     for(i = 2; i <= number-1; i++)
      node1 = node1->next;
     for(i = 2; i <= number+1; i++)
      node2 = node2->next;
     node2->prev = node1;
     node1->next = node2;
     node->prev = NULL;
     node->next = NULL;
     node = NULL;
    }
    else if(number == count) {
     node = last;
     last = node->prev;
     last->next = NULL;
     node = NULL;
    }
    else
     cout << "Invalid node number!" << endl;
   }
   else {
    node = first;
    first = node->next;
    first->prev = NULL;
    node = NULL;
   }
   cout << "Node has been deleted successfully!" << endl;
  }
 
};

int main() {
 int op = 0;
 linkedlist llist = linkedlist();
 while(op != 4) {
  cout << "1. Insert at the beginning\n2. Insert at the end\n3. Delete\n4. Display\n5. Exit" << endl;
  cout << "Enter your choice:" << endl;
  cin >> op;
  switch(op) {
   case 1:
    llist.insert_beginning();
    break;
   case 2:
    llist.insert_end();
    break;
   case 3:
    llist.del();
    break;
   case 4:
    llist.display();
    break;
   case 5:
    cout << "Bye Bye!" << endl;
    return 0;
    break;
   default:
    cout << "Invalid choice!" << endl;
  }
 }
 return 0;
}
 
assalamu alaikum,,, kembali lagi dengan saya konan kato, kesempatan kali ini saya akan membagikan post terbaru saya yaitu program pecahan menggunakan bahasa pemrograman C++, langsung saja berikut ini source code C++


#include
using namespace std;
void menu();

void samakan(int& a, int& b, int& c, int& d)
{
int x, y;
for (int i=1;i<=(b * d);i++)
{
if ((i % b == 0)&&(i % d == 0))
{
x = i/b;
y = i/d;
break;
}
}
a = a * x; b = b * x; c = c * y; d = d * y;
}
void jumlah()
{
int a, b, c, d, e, f;
cout<<" Pecahan A = ";cin>>a;
cout<<" --\n";
cout<<" ";cin>>b;
cout<

cout<<" Pecahan B = ";cin>>c;
cout<<" --\n";
cout<<" ";cin>>d;
cout<
if (b != d)
samakan(a,b,c,d);
e=a+c;
f=b;
cout<<" A + B = "<<
cout<<" --\n";
cout<<" "<<
cout<
for (int s=0;s<1000000000;s++);
menu();
}
void kurang()
{
int a, b, c, d, e, f;
cout<<" Pecahan A = ";cin>>a;
cout<<" --\n";
cout<<" ";cin>>b;
cout<

cout<<" Pecahan B = ";cin>>c;
cout<<" --\n";
cout<<" ";cin>>d;
cout<
if (b != d)
samakan(a,b,c,d);
e=a-c;
f=b;
cout<<" A - B = "<<
cout<<" --\n";
cout<<" "<<
cout<
for (int s=0;s<1000000000;s++);
menu();
}
void kali()
{
int a, b, c, d, e, f;
cout<<" Pecahan A = ";cin>>a;
cout<<" --\n";
cout<<" ";cin>>b;
cout<
cout<<" Pecahan B = ";cin>>c;
cout<<" --\n";
cout<<" ";cin>>d;
cout<
e=a*c;
f=b*d;
cout<<" A x B = "<<
cout<<" --\n";
cout<<" "<<
cout<
for (int s=0;s<1000000000;s++);
menu();
}
void bagi()
{
int a, b, c, d, e, f;
cout<<" Pecahan A = ";cin>>a;
cout<<" --\n";
cout<<" ";cin>>b;
cout<
cout<<" Pecahan B = ";cin>>c;
cout<<" --\n";
cout<<" ";cin>>d;
cout<
e=a*d;
f=b*c;
cout<<" A : B = "<<
cout<<" --\n";
cout<<" "<<
cout<
for (int s=0;s<1000000000;s++);
menu();
}
void menu()
{
system("cls");
char pil;
cout<<" OPERASI PECAHAN\n";
cout<<"=======================================================\n";
cout<<" a. Operasi Penjumlahan\n";
cout<<" b. Operasi Pengurangan\n";
cout<<" c. Operasi Perkalian\n";
cout<<" d. Operasi Pembagian\n";
cout<<" e. Keluar\n";
cout<<"=======================================================\n";
cout<<" Pilihan Operasi [a..d] = ";cin>>pil;
cout<
switch (pil)
{
case 'a' : jumlah();
break;
case 'b' : kurang();
break;
case 'c' : kali();
break;
case 'd' : bagi();
break;
}
}
void main()
{
menu();
cout<<"=======================================================\n";
cout<<" copyleft(c)BananaSoft2009\n";
cout<<
}