Laman

Powered By Blogger

Jumat, 28 Desember 2012

SISTEM TOKO HANDPHONE

Definisi Program

Kami membuat sebuah aplikasi ini bertujuan memanejemen data base pada suatu toko hape dan aplikasi ini juga bertujuan agar para customer bisa melakukan transaksi pembelian, penjualan, mengetahui informasi data hape dan mengetahui laporan penjualan.
Disini kami memberi inputan seperti kode, harga, merk, tipe hape agar customer bisa memilih sesuai dengan keinginannya.
Berikut spesifikasinya:
Menu utama
                      1.  Pembelian
          i. Inputan kode hape
         ii. Inputan tipe hape
        iii.  Inputan merk hape
        iv.   Inputan kondisi hape
         v.   Harga pembelian
         vi.  Jumlah pembelian
    2. Penjualan
         i.    Inputan kode tipe hape yang dipilih konsumen
         ii.   Inputan jumlah penjualan (jumlah tidak melebihi stok sbelum penjualan)
         iii.  Nota penjualan (total dari harga keseluruhan customer membeli barang)
                      3.      Data hape
                      Menampilkan data hape berisi kode, tipe, merk, kondisi, harga dan stok hape.
                      4.      Laporan penjualan
                      Berisi seluruh laporan dari penjualan beserta laba secara menyeluruh
                      5.      Hapus hape
                      Berisi tentang penghapusan dari tipe hape yang diinputkan
                      6.      Hapus data base
                      Berisi tentang penghapusan data dari keseluruhan yang diinputkan
                      7.      Keluar.
   
    Keunggulan program ini
        
        Program informasi toko Hape memudahkan pengunjung dalam mencari info tentang hape.
         Program dibuat dengan database. Sehingga data saran, kritik & nama pengunjung    yang mengisinya dapat tersimpan dalam database.



Selasa, 25 Desember 2012

Queue dengan java

Queue.java

class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//————————————————————–
public Queue(int s)          // konstruktor
{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
//————————————————————–
public void insert(long j)   // letakkan item (data) di posisi belakang dari queue
{
if(rear == maxSize-1)         //
rear = -1;
queArray[++rear] = j;         //naikkan rear dan masukkan item (data) pada posisi rear yang baru
nItems++;                     //tambah satu item lagi
}

//————————————————————–
public long remove()         // hapus item (data) yang berada pada posisi front
{
long temp = queArray[front++]; //dapatkan nilainya dan naikkan front
if(front == maxSize)           //
front = 0;
nItems–;                      // item (data) berkurang satu
return temp;
}
//————————————————————–
public long peekFront()      //
{

return queArray[front];
}
//————————————————————–
public boolean isEmpty()    //benar jika queue-nya kosong
{
return (nItems==0);
}
//————————————————————–
public boolean isFull()     // benar jika queue-nya penuh
{
return (nItems==maxSize);
}
//————————————————————–
public int size()           // jumlah ietm (data) dalam queue
{
return nItems;
}
//————————————————————–
}  // end class Queue

QueueApp.java

class QueueApp
{
public static void main(String[] args)
{
Queue theQueue = new Queue(5);  // queue menampung 5 item (data)
theQueue.insert(10);            // masukkan 4 item (data)
theQueue.insert(20);
theQueue.insert(30);
theQueue.insert(40);
theQueue.remove();              // hapus 3 item (data)
theQueue.remove();              //    (10, 20, 30)
theQueue.remove();
theQueue.insert(50);            // masukkan 4 item (data) lagi
theQueue.insert(60);            //    (wraps around)
theQueue.insert(70);
theQueue.insert(80);
while( !theQueue.isEmpty() )    // hapus dan tampilkan
{                            //    all items

long n = theQueue.remove();  // (
System.out.print(n);
System.out.print(“ “);
}
System.out.println(“”);

}  

antrian prioritas (priority queue)

priority queue or a antrian prioritas, where each element of higher value will go and queue in front of the smaller, in the lab, I was asked to menginputkan queue manually, and not consecutively. after which the program will automatically sort the corresponding value of the character in the enqueue. This is similar to the way sorting. ie comparing the elements of the new entrance to the front element, if the element has a value greater then the element will be shifted left fence to meet a higher value.

#include <cstdlib>
#include <iostream>
#define maks 5

using namespace std;

class Queue{
friend ostream& operator<<(ostream&, const Queue&);
public :
Queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue();
char dequeue();

private :
char A[maks];
int banyak;
char x;
};

ostream& operator<<(ostream& out, const Queue& s){
cout<<”\nIsi Quueue sebanyak : “<<s.banyak<<” yaitu : “;
for(int i=0;i<s.banyak;i++)
out<<s.A[i]<<” “;
return out;
}

Queue::Queue(){
banyak=0;
for(int i=0;i<maks;i++)
A[i]=’0′;
}

int Queue::penuh(int s){
return s==maks?1:0;
}

int Queue::kosong(int s){
return s==0?1:0;
}

void Queue::cetak(){
cout<<”\nIsi Queue : “;
for(int i=0;i<banyak;i++)
cout<<A[i]<<” “;
}

void Queue::enqueue(){
cin>>x;
cout<<”Elemen :”<<x<<” masuk antrian”;
if(penuh(banyak))cout<<”queue penuh “;
else if(A[0]==’0′){
A[0]=x;
banyak++;
}
else{
int tempat=0;
while(A[tempat]>x)tempat++;
if(banyak!=tempat)
for(int i=banyak;i>=tempat;i–)
A[i+1] = A[i];
A[tempat]=x;
banyak++;
}
}

char Queue::dequeue(){
char temp=A[--banyak];
cout<<”\nDequeue elemen –> “<<temp;
A[banyak]=’0′;
return temp;
}

int main(int argc, char *argv[])
{
Queue p;
for(int i=1;i<=5;i++){
cout<<”masukan elemnt :”;p.enqueue();
cout<<endl;
}
cout<<p;

for(int i=1;i<=5;i++){
p.dequeue();cout<<p;
if(i==5) cout<<”\n\n\n element kosong”;
cout<<endl;
}
system(“PAUSE”);
return EXIT_SUCCESS;
}


Queue (antrian)

Queue (queue) is a data structure where data is first put the data first be removed. Or it could be called a data structure that uses the mechanism of FIFO (First In First Out).
queue

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

#define maks 5

class Queue{
friend ostream& operator<<(ostream&, const Queue&);

public :
Queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue(char);
char dequeue();
private:
char A[maks];
int banyak;
};
ostream& operator<<(ostream& out, const Queue& s){
cout<<”\nIsi Queue : “;
for(int i;i<s.banyak;i++)
out<<s.A[i]<<” “;
return out;}

Queue::Queue(){
banyak=0;
for(int i=0;i<maks;i++)
A[i]=’0′;
}

int Queue::penuh(int s){
return s==maks?1:0;
}

int Queue::kosong(int s){
return s==0?1:0;
}

void Queue::cetak(){
cout<<”\nIsi Queue : “;
for(int i=0;i<banyak;i++)
cout<<A[i]<<” “;
}

void Queue::enqueue( char x){
cout<<”\nElemen “<<x<<” masuk antrian “;
if(penuh(banyak)) cout<<”Queue penuh”;
else if(A[0]==’0′){
A[0]=x;
banyak++;}
else {
for (int i=banyak;i>=0;i–)
A[i+1]=A[i];
A[0]=x;
banyak++;
}
}

char Queue::dequeue(){
char temp=A[--banyak];
cout<<”\nDequeue elemen –> “<<temp;
A[banyak]=’0′;
return temp;
}

main(){
Queue q;
for(char c=’a';c<’d';c++){
q.enqueue(c);
}
q.cetak();
char p=q.dequeue();
q.cetak();
cout<<”\n\nCetak pakai overloading “<<q;
getch();
return 0;

}

Stack atau Tumpukan (stack or the heap)

stack or the heap, this time the task qw just make a check brackets. if the character is a parenthesis then 1 character will be inserted into the stack and remove the parentheses when you meet the character to the stack, so that we can know whether parentheses akhrir we balanced input. Caran do it easily, eg given manually via a keyboard character is (a + (b / c)) we only use the selection, or if. when character = brackets -> no input characters into the stack and show character. or in c + + can be shown if (chart == '(') push (kar) and when the meet mark parentheses -> no characters pop from the stack: if (chart == ')') pop (kar), if it does not meet the second the character then go directly to the next character. Please try.


#include <except.h>
#include <new.h>

// bad initializers
class BadInitializers {
public:
BadInitializers() {}
};

// insufficient memory
class NoMem {
public:
NoMem() {}
};

// change new to throw NoMem instead of xalloc
void my_new_handler()
{
throw NoMem();
};

new_handler Old_Handler_ = set_new_handler(my_new_handler);

// improper array, find, insert, or delete index
// or deletion from empty structure
class OutOfBounds {
public:
OutOfBounds() {}
};

// use when operands should have matching size
class SizeMismatch {
public:
SizeMismatch() {}
};

// use when zero was expected
class MustBeZero {
public:
MustBeZero() {}
};

// use when zero was expected
class BadInput {
public:
BadInput() {}
};

#endif
// file stack.h
// formula-based stack

#ifndef Stack_
#define Stack_

template<class T>
class Stack {
// LIFO objects
public:
Stack(int MaxStackSize = 10);
~Stack() {delete [] stack;}
int IsEmpty() const {return top == -1;}
int IsFull() const {return top == MaxTop;}
T Top() const;
Stack<T>& Add(const T& x);
Stack<T>& Delete(T& x);
private:
int top;    // current top of stack
int MaxTop; // max value for top
T *stack;   // element array
};

template<class T>
Stack<T>::Stack(int MaxStackSize)
{// Stack constructor.
MaxTop = MaxStackSize – 1;
stack = new T[MaxStackSize];
top = -1;
}

template<class T>
T Stack<T>::Top() const
{// Return top element.
if (IsEmpty()) throw OutOfBounds(); // Top fails
else return stack[top];
}

template<class T>
Stack<T>& Stack<T>::Add(const T& x)
{// Add x to stack.
if (IsFull()) throw NoMem(); // add fails
stack[++top] = x;
return *this;
}

template<class T>
Stack<T>& Stack<T>::Delete(T& x)
{// Delete top element and put in x.
if (IsEmpty()) throw OutOfBounds(); // delete fails
x = stack[top--];
return *this;
}

#endif
// match parentheses

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

const int MaxLength = 100; // max expression length

void cek_tandakurung(char *expr)
{// Parenthesis matching.
Stack<int> s(MaxLength);
int j, length = strlen(expr);

// scan expression expr for ( and )
for (int i = 1; i <= length; i++) {
if (expr[i - 1] == ‘(‘) s.Add(i);
else if (expr[i - 1] == ‘)’)
try {s.Delete(j);  // unstack match
cout <<”(buka kurung at “<< j <<”)”<< ‘ ‘ <<”(tutup kurung at “<< i <<”)”<< endl;}
catch (OutOfBounds)
{cout << “tanda kurung kelebihan di no”
<< i << endl;}
}

// remaining ( in stack are unmatched
while (!s.IsEmpty()) {
s.Delete(j);
cout << “tanda kurung kelebihan di no “
<< j << endl;}
}

void main(void)
{
char expr[MaxLength];
cout << “masukan sembarang karekter yang mempunyai tanda kurung max (“
<< MaxLength <<”)”<< endl;
cin.getline(expr, MaxLength);
cout <<”karakter yang anda masukan adalah”
<< endl;
puts(expr);
cout<<endl;
cek_tandakurung(expr);
cout<<”\ntanda kurung seimbang “;
}

Array 1 Dimensi

Static array is an array of array [0] is shifted to the left then the element will be lost and the next element will be the first element, for the reason that, in panning slider either left or right, dilai array [0] if geserkiri or array [max] if geserkanan values ​​should be saved first, and newly allocated back to the first element and the last element.

#include <iostream.h>
#define maks 5

class Array1D{
friend ostream& operator<<(ostream&, const Array1D&);
friend istream& operator>>(istream&, Array1D&);
public :
Array1D();
void cetak();
void geser_kiri();
void geser_kanan();
private :
char A[maks];
};

Array1D::Array1D(){
for(int i=0;i<maks;i++)
A[i]=’0′;
}

void Array1D::cetak(){
for(int i=0;i<maks;i++)
cout<<A[i]<<” “;
}

ostream& operator<<(ostream& out, const Array1D& x){
for(int i=0;i<maks;i++)
cout<<x.A[i]<<” “;
cout<<endl;
return out;
}

istream& operator>>(istream& in, Array1D& x){
int posisi;
cout<<”Mengisi array pada posisi ke : “;
in>>posisi;
if(posisi>0&&posisi<=maks){
cout<<”Masukan elemen array-nya : “;
in>>x.A[posisi-1];
}
else
cout<<”Anda memasukan posisi diluar range….”;
return in;
}

void Array1D::geser_kanan(){
int n=maks;
int temp=A[n-1];
for(int i=n-1;i>=0;i–)
A[i+1]=A[i];
A[0]=temp;
}

void Array1D::geser_kiri(){
int n=maks;
int temp= A[0];
for(int i=0;i<n;i++)
A[i]=A[i+1];
A[n-1]=temp;
}

int main(){
Array1D x;
cout<<”Array masih kosong : “<<x;
cin>>x;
cout<<”isi array saat ini : “<<x;
x.geser_kiri();
cout<<”isi array setelah digeser kekiri :”<<x;
x.geser_kanan();
cout<<”isi array setelah digeser kekanan :”<<x;
return 0;
}

inheritance or inheritance

inheritance or inheritance, a class can have kids classes. and properties owned or inherited by the father of her children, which is in the public and protected, private parts can only be used by classes that have it.

class Bil_float : public Bilangan {
friend istream& operator>>(istream&, Bil_float&);
friend ostream& operator<<(ostream&, const Bil_float&);
private :
float a;
public :
Bil_float(float x=0.0) : a(x){}
void banding_float(const Bil_float& y, const Bil_float& z){
if(y.a>z.a) cout<<y.a<<”:: y lebih besar dari “<<z.a<<”::z”;
else cout<<y.a<<”::y lebih kecil dari”<<z.a<<”::z”;
}
};

istream& operator>>(istream& in, Bil_float& masuk){
cout<<”masukan bilangan”; in>>masuk.a;
return in;
}

ostream& operator<<(ostream& out, const Bil_float& keluar){
out<<”tampilkan bilangan”<<keluar.a;
return out;
}