Selasa, 21 Juni 2011

Counting the roots of quadratic equation using the function class

class in c + + function to categorize the variables, class is almost the same as the struct, the difference is the class name can be changed while in stuctr can not.



Counting the roots of quadratic equation programs use the function class

#include

#include

#include

class Persamaan{

public:

Persamaan();

void hitung();

private:

double a,b,c;

double diskriminan,x1,x2,re,im;

};

int main()

{

Persamaan x;

x.hitung();

getch();

return 0;

}

Persamaan::Persamaan(){

cout << "Persamaan Kuadrat" << endl;



cout << "a : ";



cin >> a;

cout << "b : ";



cin >> b;

cout << "c : ";



cin >> c;

}

void Persamaan::hitung (){

// hitung diskriminan

diskriminan=b*b-4*a*c;

if(diskriminan > 0)

{

x1 = (-b + sqrt(diskriminan))/(2*a);

x2 = (-b - sqrt(diskriminan))/(2*a);

cout << "Akar real : " << endl;



cout << "x1 : " << x1 << endl;



cout << "x2 : " << x2 << endl;



}

else

if(diskriminan ==0)

{

x1=-b/(2*a);

x2=x1;

cout << "Akar kembar : " << endl;



cout << "x1 : " << x1 << endl;



cout << "x2 : " << x2 << endl;



}

else //diskriminan <0



{

re= -b/(2*a);

im= sqrt(fabs(diskriminan))/(2*a);

cout << "Akar kompleks : " << endl;



cout << "x1 : " << re <<" + " << im << endl;



cout << "x2 : " << re <<" - " << im << endl;



}

}

Print the prime numbers between 1-100 by function overloading






function and operator overloading are the two most important things in C + + programming language.

mekipun unique function, this function is not much different from other types of functions.

In C + +, a function call is not only determined by the function name, but also
by type and number of actual parameters.

Facilities relating to existing functionality
other in C + + is a template function, operator function, inline function.



The following is a program of Printing prime numbers between 1-100 by function overloading





#include

#include

#include

#include


class prog

{

friend istream & operator >> ( istream &, prog & );

friend ostream & operator << ( ostream &, prog & );


public:

void id();

prog();

char nama[60];

private:

float m;

float c;

float energi;


};

void prog::id()

{

cout << "Nama Program : ";


cin.getline( nama, 60 );

cout << endl;


}

prog::prog()

{


}

ostream & operator << ( ostream & out, prog & y )


{


{

int i,j,k;

cout<<"bilangan 1-100"<

for (i=2;i<=100;i++){


for (j=2;j<=i/2;j++){


k=i%j;

if (k==0 )break;

}if(k!=0)

cout<

}

}

return out;

}

int main()

{ cout << "\t\t\t# C++ #\n\n";



char nama[90] =

{

"Cetak Bilangan Prima "

};

cout << "Nama Program :" << nama << endl;


cout << "\n";



prog a;

cout << a;


getch();

return 0;

}



Senin, 20 Juni 2011

Pointer


POINTER

Pointer is a variable that contains the memory address of a
other variables.

This address is the location of other objects (usually other variables) in
memory.

For example, if a variable contains the address of another variable, the first variable
said pointing to the second variable


Pointer operators there are two, namely:

 Operator &

& Operator is unary (requires only one operand only).

Operator & produces the address of the operandnya.

 Operator *

* Are unary operators (requires only one operand only).

Operator * value that is at an address.





pointer declaration

Tipe_data * nama_pointer;



sample program using C + + pointers

#include

#include


using namespace std;


int main(int argc, char *argv[])

{


class node {

public :

int data;

node*berikut;

};


void main(){

//langkah satu

node*baru;

baru=new node;

baru->data=5;

baru->berikut=NULL;

cout<<"Isi data node baru adalah : "<data<


//langkah dua

node*lain;

lain=new node;

lain->data=6;

lain->berikut=NULL;

cout<<"Isi data node lain adalah : "<data<


//langkah tiga : menyambung rantai

baru->berikut=lain;

cout<<"Isi data node lain dicetak dari node baru adalah :";




cout<berikut->data<


//langkah empat

node*kepala=baru;

cout<<"mencetak node pertama dari pointer kepala :";




cout<data<


cout<<"Mencetak node kedua dari pointer kepala :";




cout<berikut->data<


//langkah lima : pointer yang jalan-jalan

cout<<"Menggunakan perulangan untuk mencetak setiap data pada rantai\n";




node*jalan=kepala;

int i = 1;

while(jalan !=NULL){

cout<<"Data ke-"<"<data<


i++;

jalan=jalan->berikut;

}

//langkah enam : bukti bahwa pointer data tidak kehilangan kepala

cout<<"Mencetak node pertama dari pointer kepala : ";




cout<data<


cout<<"Mencetak node kedua dari pointer kepala : ";




cout<berikut->data<


}


system("PAUSE");

return EXIT_SUCCESS;

}


Calculator program in C + +




calculator C + +


calculator C + +







calculator was created using C + + programming language and is divided into 3 files. Next functions

are:

void kalkulator::perpangkatan (){

system("cls");

int pil;

cout<<"1.Pangkat 2\n2.Pangkat 3";


cout<<"\nMasukkan pilihan : ";


cin>>pil;

switch(pil){

case 1:

cout<<"\nmasukkan nilai x : ";


cin>>x;

cout<<"hasil perpangkatannya adalah = "<

case 2:

cout<<"\nmasukkan nilai x : ";


cin>>x;

cout<<"hasil perpangkatannya adalah = "<

}

}


void kalkulator::akar_kuadrat (){

cout<<"masukan nilai x = ";


cin>> x;

hitung=sqrt(x);

cout<<"hasilnya adalah = "<

}

void kalkulator::exponensial (){

cout<<"masukan nilai x = ";


cin>> x;

hitung=exp(x);

cout<<"hasilnya adalah = "<

}

void kalkulator::sinus (){

cout<<"Sin dari = ";


cin>> x;

float pi =3.14;

hitung = sin (x*pi/180);

cout<<"hasilnya adalah = "<

}

void kalkulator::cosinus (){

cout<<"Cos dari = ";


cin>> x;

float pi =3.14;

hitung = cos (x*pi/180);

cout<<"hasilnya adalah = "<

}

void kalkulator::tangen (){

cout<<"Tangen dari = ";


cin>> x;

float pi =3.14;

hitung = tan (x*pi/180);

cout<<"hasilnya adalah = "<

}


Minggu, 19 Juni 2011

ListOurExpend



ListOurExpend

ListOurExpend







Tugas Proyek ALGORITMA DAN PEMROGRAMAN

List Our Expend adalah program yang digunakan untuk mencatat pengeluaran sehari-hari.

TUgas Proyek ini kita buat menggunakan applikasi Android sehingga dapat diinstal atau digunakan pada mobile yang berbasic Android.

Klik Download