Tampilkan postingan dengan label Coding. Tampilkan semua postingan
Tampilkan postingan dengan label Coding. Tampilkan semua postingan

Final Project Computer Programming II

Pre-Notes :

  • Menggunakan bahasa pemograman C
  • Menggunakan Struct
  • Menggunakan subroutines


/*Buatlah program yang menampilkan laporan angka matakuliah Computer Programming II .  
Tampilkan di text file, laporan angka yang terdiri atas nim,nama, persentase nilai quiz, persentase nilai test, 
persentase lab exercise, persentase nilai final, persentase nilai project . Nilai akhir dan grade (A,A-,etc). 
 Mintalah user untuk input nilai quiz, test, final, lab, dan project. Nilai quiz, test, dan lab dilakukan lebih dari 1 kali.
Nilai akhir diperoleh dari : 10% quiz + 20% lab + 20% test + 20% final + 30% project.
Tampilkan pula di text file histogram yang menyatakan frekuensi kemunculan setiap nilai akhir mahasiswa.*/


Visual Programming - Event Handling Examples

Event Handling Example....
This code will change the messages of a button after it was clicked

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package latihan6;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 *
 * @author ASUS N43S
 */

Visual Programming - Grid Bag Layout


Thanks to my friend for the frame.pack (); it's very useful when calculating the size was a problem......

Visual Programming - Strust, Rigid Area, Glue



Contoh Strust, Rigid Area, Glue menggunakan klas javax.swing dan java.awt pada NetBeans, secara umum manfaat dari ketiga fungsi ini adalah untuk memberikan jarak / space antar button

Visual Programming - Flow Layout2


Masih Contoh FlowLayout menggunakan klas javax.swing dan java.awt pada NetBeans, kali ini mencoba menumpuk beberapa panel pada panel lainnya...

Visual Programming - Flow Layout


Contoh FlowLayout menggunakan klas javax.swing dan java.awt pada NetBeans

Statistik Encryption

Berikut sebuah coding dari tugas membuat enkripsi statistik...

#include <stdio.h>
#include <conio.h>
#include <string.h>

int main ()
{
    
    char kata [8];
    char copy [8];
    float hitung [8];
    int pjg;
    float a = 4.1, b = 5.1, c = 6.1, d = 7.1, e = 8.1;
    float f = 0.1, g = 1.1, h = 2.1, i = 3.1, j = 4.2;
    float k = 5.2, l = 6.2, m = 7.2, n = 8.2, o = 0.2;
    float p = 1.2, q = 2.2, r = 3.2, s = 4.3, t = 5.3;
    float u = 6.3, v = 7.3, w = 8.3, x = 9.3, y = 0.3;
    float z = 2.3;
    
    printf ("Masukkan input = ");
    gets (kata);fflush (stdin);
    strcpy(copy,kata);
    pjg = strlen (kata);
    for (int i=0;i<pjg;i++)
    {
        if (copy[i]=='a') {hitung[i]=a;}
        if (copy[i]=='b') {hitung[i]=b;}    
        if (copy[i]=='c') {hitung[i]=c;}
        if (copy[i]=='d') {hitung[i]=d;}
        if (copy[i]=='e') {hitung[i]=e;}
        if (copy[i]=='f') {hitung[i]=f;}
        if (copy[i]=='g') {hitung[i]=g;}
        if (copy[i]=='h') {hitung[i]=h;}
        if (copy[i]=='i') {hitung[i]=i;}
        if (copy[i]=='j') {hitung[i]=j;}
        if (copy[i]=='k') {hitung[i]=k;}
        if (copy[i]=='l') {hitung[i]=l;}
        if (copy[i]=='m') {hitung[i]=m;}
        if (copy[i]=='n') {hitung[i]=n;}
        if (copy[i]=='o') {hitung[i]=o;}
        if (copy[i]=='p') {hitung[i]=p;}
        if (copy[i]=='q') {hitung[i]=q;}
        if (copy[i]=='r') {hitung[i]=r;}
        if (copy[i]=='s') {hitung[i]=s;}
        if (copy[i]=='t') {hitung[i]=t;}
        if (copy[i]=='u') {hitung[i]=u;}
        if (copy[i]=='v') {hitung[i]=v;}
        if (copy[i]=='w') {hitung[i]=w;}
        if (copy[i]=='x') {hitung[i]=x;}
        if (copy[i]=='y') {hitung[i]=y;}
        if (copy[i]=='z') {hitung[i]=z;}
        if (copy[i]==' ') {hitung[i]=3.3;}
    }
    
    printf ("hasil enkripsi = ");
    for (int i=0;i<pjg;i++)
    {
        printf ("%.1f", hitung[i]);    
    }
    
    
    for (int i=0;i<pjg;i++)
    {
        if (hitung[i]==a) {copy[i]='a';}
        if (hitung[i]==b) {copy[i]='b';}
        if (hitung[i]==c) {copy[i]='c';}
        if (hitung[i]==d) {copy[i]='d';}
        if (hitung[i]==e) {copy[i]='e';}
        if (hitung[i]==f) {copy[i]='f';}
        if (hitung[i]==g) {copy[i]='g';}
        if (hitung[i]==h) {copy[i]='h';}
        if (hitung[i]==i) {copy[i]='i';}
        if (hitung[i]==j) {copy[i]='j';}
        if (hitung[i]==k) {copy[i]='k';}
        if (hitung[i]==l) {copy[i]='l';}
        if (hitung[i]==m) {copy[i]='m';}
        if (hitung[i]==n) {copy[i]='n';}
        if (hitung[i]==o) {copy[i]='o';}
        if (hitung[i]==p) {copy[i]='p';}
        if (hitung[i]==q) {copy[i]='q';}
        if (hitung[i]==r) {copy[i]='r';}
        if (hitung[i]==s) {copy[i]='s';}
        if (hitung[i]==t) {copy[i]='t';}
        if (hitung[i]==u) {copy[i]='u';}
        if (hitung[i]==v) {copy[i]='v';}
        if (hitung[i]==w) {copy[i]='w';}
        if (hitung[i]==x) {copy[i]='x';}
        if (hitung[i]==y) {copy[i]='y';}
        if (hitung[i]==z) {copy[i]='z';}
        if (hitung[i]==3.3) {copy[i]=' ';}    
    }
    
printf ("\nhasil dekripsi = ");
for (int i=0;i<pjg;i++)
{
    printf ("%c", copy[i]);    
}
    
getche ();
return 0;
}

Factorial using Recursion Method

#include <iostream>
#include <conio.h>

using namespace std;

int calc (int x)
{
if (x==1)
{
return 1;
}
else
{
return (x * calc (x-1));
}
}

class factorial
{
private :
int number,fact,temp;

public :
void input ();
void proses ();
void output ();
}

int main ()
{
factorial f;

f.input ();
f.proses ();
f.output ();

getche ();
return 0;
}

void factorial :: input ()
{
cout << "input number = ";
cin >> number;
temp = number;
}
void factorial :: proses ()
{
fact = calc (temp);
}
void factorial :: output ()
{
cout << "factorial of " << number << " = " << fact;
}

Armstrong Number

#include <iostream>
#include <conio.h>

using namespace std;

class Armstrong ()
{
private :
int number,temp,carry,cek;

public :
void input ();
void proses ();
void output ();

};

int main ()
{
armstrong a;
a.input ();
a.proses ();
a.output ();

getche ();
return 0;
}

void armstrong :: input ()
{
cout << "input number = ";
cin >> number;
temp = number;
}

void armstrong :: proses ()
{
while (number > 0)
{
carry = number % 10;
cek = cek + (carry*carry*carry);
number = number / 10;
}
}
void armstrong :: output ()
{
if (cek==temp)
{
cout << temp << " is Armstrong number";
}
else
{
cout << temp << " is NOT Armstrong number";
}
}

Biggest Among N-number

#include <iostream>
using namespace std;

class biggest
{
private :
int jumlah,temp,big;

public :
    void input ()
    {
        cout<<"masukkan jumlah bilangan = "<<endl;
        cin>>jumlah;
    }
    void proses ()
    {
        cout<<"masukkan bilangan  = "<<endl;
        cin>>temp;
        big=temp;
      
        for (int i=2;i<=jumlah;i++)
        {
            cout<<"masukkan bilangan = "<<i<<endl;
            cin>>temp;
            if (big<temp)
            {
                big = temp;
              
            }
        }
    }
    void output ()
    {
        cout<<"biggest number = "<<big<<endl;
    }
};

int main ()
{

biggest b;
b.input ();
b.proses ();
b.output ();

system("PAUSE");
return 0;
}

Linked List Insertion

#include <stdio.h>
#include <conio.h>
#include <malloc.h>

struct node
{
    int data;
    node *link;
}

    node *front = NULL;
    node *rear = NULL;

void insertion
{
    node *temp = (node*) malloc (sizeof(node));
    printf ("Input Elements");
    scanf ("%d",&temp->data);
    if (front==NULL)
    {
        front = temp;
        rear = temp;
    }
    else
    {
        int pick;
        printf ("1.Front\n2.Rear\n3.Position");
        scanf ("%d",&pick);
        switch (pick)
        {
        case 1:
        temp->link = front;
        front = temp;
        break;

        case 2:
        rear->link = temp;
        rear = temp;
        rear->link = NULL;
        break;

        case 3:
        int pos;
        printf ("Insert Position");
        scanf ("%d",&pos);
        if (pos<1)
        {
            printf ("error");
        }
        else if (pos==1)
        {
            temp->link = front;
            front = temp;          
        }
        else
        {
            pos--;
            int count=1;
            node *trav;
            trav = front;
            while (count<pos && trav!=NULL)
            {
                count ++;
                trav=trav->link;
            }
            if (trav!=NULL)
            {
                temp->link=trav->link;
                trav->link=temp;
                if (rear->link!=NULL)
                {
                    rear=temp;
                }
            }
            else
            {
                printf ("error");
            }
        }
        break;
        }
  
    }
}

Queues using Pointer

Praktek Mata Kuliah Data Structure

Queues on Pointer (Dynamic Memory Allocation) using DevC++

 #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>

struct node
{
    int data;
    struct node *link;
};

node *front = NULL;
node *rear = NULL;

void insertion ()
{
     node *temp = (node*) malloc (sizeof(node));
     printf ("Insert Value = ");
     scanf ("%d",&temp->data);
     temp->link = NULL;
     if (front==NULL)
     {
        front=temp;
        rear=temp;              
     }
     else
     {
        rear->link=temp;
        rear=temp;  
     }   
}

void deletion ()
{
     if(front==NULL)
     {
        printf ("Queues is Empty");             
     }
     else
     {
        node *temp;
        printf ("Elemen to be deleted = %d",front->data);
        temp=front;
        front=front->link;
        free (temp);  
     }   
}

void display ()
{
     if (front==NULL)
     {
        printf ("Queues is Empty");
     }
     else
     {
         node *temp;
         temp=front;
         printf ("elemen of Queues = \n");
         for (temp=front;temp!=NULL;temp=temp->link)
         {
               printf ("%d\t",temp->data);
         }  
     }   
}

void selection ()
{
    int pilih;
    do
    {
    printf ("\n\nQueues Using Dynamic Memory Allocation");
    printf ("\n1. Insertion ");
    printf ("\n2. Deletion");
    printf ("\n3. Display");
    printf ("\ninsert your selection = ");
    scanf ("%d",&pilih);
    switch (pilih)
           {
           case 1:
           insertion ();
           break;
         
           case 2:
           deletion ();
           break;
         
           case 3:
           display ();
           break;     
           }
    }while (pilih!=0);  
}
int main ()
{
    selection ();
    printf ("\n");  
    getche ();
    return 0;
}

Stack Using Pointer

Praktek Mata Kuliah Data Structure

Stack on Pointer (Dynamic Memory Allocation) using DevC++

 #include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>

struct node
{
int data;
struct node *link;     
};

node *high = NULL;

void pushdynamic ()
{
     node*temp = (node*) malloc (sizeof(node));
     printf ("Input values = ");
     scanf ("%d",&temp->data);
     temp->link = high;
     high = temp;
}

void popdynamic ()
{
     if (high==NULL)
     {
        printf ("Stack is Empty");            
     }
     else
     {
         node *temp;
         temp=high;
         printf ("Values to be deleted = %d",temp->data);
         high=high->link;
         free (temp);
     }   
}
void displaydynamic ()
{
     if (high==NULL)
     {
        printf ("Stack is Empty\nCan't display the elemen");
     }
     else
     {
        node *temp;
        temp=high;
        while(temp!=NULL)
        {
          printf ("The Elemen of Stack\n");
          printf ("%d\n",temp->data);
          temp=temp->link;               
        }  
     }   
}
void selection ()
{
    int pilih;
    do
    {
    printf ("\n\nStack Using Dynamic Memory Allocation");
    printf ("\n1. Push ");
    printf ("\n2. Pop");
    printf ("\n3. Display");
    printf ("\ninsert your selection = ");
    scanf ("%d",&pilih);
    switch (pilih)
           {
           case 1:
           pushdynamic ();
           break;
         
           case 2:
           popdynamic ();
           break;
         
           case 3:
           displaydynamic ();
           break;     
           }
    }while (pilih!=0);  
}
int main ()
{
    selection ();
    printf ("\n");  
    getche ();
    return 0;
}

Circular Queues

Praktek Mata Kuliah Data Structure

Circular Queues on Array using DevC++

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define n 6

int array [n];
int front=0;
int rear=0;
int pick;

void insertion ()
{
     if((rear+1)%n==front)
     {
         printf ("Queue is Full");                    
     }
     else
     {
         rear=(rear+1)%n;
         printf ("Input value = ");
         scanf ("%d",&array[rear]);   
     }    
}

void deletion ()
{
     if (front==rear)
     {
          printf ("Queues is empty");               
     }
     else
     {
          printf ("Elemen to be deleted = %d", array[front+1]);
          front=(front+1)%n;   
     }    
}

void display ()
{
     if (front==rear)
     {
          printf ("Queues is empty");               
     }
     else
     {
         printf ("Elemen of Queues = \n");
         for (int i=front+1;i<=rear;i=(i+1)%n)
         {
          printf ("%d\n", array[i]);   
         }   
     }    
}

int main ()
{
    do
    {
    printf ("\n\nQueues Using Circular Array");
    printf ("\n1. Insert Queues");
    printf ("\n2. Deletion Queues");
    printf ("\n3. Display Queues");
    printf ("\nInsert your selection = ");
    scanf ("%d",&pick);
    switch (pick)
         {
         case 1:
              insertion ();
              break;
         case 2:
              deletion ();
              break;
         case 3:
              display ();
              break;
         }
    }while (pick!=0);  
    getche ();
    return 0;   
}

Queues Using Array

Praktek Mata Kuliah Data Structure

Queues on Array using DevC++


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define n 6

int array [n];
int front=-1;
int rear=-1;
int pick;

void insertion ()
{
     if (rear<n-1)
     {
        rear++;
        printf ("Insert value = ");
        scanf ("%d",&array[rear]);            
     }
     else
     {
         printf ("Queues is FULL");   
     }    
}

void deletion ()
{
     if (rear!=front)
     {
        front++;
        printf ("Value to be deleted = %d", array[front]);               
     }
     else
     {
        printf ("Queues is EMPTY");   
     }   
}

void show ()
{
     if (rear!=front)
     {
        for (int i=front+1;i<=rear;i++)
        {
            printf ("%d\n",array[i]);   
        }               
     }
     else
     {
         printf ("Queues is EMPTY");   
     }    
}

void adjusted ()
{
     if (front!=rear)    
     {
        printf ("values to be deleted = %d", array[front+1]);
        for(int i=0;i<rear;i++)
        {
             array[i]=array[i+1];                  
        }
        rear--;                    
     }
     else
     {
         printf ("Queues is EMPTY");   
     }
}

int main ()
{  
    do
    {
    printf ("\n\nQueues Using Array");
    printf ("\n1. Insert Queues");
    printf ("\n2. Deletion Queues");
    printf ("\n3. Display Queues");
    printf ("\n4. Deletion Adjusted Queues");
    printf ("\nInsert your selection = ");
    scanf ("%d",&pick);
    switch (pick)
         {
         case 1:
              insertion ();
              break;
         case 2:
              deletion ();
              break;
         case 3:
              show ();
              break;
         case 4:
              adjusted ();
              break;
         }
    }while (pick!=0);  
getche ();
return 0;
}

Stack Using Array

Praktek Mata Kuliah Data Structure

Stack on Array using DevC++
 
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define n 6

void push ();
void pop ();
void display ();

int array[n];
int top=-1;
int pick;

int main ()
{
    do
    {
    printf ("\n\nSelection Menu");
    printf ("\n1. Push Stack");
    printf ("\n2. Pop Stack");
    printf ("\n3. Display Stack");
    printf ("\nInsert your selection = ");
    scanf ("%d",&pick);
    switch (pick)
         {
         case 1:
              push ();
              break;
         case 2:
              pop ();
              break;
         case 3:
              display ();
              break;
         }
    }while (pick!=0);  
getche ();
return 0;
}

void push ()
{
     if (top<n-1)
     {
        top++;
        printf ("insert element to the stack = ");
        scanf ("%d",&array[top]);           
     }
     else
     {
         printf ("Stack is overflow");   
     }    
}

void pop ()
{
     if (top>-1)
     {
        top--;
        printf ("The Top Value = %d", array[top]);          
     }
     else
     {
         printf ("Stack is underflow");   
     }    
}

void display ()
{
     if (top>-1)
     {
        for (int i=top;i>=0;i--)
        {
            printf ("%d\n",array[i]);   
        }          
     }
     else
     {
         printf ("Stack is Empty");   
     }    
}