0% found this document useful (0 votes)
117 views4 pages

Materi 6 PBO (Contoh Program OOP Dengan C++)

This document provides an example program for object-oriented programming in C++. It defines a class called "bangunruang" (shape in Indonesian) that contains methods for calculating the area and volume of a cube, pyramid, and cone. The main function displays a menu allowing the user to select which shape to calculate, calls the corresponding method to get input values and display the results, and repeats the process until the user selects to exit.

Uploaded by

dedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views4 pages

Materi 6 PBO (Contoh Program OOP Dengan C++)

This document provides an example program for object-oriented programming in C++. It defines a class called "bangunruang" (shape in Indonesian) that contains methods for calculating the area and volume of a cube, pyramid, and cone. The main function displays a menu allowing the user to select which shape to calculate, calls the corresponding method to get input values and display the results, and repeats the process until the user selects to exit.

Uploaded by

dedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Contoh Program OOP ( Object Oriented Programming ) C++

berikut saya telah menyiapkan contoh program oop, silahkan kalian praktikkan menggunakan code blocks.

1. Program Mengitung Kubus

#include <stdio.h>

#include <iostream>

#include <windows.h>

using namespace std;

#define pi 3.14

class bangunruang

public :

double luas, volume, s, la, jst, ls, r, t;

void kubus ()

cout<<" Luas dan Volume Kubus "<<endl;

cout<<" --------------------- "<<endl;

cout<<"Input Sisi Kubus = ";cin>>s;

luas = 6 * s * s;

volume = s * s * s;

cout<<"Luas Kubus = "<<luas<<endl;

cout<<"Volume Kubus = "<<volume<<endl;

cout<<endl;

void limas ()

cout<<" Luas dan Volume Limas "<<endl;


cout<<" --------------------- "<<endl;

cout<<"Input Luas Alas = ";cin>>la;

cout<<"Input Jumlah Sisi Tegak = ";cin>>jst;

luas = la * jst;

volume = 0.33 * jst;

cout<<"Luas Limas = "<<luas<<endl;

cout<<"Volume Limas = "<<volume<<endl;

cout<<endl;

void kerucut ()

cout<<" Luas dan Volume Kerucut "<<endl;

cout<<" ----------------------- "<<endl;

cout<<"Input Luas Alas = ";cin>>la;

cout<<"Input Luas Selimut = ";cin>>ls;

cout<<"Input Jari-jari = ";cin>>r;

cout<<"Input Tinggi Kerucut = ";cin>>t;

luas = la * ls;

volume = 0.33 * pi * r * r * t;

cout<<"Luas Kerucut = "<<luas<<endl;

cout<<"Volume Kerucut = "<<volume<<endl;

cout<<endl;

};

int main()

int pilihan;

atas :

bangunruang x;
cout<<"================================================================================"<<e
ndl;

cout<<"\t\twww.syarifsoden.blogspot.com \t\t\t"<<endl;

cout<<"\t\tObject Oriented Programming ( OOP ) C++ \t\t\t"<<endl;

cout<<"================================================================================"<<e
ndl;

cout<<" Menu Pilihan "<<endl;

cout<<" 1. Luas dan Volume Kubus "<<endl;

cout<<" 2. Luas dan Volume Limas "<<endl;

cout<<" 3. Luas dan Volume Kerucut "<<endl;

cout<<" 4. Exit Program "<<endl;

cout<<endl;

cout<<" Input Nomor Menu Pilihan = ";cin>>pilihan;

cout<<endl;

switch (pilihan)

case 1 : x.kubus ();

goto atas;

break;

case 2 : x.limas ();

goto atas;

break;

case 3 : x.kerucut ();

goto atas;

break;

case 4 : exit:

cout<<" Anda Kembali ke Halaman Program "<<endl;

break;
default: cout <<"Anda Salah Input Pilihan"<<endl;

goto atas;

system ("pause");

return 0;

Hasil Program:

You might also like