Tugas C++ 2

ini tugas ke 2 C++, huh habisna di protes ma temen, “tugasnya kurang nih, yang CONSTRUCTOR DAN DESTRUCTOR“. OK OK, q kerjakan. laen kali buat tmn2q yang mau nyontek tugas, bawakan kue dong!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! capek nih

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

class kalkulator
{ int *x, *y;
public :
int jml();
int kurang();
int kali();
float bagi();
kalkulator(int z, int q);
~kalkulator();
};

kalkulator::kalkulator(int z, int q)
{x=new int; y=new int;
*x=z;*y=q;}
int kalkulator::jml()
{ return(*x+*y);}
int kalkulator::kurang()
{ return(*x-*y);}
int kalkulator::kali()
{ return(*x**y);}
float kalkulator::bagi()
{ return(*x / *y);}
kalkulator::~kalkulator()
{ delete x;delete y;}
main()
{
kalkulator f(2,3);
kalkulator g(4,5);
kalkulator h(2,10);
kalkulator i(9,5);
cout<<“\nPenjumlahan = “<<f.jml();
cout<<“\nPengurangan = “<<g.kurang();
cout<<“\nPerkalian = “<<h.kali();
cout<<“\nPembagian = “<<i.bagi();
getch();
}

 

%d blogger menyukai ini: