Anda di halaman 1dari 1

MODUL 8

TEMPLATE FUNGSI DAN KELAS

SASARAN
1. Mengetahui kemampuan template dalam C++
2. Dapat menggunakan dan membuat template dalam C++

TUGAS PENDAHULUAN
1. Apa yang anda ketahui tentang template ?
2. Apa manfaat dari fungsi template ?

PRAKTIKUM

Contoh81.CPP
//*------------------------------------------------*
//* Contoh Fungsi Template *
//*------------------------------------------------*

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

template<class T>
void tukar(T &x, T &y)
{
T tmp;

tmp = x;
x = y;
y = tmp;
}
//akhir template

//prototype fungsi
void tukar(int &x, int &y);
void tukar(double &x, double &y);

void main()
{
clrscr();
double x=17.7777;
double y=15.5555;

cout << "x= " << x << " y = " << y << endl;
tukar(x,y);
cout << "x= " << x << " y = " << y << endl;

int a = 55;
int b = 77;
cout << "a= " << a << " b = " << b << endl;
tukar(a,b);
cout << "a= " << a << " b = " << b << endl;
}

30

Anda mungkin juga menyukai