Senin, 17 Januari 2011

Bahan Virtualisasi dan Mat diskrit(Aljabar Boolean)

http://www.ziddu.com/download/13361893/PERTEMUANXIV.docx.html

http://www.ziddu.com/download/13362063/AljabarBoolean.ppt.html

Sabtu, 15 Januari 2011

Genap dan Ganjil pada c++

#include <stdio.h>
#include <conio.h>
void main ()
{
int Genap[10], Ganjil[10], i=1, n, g, sisa, x, y, temp;
printf ("PROGRAM GENAP / GANJIL\n");
printf ("1. Genap\n2. Ganjil\n");
printf ("Pilih 1 atau 2 ?"); scanf ("%d",&g);
while (i>=1)
if (g == 1)
{
printf ("Anda memilih program genap\n");
i=0;
}
else if (g == 2)
{
printf ("Anda memilih program ganjil\n");
i=0;
}
else
{
printf ("Salah input\n");
i+1;
printf ("Pilih 1 atau 2 ?"); scanf ("%d",&g);
}
printf ("Masukkan jumlah data yang akan anda gunakan :"); scanf ("%d",&n);
if (g == 1)
{
for (i=0;i<n;i++)
{
printf ("Masukkan data genap ke %d :",i+1); scanf ("%d",&Genap[i]);
sisa = Genap[i] % 2;
if (sisa != 0)
{
i = 0;
printf ("Salah Input\nSilahkan mengulang inputan dari awal\n");
printf ("Masukkan data genap ke %d :",i+1); scanf ("%d",&Genap[i]);
}
}
}
else
{
for (i=0;i<n;i++)
{
printf ("Masukkan data ganjil ke %d :",i+1); scanf ("%d",&Ganjil[i]);
sisa = Ganjil[i] % 2;
if (sisa == 0)
{
i = 0;
printf ("Salah Input\nSilahkan mengulang inputan dari awal\n");
printf ("Masukkan data ganjil ke %d :",i+1); scanf ("%d",&Ganjil[i]);
}
}
}
if (g == 1)
{
for (x=0;x<n;x++)
{
for (y=n;y>=x;y--)
{
if (Genap[y] < Genap[y-1])
{
temp = Genap[y];
Genap[y] = Genap[y-1];
Genap[y-1] = temp;
}
}
}
}
else
{
for (x=0;x<n;x++)
{
for (y=n;y>=x;y--)
{
if (Ganjil[y] < Ganjil[y-1])
{
temp = Ganjil[y];
Ganjil[y] = Ganjil[y-1];
Ganjil[y-1] = temp;
}
}
}
}
if (g == 1)
{
for (i=0;i<n;i++)
{
if (i<n-1)
{
printf ("1/%d + ",Genap[i+1]);
}
else
{
printf ("1/%d",Genap[i+1]);
}
}
}
else
{
for (i=0;i<n;i++)
{
if (i<n-1)
{
printf ("1/%d + ",Ganjil[i+1]);
}
else
{
printf ("1/%d",Ganjil[i+1]);
}
}
}
printf ("\n");
getch();
}








 

Berbagai coding Sorting pada c++

#include<iostream>
using namespace std;

template<class T>
class Sorting{

T * list;
int n;

void swap(T & x1, T & x2){
T x3 = x1;
x1 = x2;
x2 = x3;
}

public:
Sorting(int x=5){
n=x;
list = new T[n];
}

T * getList(){
T * temp = new T[n];
for(int i=0;i<n;i++)
temp[i] = list[i];
return temp;
}

void inputList(){
for(int i=0;i<n;i++)
cin>>list[i];
}

void display(){
for(int i=0;i<n;i++)
cout<<list[i]<<" ";
}

void selectionSort(){
/***** algorithm ***
1.Find the minimum value in the list
2.Swap it with the value in the first position
3.Repeat the steps above for the remainder of the list
(starting at the second position and advancing each time)
*/

T * temp = getList();

for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++)
{
if(temp[j]<temp[i]){
swap(temp[i], temp[j]);
}
}
}

cout<<"After applying \"selection\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void insertionSort(){
/***** algorithm ***
1. current position begin with 0
2. increment current position
3. insert current value (position i) in appropiate position of the left list
4. repeat step 2
*/
T * temp = getList();

for(int i=0;i<n-1;i++){ //i<n-1 because j= i+1, last value of j is the last element
int j=i+1;
while(temp[j]<temp[j-1] && j>0){ //swap current position with previous one if it is less
swap(temp[j], temp[j-1]);
j--; // decrement current position
}
}

cout<<"After applying \"insertion\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void shellSort(){
/***** algorithm ***
1. calculate Shell's increment, begin with n/2
2. for position i [0:increment]
sort the list using insertion sort start with i, with increment=increment
3. set increment = increment/2, repeat step 2 until increment = 1
*/
T * temp = getList();

int increment = n/2;
while(increment >= 1){
for(int i=0; i<increment; i++){
/////////insertion sort that start from i with increment = increment
for(int j=i;j<n-increment;j+=increment){
int k = j+increment;
while(temp[k]<temp[k-increment] && k>i){
swap(temp[k],temp[k-increment]);
k-=increment;
}
}
/////////////////////////////////////////////////
}
increment /=2;
}
cout<<"After applying \"shell\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void quickSort(T * temp, int l,int h){
/***** algorithm ***
1. Pick a pivot from the list.
2. Do partition operation by reordering the list so that:
- all elements with values less than the pivot come before the pivot,
- while all elements with values greater than the pivot come after it
(equal values can go either way).
After this partitioning, the pivot is in its final position.
3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
*/
int i=l,j=h;
int m=(l+h)/2;
T pivot=temp[m];

while(i<=j){ //partition

while(temp[i]<pivot)
i++;

while(temp[j]>pivot)
j--;

if(i<=j){
swap(temp[i],temp[j]);
i++;
j--;
}

}

if(l<j)
quickSort(temp,l,j);

if(h>i)
quickSort(temp,i,h);
}

void mergeSort(T * temp, int l, int h){
/*
1. split list recursively
2. call merge function to merge splited list in order
*/
if(l < h){
int m = (l+h)/2;
mergeSort(temp,l,m);
mergeSort(temp,m+1,h);
merge(temp,l,m,h);
}
}

private:
void merge(T * temp, int l, int m, int h){ //function for merge sort312

T * aux = new T[m];
int i=l,j=l,k=l;

//copy first half list temp to auxilary array aux
while(j<=m)
aux[j++] = temp[i++];

//merge aux with second half temp into temp
i=l,j=m+1;
while(i<=j && j<=h){ //i<j alway true therfore all second half will be copied "<="

if(aux[i]<temp[j] && i<=m) //i<=m (because i=m first half ends
temp[k++] = aux[i++];
else
temp[k++] = temp[j++];
}

//copy remaining first half if any
while(k<=h)
temp[k++] = aux[i++];
}
};

void main()
{
int ch,size;

cout<<"\nWhat is the size of the list?\n";
cin>>size;

Sorting<int> st(size);

cout<<"\nPlease insert list:\n";
st.inputList();

do{
cout<<"\nPlease select your choice:\
\n 1.apply insertion sort\
\n 2.apply selection sort\
\n 3.apply shell sort\
\n 4.apply quick sort\
\n 5.apply merge sort\
\n 6.display original list\
\n 7.input another list\n";
cin>>ch;

switch(ch){
case 1:
st.insertionSort();
break;
case 2:
st.selectionSort();
break;
case 3:
st.shellSort();
break;
case 4:
{
int * temp = st.getList();
st.quickSort(temp,0,size-1);
cout<<"After applying \"quick\" sort, the list become:\n";
for(int i=0;i<size;i++)
cout<<temp[i]<<" , ";
}
break;
case 5:
{
int * temp = st.getList();
st.mergeSort(temp,0,size-1);
cout<<"After applying \"merge\" sort, the list become:\n";
for(int i=0;i<size;i++)
cout<<temp[i]<<" , ";
}
break;
case 6: st.display();
break;
case 7:
cout<<"\nPlease insert list:\n";
st.inputList();
break;

}
}while(ch);
}#include<iostream>
using namespace std;

template<class T>
class Sorting{

T * list;
int n;

void swap(T & x1, T & x2){
T x3 = x1;
x1 = x2;
x2 = x3;
}

public:
Sorting(int x=5){
n=x;
list = new T[n];
}

T * getList(){
T * temp = new T[n];
for(int i=0;i<n;i++)
temp[i] = list[i];
return temp;
}

void inputList(){
for(int i=0;i<n;i++)
cin>>list[i];
}

void display(){
for(int i=0;i<n;i++)
cout<<list[i]<<" ";
}

void selectionSort(){
/***** algorithm ***
1.Find the minimum value in the list
2.Swap it with the value in the first position
3.Repeat the steps above for the remainder of the list
(starting at the second position and advancing each time)
*/

T * temp = getList();

for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++)
{
if(temp[j]<temp[i]){
swap(temp[i], temp[j]);
}
}
}

cout<<"After applying \"selection\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void insertionSort(){
/***** algorithm ***
1. current position begin with 0
2. increment current position
3. insert current value (position i) in appropiate position of the left list
4. repeat step 2
*/
T * temp = getList();

for(int i=0;i<n-1;i++){ //i<n-1 because j= i+1, last value of j is the last element
int j=i+1;
while(temp[j]<temp[j-1] && j>0){ //swap current position with previous one if it is less
swap(temp[j], temp[j-1]);
j--; // decrement current position
}
}

cout<<"After applying \"insertion\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void shellSort(){
/***** algorithm ***
1. calculate Shell's increment, begin with n/2
2. for position i [0:increment]
sort the list using insertion sort start with i, with increment=increment
3. set increment = increment/2, repeat step 2 until increment = 1
*/
T * temp = getList();

int increment = n/2;
while(increment >= 1){
for(int i=0; i<increment; i++){
/////////insertion sort that start from i with increment = increment
for(int j=i;j<n-increment;j+=increment){
int k = j+increment;
while(temp[k]<temp[k-increment] && k>i){
swap(temp[k],temp[k-increment]);
k-=increment;
}
}
/////////////////////////////////////////////////
}
increment /=2;
}
cout<<"After applying \"shell\" sort, the list become:\n";
for(int i=0;i<n;i++)
cout<<temp[i]<<" , ";
}

void quickSort(T * temp, int l,int h){
/***** algorithm ***
1. Pick a pivot from the list.
2. Do partition operation by reordering the list so that:
- all elements with values less than the pivot come before the pivot,
- while all elements with values greater than the pivot come after it
(equal values can go either way).
After this partitioning, the pivot is in its final position.
3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
*/
int i=l,j=h;
int m=(l+h)/2;
T pivot=temp[m];

while(i<=j){ //partition

while(temp[i]<pivot)
i++;

while(temp[j]>pivot)
j--;

if(i<=j){
swap(temp[i],temp[j]);
i++;
j--;
}

}

if(l<j)
quickSort(temp,l,j);

if(h>i)
quickSort(temp,i,h);
}

void mergeSort(T * temp, int l, int h){
/*
1. split list recursively
2. call merge function to merge splited list in order
*/
if(l < h){
int m = (l+h)/2;
mergeSort(temp,l,m);
mergeSort(temp,m+1,h);
merge(temp,l,m,h);
}
}

private:
void merge(T * temp, int l, int m, int h){ //function for merge sort312

T * aux = new T[m];
int i=l,j=l,k=l;

//copy first half list temp to auxilary array aux
while(j<=m)
aux[j++] = temp[i++];

//merge aux with second half temp into temp
i=l,j=m+1;
while(i<=j && j<=h){ //i<j alway true therfore all second half will be copied "<="

if(aux[i]<temp[j] && i<=m) //i<=m (because i=m first half ends
temp[k++] = aux[i++];
else
temp[k++] = temp[j++];
}

//copy remaining first half if any
while(k<=h)
temp[k++] = aux[i++];
}
};

void main()
{
int ch,size;

cout<<"\nWhat is the size of the list?\n";
cin>>size;

Sorting<int> st(size);

cout<<"\nPlease insert list:\n";
st.inputList();

do{
cout<<"\nPlease select your choice:\
\n 1.apply insertion sort\
\n 2.apply selection sort\
\n 3.apply shell sort\
\n 4.apply quick sort\
\n 5.apply merge sort\
\n 6.display original list\
\n 7.input another list\n";
cin>>ch;

switch(ch){
case 1:
st.insertionSort();
break;
case 2:
st.selectionSort();
break;
case 3:
st.shellSort();
break;
case 4:
{
int * temp = st.getList();
st.quickSort(temp,0,size-1);
cout<<"After applying \"quick\" sort, the list become:\n";
for(int i=0;i<size;i++)
cout<<temp[i]<<" , ";
}
break;
case 5:
{
int * temp = st.getList();
st.mergeSort(temp,0,size-1);
cout<<"After applying \"merge\" sort, the list become:\n";
for(int i=0;i<size;i++)
cout<<temp[i]<<" , ";
}
break;
case 6: st.display();
break;
case 7:
cout<<"\nPlease insert list:\n";
st.inputList();
break;

}
}while(ch);
}

Coding Ascii

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

void main()
{
char hur[7];
for(int i=0;i<6;i++)
{
fflush(stdin);
printf("input huruf ke-%d: ",i+1);
scanf("%c",&hur[i]);
}

printf("sebelum sorting : \n");
for(int j=0;j<6;j++)
{
printf("%c\n",hur[j]);
}

getch();

printf("Setelah sorting\n");
for(int k=65;k<91;k++)
{
for(int l=0;l<6;l++)
{
if(hur[l]==(char)k)
{
printf("%c\n",hur[l]);
}
}
}
getch();
}

Kamis, 13 Januari 2011

Warning

buka dan bagikanlah link ini untuk memberkati sesama kita...

http://kamarsolusi.com/2011/01/10/lukisan-lukisan-dari-jurang-maut/