Contoh program console dengan c++

sobat blogger kali ini saya ingin membagikan contoh program yang sempat saya buat dengan menggunakan c++ builder. program ini berfungsi untuk menghitung beberapa masalah matematika menggunakan rumus dasar, berikut source codenya :


//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
/*PROGRAM PENGHITUNGAN DALAM MATEMATIKA*/
#pragma argsused
#include<iostream.h>
#include<conio.h>
void main()
{
textbackground(BLUE);
char pil1,pil2,pil3,pil4,pil5,pil6,pil7,pil8,pil9,pil10,pil11,pil12,pil13,p1,p2,q;
double s,p,l,L,K,V,LP,r,a,t,c,t2;
q='Y';
do
{
clrscr();
cout<<"MOHON MAAF APABILA DALAM PROGRAM INI MEMILIKI KEKURANGAN\n\n";
cout<<"a. bangun datar\n";
cout<<"b. bangun ruang\n";
cout<<"masukkan pilihanmu?:";cin>>pil1;
switch (pil1)
{
case 'a':{
         cout<<"a. persegi\n";
         cout<<"b. persegi panjang\n";
         cout<<"c. lingkaran\n";
         cout<<"d. segitiga\n";
         cout<<"pilihanmu?:";cin>>pil2;
         switch (pil2)
         {
         case 'a':{
                  cout<<"a. Luas persegi\n";
                  cout<<"b. keliling persegi\n";
                  cout<<"pilihanmu?:";cin>>pil4;
                  switch (pil4)
                  {
                  case 'a':{
                           cout<<"masukkan sisi:";cin>>s;
                           L=s*s;
                           cout<<"luasnya adalah:"<<L<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan sisi:";cin>>s;
                           K=s*4;
                           cout<<"kelilingnya adalah:"<<K<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'b':{
                  cout<<"a. luas persegi panjang\n";
                  cout<<"b. keliling persegi panjang\n";
                  cout<<"pilihanmu?:";cin>>pil5;
                  switch (pil5)
                  {
                  case 'a':{
                           cout<<"masukkan panjang:";cin>>p;
                           cout<<"masukkan lebar:";cin>>l;
                           L=p*l;
                           cout<<"luasnya adalah:"<<L<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan panjang:";cin>>p;
                           cout<<"masukkan lebar:";cin>>l;
                           K=2*p+l;
                           cout<<"kelilingnya adalah:"<<K<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'c':{
                  cout<<"a. luas lingkaran\n";
                  cout<<"b. keliling lingkaran\n";
                  cout<<"pilihanmu?:";cin>>pil6;
                  switch (pil6)
                  {
                  case 'a':{
                           cout<<"masukkan jari-jari:";cin>>r;
                           L=3.14*r*r;
                           cout<<"luasnya adalah:"<<L<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan jari-jari:";cin>>r;
                           K=3.14*2*r;
                           cout<<"kelilingnya adalah:"<<K<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'd':{
                  cout<<"a. luas segitiga\n";
                  cout<<"b. keliling segitiga\n";
                  cout<<"pilihanmu?:";cin>>pil7;
                  switch(pil7)
                  {
                  case 'a':{
                           cout<<"masukkan alas:";cin>>a;
                           cout<<"masukkan tinggi:";cin>>t;
                           L=0.5*a*t;
                           cout<<"luasnya adalah:"<<L<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan a:";cin>>a;
                           cout<<"masukkan b:";cin>>t;
                           cout<<"masukkan c:";cin>>c;
                           K=a+t+c;
                           cout<<"kelilingnya adalah:"<<K<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         }
         getch();break;
         }
case 'b':{
         cout<<"a. kubus\n";
         cout<<"b. balok\n";
         cout<<"c. limas\n";
         cout<<"d. tabung\n";
         cout<<"pilihanmu?:";cin>>pil3;
         switch (pil3)
         {
         case 'a':{
                  cout<<"a. volume kubus\n";
                  cout<<"b. luas permukaan\n";
                  cout<<"pilihanmu?:";cin>>pil8;
                  switch (pil8)
                  {
                  case 'a':{
                           cout<<"masukkan sisi:";cin>>s;
                           V=s*s*s;
                           cout<<"volumenya adalah:"<<V<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan sisi:";cin>>s;
                           LP=s*s*6;
                           cout<<"luas permukaannya adalah:"<<LP<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'b':{
                  cout<<"a. volume balok\n";
                  cout<<"b. luas permukaan\n";
                  cout<<"pilihanmu?:";cin>>pil9;
                  switch (pil9)
                  {
                  case 'a':{
                           cout<<"masukkan panjang:";cin>>p;
                           cout<<"masukkan lebar:";cin>>l;
                           cout<<"masukkan tinggi:";cin>>t;
                           V=p*l*t;
                           cout<<"volumenya adalah:"<<V<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkan panjang:";cin>>p;
                           cout<<"masukkan lebar:";cin>>l;
                           cout<<"masukkan tinggi:";cin>>t;
                           LP=(p*l)+(p*t)+(t*l);
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'c':{
                  cout<<"a. limas segitiga\n";
                  cout<<"b. limas segiempat\n";
                  cout<<"masukkan pilihanmu:";cin>>pil10;
                  switch(pil10)
                  {
                  case 'a':{
                           cout<<"a. volume\n";
                           cout<<"pilihanmu?:";cin>>p1;
                           switch (p1)
                           {
                           case 'a':{
                                    cout<<"masukkan alas:";cin>>a;
                                    cout<<"masukkan tinggi segitiga:";cin>>t;
                                    cout<<"masukkan tinggi limas:";cin>>t2;
                                    V=1/3*a*t*0.5*t2;
                                    cout<<"volumenya adalah:"<<V<<endl;
                                    getch();break;
                                    }
                           }
                           getch();break;
                           }
                  case 'b':{
                           cout<<"a. volume\n";
                           cout<<"pilihanmu?:";cin>>p2;
                           switch (p2)
                           {
                           case 'a':{
                                    cout<<"masukkan panjang:";cin>>p;
                                    cout<<"masukkan lebar:";cin>>l;
                                    cout<<"masukkan tinggi:";cin>>t2;
                                    V=p*l*t2*1/3;
                                    cout<<"volumenya adalah:"<<V<<endl;
                                    getch();break;
                                    }
                           }
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         case 'd':{
                  cout<<"a. volume tabung\n";
                  cout<<"b. luas permukaan\n";
                  cout<<"pilihanmu?:";cin>>pil11;
                  switch (pil11)
                  {
                  case 'a':{
                           cout<<"masukkan jari-jari:";cin>>r;
                           cout<<"masukkan tinggi:";cin>>t;
                           V=3.14*t*r*r;
                           cout<<"volumenya adalah:"<<V<<endl;
                           getch();break;
                           }
                  case 'b':{
                           cout<<"masukkanjari-jari:";cin>>r;
                           cout<<"masukkan tinggi:";cin>>t;
                           LP=(3.14*r*r*2)+(2*3.14*r*t);
                           cout<<"luas permukaan tabung adalah:"<<LP<<endl;
                           getch();break;
                           }
                  }
                  getch();break;
                  }
         }
         getch();break;
         }
}
cout<<"apakah akan mengulang?(Y/N):";cin>>q;
}while (q=='Y');
getch();
}


demikian semoga membantu.
Previous
Next Post »