Pembahasan Struct memang agak panjang dan melelahkan , tapi ini demi kalian kalian semua para programmer newbie . ok BIntara akan sedikit menambah dari yang part 4
1. Program 1
#include <iostream.h>
#include <conio.h>
struct kompleks
{ float real,imajiner;}
bil;
int perkalian (float r1, float i1, float r2, float i2)
{bil.real = r1 * r2;
bil.imajiner = i1 * i2;
}
int tambah(float r1, float i1, float r2, float i2)
{bil.real = r1 + r2;
bil.imajiner = i1 + i2;
}
int kurangi(float r1, float i1, float r2, float i2)
{bil.real = r1 - r2;
bil.imajiner = i1 - i2;
}
char a,garis(),samadengan();
int main()
{
float n_r1, n_r2, n_i1, n_i2;
cout<<"[___PROGRAM BILANGAN KOMPLEKS___]\n\n";
cout<<"Bilangan Kompleks I" << endl;
cout<<"Masukkan Nilai Real : ";
cin>>n_r1;
cout<<"Masukkan Nilai Imajiner : ";
cin>>n_i1;
cout<<"\nBilangan Kompleks II" << endl;
cout<<"Masukkan Nilai Real : ";
cin>>n_r2;
cout<<"Masukkan Nilai Imajiner : ";
cin>>n_i2;
cout<<endl;
samadengan();cout<<endl<<endl;
tambah(n_r1,n_i1,n_r2,n_i2);
cout<<"Hasil Penjumlahan\n";
garis();cout<<endl;
cout<<"( "<<n_r1<<" + "<<n_i1<<"i )"<<" + ";
cout<<"( "<<n_r2<<" + "<<n_i2<<"i )"<<" = ";
cout<<bil.real<<" + ";
cout<<bil.imajiner<<"i"<<endl<<endl;
kurangi(n_r1,n_i1,n_r2,n_i2);
cout<<"Hasil Pengurangan\n";
garis();cout<<endl;
cout<<"( "<<n_r1<<" + "<<n_i1<<"i )"<<" - ";
cout<<"( "<<n_r2<<" + "<<n_i2<<"i )"<<" = ";
cout<<bil.real<<" + "<<bil.imajiner<<"i"<<endl<<endl;
perkalian(n_r1,n_i1,n_r2,n_i2);
cout<<"Hasil Perkaliannya\n";
garis();cout<<endl;
cout<<"( "<<n_r1<<" + "<<n_i1<<"i )"<<" * ";
cout<<"( "<<n_r2<<" + "<<n_i2<<"i )"<<" = ";
cout<< bil.real <<" * ";
cout<<bil.imajiner << 'i' <<"\n\n";
samadengan();cout<<endl;
getch();
}
char garis()
{
for (a=1;a<=40;a++){cout<<"-";}
}
char samadengan()
{
for (a=1;a<=40;a++){cout<<"=";}
}
Hasil Program
Akhirnya Pembahasan struct selesai juga. semoga bermanfaat . salam sukses BIntara . .
Related Post:
Title
:
Pemrograman Menggunakan C++ Struct Part 5
Description
:
Pemrograman Menggunakan C++ Struct Part 5 Pembahasan Struct memang agak panjang dan melelahkan , tapi ini demi kalian kalian semua para pr...