Minggu, 04 Desember 2011

Tugas struktur data stack(kelompok)

0 komentar
source code c++:
#include <string>
#include <iostream>


using namespace std;
class stak{
 public:
        stak();
        void baru();
        void bagi1();
        void bagi2();
        void cetak1();
        void cetak_hasil();
 private:
        int top;
        char stackA[9];
        char stackC[9];
        char stackB[9];
        char x;};

stak::stak(){
        top=-1;
        cout<<"Tugas Kelompok Stack\n\n";}

void stak::baru(){
        cout<<"Stack A\n";
        for (int i=0; i<6; i++){
        cout<<"Masukkan stack ["<<i+1<<"] : ";
        cin>>x;
        top++;
        stackA[top]=x;}}

void stak::bagi2(){
     cout<<"\nKarakter yang di pop";
     cout<<"\nStack B\n";
     int i=0;
     for(i=2;i>=0;i--){
     x=stackA[i];
     stackB[i+1]=x;
     cout<<"stack ke ["<<i+1<<"] : "<< x<<endl;}}
    
void stak::bagi1(){
     cout<<"\nKarakter yang di pop";
     cout<<"\nStack C\n";
     int i=0;
     for(i=top;i>=3;i--){
     x=stackA[i];
     stackC[i-2]=x;
     cout<<"stack ke ["<<i-2<<"] : "<< x<<endl;}}

void stak::cetak1(){
        int i=0;
        for (i= top; i>=0; i--)
        cout<<"stack ke ["<<i+1<<"] : "<<stackA[i]<<endl;}

void stak::cetak_hasil(){
     cout<<"\nHasil pembagian stack";
     cout<<"\n\tStack B\n";
        int i=0;
        for (i= 3; i>=1; i--){
        cout<<"stackB ke ["<<i<<"] : "<<stackB[i]<<endl;}
        cout<<"\n\tStack C\n";
        int j=0;
        for (j= 3; j>=1; j--){
        cout<<"stackC ke ["<<j<<"] : "<<stackC[j]<<endl;}}
       
int main (){
        int input;
        stak a;
        a.baru();
        //a.cetak1();
        a.bagi1();
        a.bagi2();
        a.cetak_hasil();
         system("PAUSE");
         return EXIT_SUCCESS;}

hasil:

Leave a Reply

Labels