Sabtu, 29 Desember 2012
Tugas Akhir DDP "CLASS"
Label:
Tugas
#include <cstdlib>
#include <iostream>
#include <iomanip.h>
using namespace std;
class final{
public:
void volume_bola();
void volume_balok();
void volume_kubus();
void volume_tabung();
void perulangan();
void matrix();
private:
float r,volume;
int p,l,t;
int s;
};
void final::volume_bola(){
cout<<"volume bola "<<endl;
cout<<"masukkan jari jari :";
cin>>r;
volume=(4*3.14*r*r*r)/3;
cout<<"hasil volume bola :"<<volume<<endl;
}
void final::volume_balok(){
cout<<"volume balok "<<endl;
cout<<"masukkan panjang :";
cin>>p;
cout<<"masukkan lebar :";
cin>>l;
cout<<"masukkan tinggi :";
cin>>t;
volume=(p * l * t );
cout<<"hasil volume balok :"<<volume<<endl;
}
void final::volume_kubus(){
cout<<"volume kubus "<<endl;
cout<<"masukkan sisi :";
cin>>s;
volume=s*s*s;
cout<<"hasil volume kubus :"<<volume<<endl;
}
void final::volume_tabung(){
cout<<"volume tabung "<<endl;
cout<<"masukkan jari jari :";
cin>>r;
cout<<"masukkan tinggi :";
cin>>t;
volume=3.14*r*r*t;
cout<<"hasil volume tabung :"<<volume<<endl;
}
void final::perulangan(){
int x,y;//program ini menggunakan inputan user
cout<<"Menentukan bilangan genap dan ganjil "<<endl;
cout<<"masukan batas awal : ";
cin>>x;
cout<<"masukan batas akhir : ";
cin>>y;
cout<<"bilangan genap adalah = ";
for(int i=x;i<=y;i++){
if(i%2==0){
cout<<i<<" ";
}
}
cout<<endl;
cout<<"bilangan ganjil adalah = ";
for(int i=x;i<=y;i++){
if(i%2==1){
cout<<i<<" ";
}
}
cout<<endl;
}
void final::matrix(){
int i, j, k, baris, kolom, m1[10][10];
cout<<"Jumlah Baris : "; cin>>baris;
cout<<"Jumlah Kolom : "; cin>>kolom;
cout<<"\nMatriks A "<<endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++){
cout<<"data["<<i<<", "<<j<<"] = ";
cin>>m1[i][j];
}
cout<<"\nMatriks A "<<endl;
for(i=0;i<baris;i++)
{for(j=0;j<kolom;j++)
cout<<setw(4)<<m1[i][j]<<" ";
cout<<endl;
}
cout<<"\nHasilnya... "<<endl;
cout<<"Matriks A transpose \n";
for(j=0;j<kolom;j++) {
for(i=0;i<baris;i++)
cout<<setw(4)<<m1[i][j];
cout<<endl;
}
}
void pilihan(){
cout<<"\t1.menghitung jumlah volume : \n";
cout<<"\t\t- bola\n";
cout<<"\t\t- balok \n";
cout<<"\t\t- kubus \n";
cout<<"\t\t- tabung \n";
cout<<"\t2.menentukan bilangan ganjil dan genap : \n";
cout<<"\t3.transpose matriks : \n";
}
int main(int argc, char *argv[])
{
final project;//project adalah objek
int x;
pilihan();
cout<<"masukan pilihan : ";
cin>>x;
switch(x){
case 1 :system("CLS");
cout<<"\t\t1. bola\n";
cout<<"\t\t2. balok \n";
cout<<"\t\t3. kubus \n";
cout<<"\t\t4. tabung \n";
cout<<"masukan pilihan : ";
cin>>x;
if (x==1){system("CLS");
project.volume_bola();}
else if(x==2){system("CLS");
project.volume_balok();}
else if(x==3){system("CLS");
project.volume_kubus();}
else if(x==4){system("CLS");
project.volume_tabung();}
break;
case 2 : system("CLS");
project.perulangan();
break;
case 3 : system("CLS");
project.matrix();
break;
}
system("PAUSE");
return EXIT_SUCCESS;
}
0 komentar
Posting Komentar