Jumat, 08 Juli 2011

Class Konversi meter ke centimeter dan inchi


Sama seperti program-program sebelumnya yang telah saya posting, 
program ini juga dibuat menggunakan dalam bentuk class. . .
program ini bisa digunakan untuk mencari  Konversi meter ke centimeter dan inchi.


#include <iostream>
#include <conio>
class meter {
friend ostream& operator<<(ostream&,const meter&);
friend istream& operator>>(istream&,meter&);
public:
  meter(int a=0):m(a){}
  int cm() const;
  double inci() const;
private:
  int m;
};
ostream& operator<<(ostream& out,const meter& j){
  out << "Ukuran dalam cm     : " << j.cm();
  out << "\nUkuran dalam inci : " << j.inci();
  return out;
}
istream& operator>>(istream& in,meter& j){
  cout << "Masukkan jarak dalam meter : "; in >> j.m;
  return in;
}
int meter::cm()const{
   return (m*100);
}
double meter::inci()const{
   return (m*100/2.54);
}
void main(){
  meter j;
  cin >> j;
  cout << j;
  getch();
}




met mencoba ycc ^_^. . . .

Class detik


Sama seperti program-program sebelumnya yang telah saya posting, 
program ini juga dibuat menggunakan dalam bentuk class. . .

#include <iostream.h>
#include <conio.h>
class Detik {
            friend ostream& operator<<(ostream&,const Detik&);
            friend istream& operator>>(istream&, Detik&);
public:
            Detik(int j=0, int m=0, float d=0.0) : jam(j), menit(m), detik(d) { }
private:
   void fDetik();
   int jam;
   int menit;
   float detik;
};
void Detik::fDetik(){
            menit += (int)detik/60;
            jam += menit/60;
            menit %= 60;
            jam %= 24;
            detik = (int)detik % 60;
   if (detik<0) { detik+=60; menit--;}
   if (menit<0) { menit+=60; jam--;}
            if (jam<0) { jam+=24;}
}
ostream& operator<<(ostream& out, const Detik& w){
            out << w.jam << ":" << w.menit << ":" <<  w.detik;
            return out;
}
istream& operator>>(istream& in, Detik& w) {
   cout << "Masukkan detik \t: ";
   in >> w.detik;
   w.fDetik();
   return in;
}
void main(){
Detik a;
cout<<"Inisialisasi Waktu :"<<a <<endl;
cin>>a;
cout<<"Hasil Masukkan :"<<a<<endl;
getch();
}




met mencoba ycc ^_^ SEMIGA ANDA SUKSES OK

Class Celcius


Program ini dibuat menggunakan class untuk mencari celcius, se,oga bermanfaat bagi teman-teman. . . ^_^


#include <iostream.h>
#include <conio.h>
class Celcius {
friend ostream& operator<<(ostream&,const Celcius&);
friend istream& operator>>(istream&,Celcius&);
public:
  Celcius(double a=0):c(a){}
  double reamur() const;
  double fahrenheit() const;
  double kelvin() const;
private:
  double c;
};
ostream& operator<<(ostream& out,const Celcius& j){
  out << "Reamur     : " << j.reamur();
  out << "\nFahrenheit  : " << j.fahrenheit();
  out << "\nKelvin      : " << j.kelvin();
  return out;
}
istream& operator>>(istream& in,Celcius& j){
  cout << "Masukkan suhu dalam Celcius : "; in >> j.c;
  return in;
}
double Celcius::reamur()const{
   return (4/5.0*c);
}
double Celcius::fahrenheit()const{
   return (9/5.0*c+32);
}
double Celcius::kelvin()const{
   return (c+273);
}
void main(){
  Celcius j;
  cin >> j;
  cout << j;
  getch();
}



Met Mencoba. . .^_^

Class Cek Karakter huruf kecil atau besar


Program ini digunakan untuk mengecek apakah huruf itu hyryf besar atau huruf kecil. . .


Program:
#include <iostream.h>
#include <conio.h>
class Kecbesdig{
            friend ostream& operator<<(ostream& , const Kecbesdig&);
            friend istream& operator>>(istream& ,  Kecbesdig&);
public:
            Kecbesdig(){};
private:
            char a;
};
ostream& operator<<(ostream& out, const Kecbesdig& C) {
   if (((int)C.a>=65) && ((int)C.a<=90)) out << C.a<< " adalah Huruf Besar\n";
   if (((int)C.a>=97) && ((int)C.a<=122))out << C.a << " adalah Huruf kecil\n";
   if (((int)C.a>=48) && ((int)C.a<=57)) out << C.a << " adalah Angka\n";
   if (((int)C.a>=33) && ((int)C.a<=47)) out << C.a <<" adalah operator\n";
   return out;
}
istream& operator>>(istream& in,Kecbesdig& C){
cout<<"Masukkan sebuah karacter sembarang : ";in>>C.a;
return in;
}
int main (){
   Kecbesdig p;
   cout<<"Program ini menginisialisasi input yang dimasukkan oleh user\n"<<endl;
   cin>>p;
   cout<<p<<endl;
   getch();
   return 0;
}






Met Mencoba ycc Temen. . . .

Class Bola

 #include <iostream.h>
#include <math.h>
#include <conio.h>
class Bola {
            friend istream& operator>>(istream&, Bola&);
public:
            Bola (float a=0):r(a){};
            double isi();
private:
            float r;
};
istream& operator>>(istream& in, Bola& B){
            cout << "Masukkan Jari-jari : "; in >> B.r;
            return in;
}
double Bola::isi(){
            return (4/3.0*22/7.0*r*r*r);
}
void main(){
            Bola b;
            cout<<"Mencari isi bola jika r diketahui \t" <<endl;
            cin >> b;
            cout << "Isi Bola adalah " << b.isi();
   getch();
            return;
} Hasil Running >>>

Class bilangan


Program ini digunakan untuk mencari clasws bilangan. . . .
met mencoba yccc.............. ^_^

#include <iostream.h>
#include <conio.h>
class Bilangan {
friend ostream& operator<<(ostream& , const Bilangan&);
friend istream& operator>>(istream& ,  Bilangan&);
public:
            Bilangan(){};
   int cek() const;
private:
            float bil;
};
ostream& operator<<(ostream& out , const Bilangan& N){
if (N.cek()) out<<"Bulat"; else out << "Real";
            return out;
}
istream& operator>>(istream& in,Bilangan& q){
            cout<<"Masukkan bilangan = ";
            in>>q.bil;
            return in;
}
int Bilangan::cek() const{
   if ((int)bil==bil) return 1;
   else return 0;
}
void main(){
   Bilangan n;
   cin>>n;
   cout<<"Bilangan yang anda masukkan adalah bilangan "<< n <<endl;
   getch();
   return;
}

PROGRAM C++ PELAYANAN RUMAH SAKIT

program ini bisa mempermudah pelayanan di rumah sakit
supaya bisa mempercepat proses pelayanan.


selamat mencoba !!!



#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes
char getChoice();
double patientCharges(int, double, double, double); // In-patient
double patientCharges(double, double); // Out-patient

int main()
{
char patientType; // I=in-patient, O=out-patient
int days; // Number of days of <strong class="highlight">hospital</strong> stay
double roomRate, // Daily room rate
medication, // Total medication charges
services, // Total for tests and other services
totalCharges; // Total of all charges

// Input and validate patient type
cout << "This <strong class="highlight">program</strong> will compute patient <strong class="highlight">hospital</strong> charges.\n";
cout << "Enter I for in-patient or O for out-patient: ";
patientType=getChoice();


//Process the menu selection
switch (patientType)
{
//Inpatient
case 'I':
case 'i': cout << "The number of days spent in the <strong class="highlight">hospital</strong>: ";
cin >> days;
cout << "The daily rate: ";
cin >> roomRate;
cout << "Charges for <strong class="highlight">hospital</strong> service: ";
cin >> services;
cout << "Hospital medicaion charges; ";
cin >> medication;
cout << patientCharges (days, roomRate, services, medication) << endl;
totalCharges=(days*roomRate) + services + medication;
break;

//Outpatient
case 'O':
case 'o': cout << "Charges for <strong class="highlight">hospital</strong> services: ";
cin >> services;
cout << "Hospital medication charges: ";
cin >> medication;
cout << patientCharges (services, medication) << endl;
totalCharges= services + medication;
}



// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
cout << "******************************\n";
if (patientType == 'I' && patientType == 'i')
cout << "Room charges $" << setw(8) << days*roomRate << endl;
if (services > 0.0)
cout << "Lab & Services $" << setw(8) << services << endl;
if (medication > 0.0)
cout << "Medication $" << setw(8) << medication << endl;
cout << "Total charges $" << setw(8) << totalCharges << endl;
cout << "******************************\n";



return 0;
}// End of main function

//************************************...
// Definition of function getChoice *
// Accepts and returns user's validated menu choice. *
//************************************...
char getChoice()
{
char letter; // Holds user's letter choice

// Get the user's choice
cin >> letter;

// Validate the choice
while (letter != 'I' && letter != 'i'
&& letter != 'O' && letter != 'o')
{
cout << "Enter I or O: ";
cin >> letter;
}
// Return the choice
return letter;
}

/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for in-patients *
**************************************...
double patientCharges(int days, double rate, double med, double serv)
{

return (days*rate) + med + serv;


}// end overload function patientCharges

/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for out-patients *
**************************************...
double patientCharges(double med, double serv)
{

return med + serv;

}// end overload function patientCharges