b374k
v10
today : | at : | safemode : ON
> / home / facebook / twitter / youtube /
name author perms com modified label
Showing posts with label SDATA Task. Show all posts
Showing posts with label SDATA Task. Show all posts

Program stack dengan bahasa C pramana rwxr-xr-x 0 1:43 am

Filename Program stack dengan bahasa C
Permission rw-r--r--
Author pramana
Date and Time 1:43 am
Label
Action
Tampilan program :







Download program

Semoga bermanfaat guys !!!


Pengertian Stack pramana rwxr-xr-x 0 1:33 am

Filename Pengertian Stack
Permission rw-r--r--
Author pramana
Date and Time 1:33 am
Label
Action
Stack adalah suatu bentuk khusus dari linier list, dengan operasi penyisipan dan penghapusan dibatasi hanya pada satu sisinya, yaitu puncak stack (TOP).

Elemen teratas dari stack dinotasikan sebagai TOP(S).
Untuk stack S, dengan S = [S1, S2, S3, ..., ST] maka TOP(S) = ST

Jumlah elemen didalam stack kita notasikan dengan NOEL(S).
NOEL(S) menghasilkan nilai integer untuk stack S = [S1, S2, S3, ..., ST] maka            NOEL (S) = T.

Operator penyisipan (insertion) : PUSH
Operator penghapusan (deletion) : POP
Operasi stack : LIFO (Last In First Out), yaitu : yang terakhir masuk yang pertama keluar.

Double link list pramana rwxr-xr-x 0 3:04 am

Filename Double link list
Permission rw-r--r--
Author pramana
Date and Time 3:04 am
Label
Action
#include<stdio.h>
#include<conio.h>
#include<iostream>

using namespace std;
struct node{
       int data;
       struct node *prev,*next,*info;
       };
       typedef struct node node;
       node *head,*last,*temp,*t,*p,search,item;
       int d;
       void addhead();
       void addmiddle();
       void addtail();
       void delhead();
       void delmiddle();
       void deltail();
       int Search();
       void disp();


int main(){
            int ch;
            while(1){
                     printf("\n1. add to head ");
                     printf("\n2. add to Middle ");
                     printf("\n3. add to tail ");
                     printf("\n4. Delete from head ");
                     printf("\n5. Delete from Middle ");
                     printf("\n6. Delete from tail ");
                     printf("\n7.earch");
                     printf("\n8. Exit");
                     printf("\nEnter your Choice : ");
                     scanf("%d",&ch);
            switch(ch){
                       case 1:
                            addhead();
                            disp();
                            break;
                       case 2:
                            addmiddle();
                            disp();
                            break;
                       case 3:
                            addtail();
                            disp();
                            break;
                       case 4:
                            delhead();
                            disp();
break;
case 5:
delmiddle();
disp();
break;
case 6:
deltail();
disp();
break;
case 7:
Search();
disp();
break;
case 8:
exit(0);
default:
printf("\nInvalid Choice");
}
getch();
}
}

void addhead()
{
temp=(node*)malloc(sizeof(node));
printf("\nEneter the Data : ");
scanf("%d",&temp->data);
temp->next=temp->prev=NULL;
if(head==NULL)
head=temp;
else
{
temp->next=head;
head->prev=temp;
head=temp;
}
}


void addmiddle()
{
int d;
temp=(node*)malloc(sizeof(node));
printf("\nEneter the Data : ");
scanf("%d",&temp->data);
temp->next=temp->prev=NULL;
if(head==NULL)
head=temp;
else
{
t=head;
printf("\nEnter the node after which insertion to be made : ");
scanf("%d",&d);
while(t!=NULL)
{
if(t->data==d)
{
temp->next=t->next;
temp->prev=t;
t->next=temp;
return;}
else
t=t->next;
}
printf("\nadd node not found");
}
}
void addtail()
{
node *t;
temp=(node*)malloc(sizeof(node));
printf("\nEneter the Data : ");
scanf("%d",&temp->data);
temp->next=temp->prev=NULL;
if(head==NULL)
head=temp;
else
{
t=head;
while(t->next!=NULL)
t=t->next;
t->next=temp;
temp->prev=t;
}
}
void delhaed()
{
if(head==NULL)
printf("\nList is Empty");
else
{
t=head;
printf("\nDeleted node is %d\n",t->data);
head=head->next;
head->prev=NULL;
free(t);
}
}
void delmiddle()
{
int d;
node *s,*n;
if(head==NULL)
printf("\nList is Empty");
else
{
printf("\nEnter  the node data to be deleted : ");
scanf("%d",&d);
if(head->data==d)
{
t=head;
head=head->next;
head->prev=NULL;
printf("\nDeleted node is %d\n",t->data);
free(t);
}
else
{
t=head;
while(t->next!=NULL)
{
if(t->data==d){
s=t;
printf("\nDeleted node is %d\n",s->data);
p=t->prev;
n=t->next;
p->next=t->next;
n->prev=p;
free(s);
}
else
{
p=p->next;
t=t->next;
}
}
}
} }
void deltail()
{
if(head==NULL)
printf("\nList is Empty");
else if(head->next==NULL)
{
t=head;
printf("\nDeleted node is %d\n",t->data);
head=NULL;
}
else
{
t=head;
while(t->next!=NULL)
{
t=t->next;
}
p=t->prev;
p->next=NULL;
printf("\nDeleted node is %d\n",t->data);
free(t);
}
}
//search

int Search()
{
    while(head!=NULL)
    {
        if(head->info=item){ // if the values match,
            //return head; // return the matching node.
        head=head->next; }// otherwise, move on
    }
    system("pause");
    return 0;
}

Circular pramana rwxr-xr-x 0 4:06 pm

Filename Circular
Permission rw-r--r--
Author pramana
Date and Time 4:06 pm
Label
Action
#include <iostream>
#include <cstdlib>

using namespace std;
class circle
{
private:
    struct Node
    {
        Node* ulang;
        int nil;
        Node *lanjutan;
    };
    Node *pertama;
   
public :
   
    circle()
    {
        Node *t1 = new Node();
        t1->ulang = NULL;
        t1->nil = 3;
        t1->lanjutan = NULL;
       pertama = t1;
       
        Node *t2 = new Node();
        t2->ulang = t1;
        t2->nil = 13;
        t2->lanjutan = NULL;
        t1->lanjutan = t2;
       
        Node *t3 = new Node();
        t3->ulang = t2;
        t3->nil = 1;
        t3->lanjutan = NULL;
        t2->lanjutan = t3;
       
        Node *t4 = new Node();
        t4->ulang = t3;
        t4->nil = 33;
        t4->lanjutan = NULL;
        t3->lanjutan = t4;

        Node *t5 = new Node();
        t5->ulang = t4;
        t5->nil = 8;
        t5->lanjutan = NULL;
        t4->lanjutan = t5;

        Node *t6 = new Node();
        t6->ulang = t5;
        t6->nil = 133;
        t6->lanjutan = NULL;
        t5->lanjutan = t6;

        Node *t7 = new Node();
        t7->ulang = t6;
          t7->lanjutan = t1;
        t7->nil = 0;
        t7->lanjutan = NULL;
        t6->lanjutan = t7;
     

    }
   
    ~circle()
    {
        Node *temp =pertama, *current =pertama;
        while(current != NULL)
        {
            temp = current->lanjutan;
            delete current;
            current = temp;
        }
       
    }
   
    void Tampil()
    {
        Node *temp;
        for(temp =pertama; temp != NULL; temp = temp->lanjutan)
        {
            cout<<temp->nil<<" , ";
        }
        cout<<endl;
    }
   
   
    void Sort()
    {
        Node *current, *cur;

        for(current =pertama; current->lanjutan != NULL; current = current->lanjutan)
        {
            Node *minimum = current;
            for(cur = current ; cur != NULL; cur = cur->lanjutan)
            {
                if(minimum->nil > cur->nil)
                {
                    minimum = cur;
                }
            }
            if(minimum != current)
            {
                Node *current_lagi, *current_lanjutan, *min_ulang, *min_lanjutan;

                // Initialize them
                current_lanjutan = current->lanjutan;
                min_ulang = minimum->ulang;
                min_lanjutan = minimum->lanjutan;
                current_lagi = current->ulang;

                if(current_lagi == NULL)
                {
                    // Change thepertama Node
                   pertama = minimum;
                }
                if(current->lanjutan == minimum)
                {
                    // Nodes are Adjacent
                    minimum->ulang = current_lagi;
                    minimum->lanjutan = current;

                    current->ulang= minimum;
                    current->lanjutan = min_lanjutan;

                    if(min_lanjutan)
                    {
                        min_lanjutan->ulang= current;
                    }
                    if(current_lagi)
                    {
                        current_lagi->lanjutan = minimum;
                    }
                }
                else
                {
                    minimum->ulang = current_lagi;
                    minimum->lanjutan = current_lanjutan;

                    current->ulang = min_ulang;
                    current->lanjutan = min_lanjutan;

                    if(current_lanjutan)
                    {
                        current_lanjutan->ulang = minimum;
                    }
                    if(min_ulang)
                    {
                        min_ulang->lanjutan = current;
                    }
                    if(min_lanjutan)
                    {
                        min_lanjutan->ulang = current;
                    }
                    if(current_lagi)
                    {
                        current_lagi->lanjutan = minimum;
                    }
                }
                current = minimum;
            }
        }

    }
};

int main()
{
    circle list;
   
    cout<<"LinkList = ";
   
    list.Tampil();
   
    cout<<"\n\nSort circular likend list \n\n";
   
    list.Sort();
   
    cout<<"LinkList = ";
   
    list.Tampil();
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

Polinomial 2 pramana rwxr-xr-x 0 3:57 pm

Filename Polinomial 2
Permission rw-r--r--
Author pramana
Date and Time 3:57 pm
Label
Action
#include <cstdlib>
#include <iostream>
#include <conio.h>

#define MAX 10
using namespace std;
struct nomi
{
int coeff ;
int exp ;
} ;

struct poly
{
struct nomi t [10] ;
int noofterms ;
} ;


void initpoly ( struct poly * ) ;
void polyappend ( struct poly *, int c, int e ) ;
struct poly polyadd ( struct poly, struct poly ) ;
void display ( struct poly ) ;

int main( )
{
struct poly p1, p2, p3 ;

//clrscr( ) ;

initpoly ( &p1 ) ;
initpoly ( &p2 ) ;
initpoly ( &p3 ) ;

polyappend ( &p1, 1, 7 ) ;
polyappend ( &p1, 2, 6 ) ;
polyappend ( &p1, 3, 5 ) ;
polyappend ( &p1, 4, 4 ) ;
polyappend ( &p1, 5, 2 ) ;

polyappend ( &p2, 1, 4 ) ;
polyappend ( &p2, 1, 3 ) ;
polyappend ( &p2, 1, 2 ) ;
polyappend ( &p2, 1, 1 ) ;
polyappend ( &p2, 2, 0 ) ;

p3 = polyadd ( p1, p2 ) ;

cout<< ( "\nFirst polynomial:\n" ) ;
display(p1) ;

printf ( "\n\nSecond polynomial:\n" ) ;
display ( p2 ) ;

printf ( "\n\nResultant polynomial:\n" ) ;
display ( p3 ) ;

getch( ) ;
}

/* initializes elements of struct poly */
void initpoly ( struct poly *p )
{
int i ;
p -> noofterms = 0 ;
for ( i = 0 ; i < MAX ; i++ )
{
p -> t[i].coeff = 0 ;
p -> t[i].exp = 0 ;
}
}

/* adds the term of polynomial to the array t */
void polyappend ( struct poly *p, int c, int e )
{
p -> t[p -> noofterms].coeff = c ;
p -> t[p -> noofterms].exp = e ;
( p -> noofterms ) ++ ;
}

/* displays the polynomial equation */
void display ( struct poly p )
{
int flag = 0, i ;
for ( i = 0 ; i < p.noofterms ; i++ )
{
if ( p.t[i].exp != 0 )
printf ( "%d x^%d + ", p.t[i].coeff, p.t[i].exp ) ;
else
{
printf ( "%d", p.t[i].coeff ) ;
flag = 1 ;
}
}
if ( !flag )
printf ( "\b\b " ) ;

}

/* adds two polynomials p1 and p2 */
struct poly polyadd ( struct poly p1, struct poly p2 )
{
int i, j, c ;
struct poly p3 ;
initpoly ( &p3 ) ;

if ( p1.noofterms > p2.noofterms )
c = p1.noofterms ;
else
c = p2.noofterms ;

for ( i = 0, j = 0 ; i <= c ; p3.noofterms++ )
{
if ( p1.t[i].coeff == 0 && p2.t[j].coeff == 0 )
break ;
if ( p1.t[i].exp >= p2.t[j].exp )
{
if ( p1.t[i].exp == p2.t[j].exp )
{
p3.t[p3.noofterms].coeff = p1.t[i].coeff + p2.t[j].coeff ;
p3.t[p3.noofterms].exp = p1.t[i].exp ;
i++ ;
j++ ;
}
else
{
p3.t[p3.noofterms].coeff = p1.t[i].coeff ;
p3.t[p3.noofterms].exp = p1.t[i].exp ;
i++ ;
}
}
else
{
p3.t[p3.noofterms].coeff = p2.t[j].coeff ;
p3.t[p3.noofterms].exp = p2.t[j].exp ;
j++ ;
}
}
return p3 ;
}

Link list pramana rwxr-xr-x 0 8:38 am

Filename Link list
Permission rw-r--r--
Author pramana
Date and Time 8:38 am
Label
Action
#include <iostream>
#include <list>
#include <iterator>
#include <algorithm>
#include <conio.h>
using namespace std;

int main()
{
list<int> intList1, intList2, intList3, intList4;           

    ostream_iterator<int> screen(cout," ");     

    intList1.push_back(23);              
    intList1.push_back(58);           
    intList1.push_back(58);           
    intList1.push_back(58);           
    intList1.push_back(36);             
    intList1.push_back(15);              
    intList1.push_back(93);              
    intList1.push_back(98);              
    intList1.push_back(58);              

    cout<<"Line 12: intList1: ";              
    copy(intList1.begin(),intList1.end(),screen);
    cout<<endl;                      
    intList2 = intList1;                  

    cout<<"Line 16: intList2: ";             
    copy(intList2.begin(),intList2.end(),screen);
    cout<<endl;                      
    intList1.unique();                  



    cout<<"Line 20: After removing the consecutive "
           <<"duplicates,"<<endl
           <<"         intList1: ";              
    copy(intList1.begin(),intList1.end(),screen);
    cout<<endl;                      

    intList2.sort();                  

    cout<<"Line 24: After sorting, intList2: ";  //Line 24
    copy(intList2.begin(),intList2.end(),screen);//Line 25
    cout<<endl;                      
    intList3.push_back(13);              
    intList3.push_back(23);              
    intList3.push_back(25);              
    intList3.push_back(136);              
    intList3.push_back(198);              
   
    cout<<"Line 32: intList3: ";              
    copy(intList3.begin(),intList3.end(),screen);
    cout<<endl;                      

    intList4.push_back(-2);              
    intList4.push_back(-7);              
    intList4.push_back(-8);              
   
    cout<<"Line 38: intList4: ";              
    copy(intList4.begin(),intList4.end(),screen);
    cout<<endl;                      

    intList3.splice(intList3.begin(),intList4); 

    cout<<"Line 42: After moving the elements of "
            <<"intList4 into intList3,"<<endl
            <<"         intList3: ";              
    copy(intList3.begin(),intList3.end(),screen);
    cout<<endl;                      

    intList3.sort();                 

    cout<<"Line 46: After sorting, intList3: "; 
    copy(intList3.begin(),intList3.end(),screen);
    cout<<endl;                      

    intList2.merge(intList3);              

    cout<<"Line 50: After merging intList2 and intList3, "
            <<"intList2: "<<endl<<"         ";      
    copy(intList2.begin(),intList2.end(),screen);
    cout<<endl;                      

    intList2.unique();                  

    cout<<"Line 54: After removing the consecutive "
        <<"duplicates, intList2: "<<endl
       <<"         ";                  
    copy(intList2.begin(),intList2.end(),screen);
    cout<<endl;                      
getch();
    return 0;
}

Polinomial pramana rwxr-xr-x 0 8:36 am

Filename Polinomial
Permission rw-r--r--
Author pramana
Date and Time 8:36 am
Label
Action
#include <iostream.h>
#include <conio.h>

class poli{
friend ostream& operator << (ostream& , poli& );
friend istream& operator >> (istream& , poli& );
public:
poli();
void penjumlahan(const poli&, const poli&);
void nilai(int);
private:
int elemen[100];
int banyak;
};



poli::poli(){
for(int i=0;i<banyak;i++)
elemen[i];
}
istream& operator >> (istream& in, poli& a){
cout<<"banyak elemen : "; in>>a.banyak;
cout<<"masukkan data polinomial : \n";
for(int i=0;i<a.banyak;i++){
cout<<"variabel pangkat "<<i<<" :";
cin>>a.elemen[i];
}
return in;
}
void poli::nilai(int i){
banyak= i;
}
ostream& operator << (ostream& out, poli& a){

for(int i=(a.banyak-1); i>=0; i--){
        cout<<a.elemen[i];
        if(i!=0) cout<<"x^"<<i<<"+";
        }
cout<<endl;
return out;
}
void poli::penjumlahan(const poli& a, const poli& b){
if(a.banyak>b.banyak)banyak=a.banyak;
else banyak=b.banyak;
for(int i=0;i<banyak;i++){
if ((a.banyak-1)<i) elemen[i]=b.elemen[i];
else if ((b.banyak-1)<i) elemen[i]=a.elemen[i];
else elemen[i]=a.elemen[i]+b.elemen[i];
}
}

int main(){
poli x, y, z;
cin>>x;
cout<<x;
cin>> y;
cout<<y;
z.penjumlahan(x,y);
cout<<"\n\nhasil penjumlahan 2 polinomial\n"<<z<<endl;
getch();
return 0;
}

Presensi pramana rwxr-xr-x 0 8:32 am

Filename Presensi
Permission rw-r--r--
Author pramana
Date and Time 8:32 am
Label
Action
#include <cstdlib>
#include <iostream>

using namespace std;
//class Presensi
class Presensi{
public:
Presensi(){} //konstruktor
Presensi(string nama, string nim); //default konstruktor
void tambahPresensi(string nama, string nim); //method tambah presensi
void cetak(); //method untuk cetak presensi
private:
//struct Mahasiswa
struct Mahasiswa{
string Nama; // variabel Nama dengan tipe data string
string Nim; // variabel Nim dengan tipe data string
}
Mhs; //objek baru dari struct Mahasiswa dengan nama Mhs

};



Presensi::Presensi(string nama,string nim){
nama = "";
nim = "";
this->Mhs.Nama = nama; // assignment variabel nama ke Nama
this->Mhs.Nim = nim; // assignment variabel nim ke Nim
}

void Presensi::tambahPresensi(string nama, string nim){
this->Mhs.Nama = nama; // assignment variabel nama ke Nama
this->Mhs.Nim = nim; // assignment variabel nim ke Nim


}

void Presensi::cetak(){
cout<<Mhs.Nama<<" ( "<<Mhs.Nim<<" )"<<endl; // cetak presensi (Nama dan Nim)

}

int main(int argc, char *argv[])
{
Presensi x[2];
string a,b;

for(int i=0;i<2;i++){
cout<<"Masukkan Nama Anda  :";
cin>>a;
cout<<"Masukkan Nim Anda :";
cin>>b;

x[i].tambahPresensi(a,b);
}

for(int j=0;j<2;j++){

x[j].cetak();

}



system("pause");
return 0;
}

Menjumlahkan suatu deret pramana rwxr-xr-x 0 8:30 am

Filename Menjumlahkan suatu deret
Permission rw-r--r--
Author pramana
Date and Time 8:30 am
Label
Action
#include <iostream.h>
#include <conio.h>
class Deret {
friend istream& operator>>(istream&, Deret&);
friend ostream& operator<<(ostream&, Deret&);
public:
void cetak();
private:
int bil;
int i, k, sum;
};

void Deret::cetak() {
sum=0;
k=0;
for (i=1; k<=bil;i++){
if (k <= bil && (k+2)>=bil)
break;
k=(i*3)-2;
sum+=k;
cout << "Suku ke : " << i << " = " << sum << endl;
}
}


istream& operator>>(istream& input, Deret& x) {
cout << "Masukkan integer : ";
input >> x.bil;
return input;
}

ostream& operator<<(ostream& output, Deret& x) {
output << "Jumlah Deret : ";
x.k=0;
for (x.i=1; x.k<= x.bil; x.i++){
x.k=2*(x.i-1)+1;
if (x.k <= x.bil && (x.k+2)>=x.bil){
cout << x.k<< " adalah " << endl;
break;
}
else cout << x.k << " + ";
}
x.cetak();
return output;
}

int main() {
Deret Bilangan;
cin >> Bilangan;
cout << Bilangan << endl;
getch();
return 0;
}
 

Jayalah Indonesiaku © 2010 Pramana's BLOG
VB (Vio b374k) Template design by p4r46hcyb3rn3t