Senin, 14 Februari 2011
Program Complex Number
Ini program aku buat setelah kelas OOP , buat agan-agan yang mau copy silahkan...
berikut Programnya....
<<<<<<<<<<++++++++++>>>>>>>>>>
#include "conio.h"
#include "iostream.h"
class Complex{
private:
int real;
int imaginary;
public:
Complex(){
cout<<"Masukan nilai Complex"<<endl;
cout<<"Real Part:";
cin>>real;
cout<<"Imaginary Part:";
cin>>imaginary;
}
void tampil(){
cout<<this->real;
if(this->imaginary!=0){
if(this->imaginary>0){
cout<<"+";
}
cout<<this->imaginary<<"i"<<endl;
}
}
void addComplex(Complex z){
this->real+=z.real;
this->imaginary+=z.imaginary;
}
void multiplyComplex(Complex z){
int x=this->real;
int y=this->imaginary;
this->real=(x*z.real)+((y*z.imaginary)*-1);
this->imaginary=(x*z.imaginary)+(y*z.real);
}
void subtractComplex(Complex z){
this->real-=z.real;
this->imaginary-=z.imaginary;
}
};
void main(){
int pilihan;
cout<<"Menu"<<endl;
cout<<"----------------"<<endl;
cout<<"1.Penjumlahan 2 Complex Number"<<endl;
cout<<"2.Pengurangan 2 Complex Number"<<endl;
cout<<"3.Perkalian 2 Complex Number"<<endl;
cout<<"Masukan pilahan anda : ";
cin>>pilihan;
Complex var1;
Complex var2;
if(pilihan>=1&&pilihan<=3){
if(pilihan==1){
var1.addComplex(var2);
}else
if(pilihan==2){
var1.multiplyComplex(var2);
}else
if(pilihan==3){
var1.subtractComplex(var2);
}
var1.tampil();
}else{
cout<<"Anda salah memasukan pilihan!!!"<<endl;
}
getch();
}
<<<<<<<<<<++++++++++>>>>>>>>>>
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar