1.dengan fungsi
#include <iostream>
using namespace std;
void tukar (int *k, int *l)
{ int temp;
temp = *k;
*k = *l;
*l = temp;
}
main() {
int k = 200, l = 80;
cout << "Sebelum Tukar\n";
cout << "Isi Nilai1 = " << k << endl;
cout << "Isi Nilai2 = " << k << endl;
tukar (&k,&l);
cout << "Sesudah Tukar\n";
cout << "Isi Nilai1 = " << k << endl;
cout << "Isi Nilai2 = " << l << endl;
return 0;
}
2.dengan class
#include <iostream>
using namespace std;
class data {
private :
int k, l;
public :
data();
void tukar();
void cetak();
};
data::data()
{
cout<<"---Menukar nilai isi variable-----"<<endl;
k = 200; l = 80;
}
void data::tukar()
{ int temp;
temp = k;
k = l;
l = temp;
}
void data::cetak()
{
cout << "Isi Nilai1 = " << k << endl;
cout << "Isi Nilai2 = " << l << endl;
}
main() {
data angka;
cout << "Sebelum Tukar\n";
angka.cetak();
angka.tukar ();
cout << "Sesudah Tukar\n";
angka.cetak();
return 0;
}
menggunakan raptor menentukan fungsi dan class
1. raptor fungsi
2.class
Tidak ada komentar:
Posting Komentar