Informasi Teknologi, Tutorial Blog Dan Pemrograman

Program C++ Public Pada Class

Program C++ Public Pada Class

Format C + + class paProgram Public In Class

Public stated that the declaration of variables or items that are in the class can be accessed outside the class.

Example C + + First Program

#include
#include
#include
#include
Class motor
{
public:
char merk[50];
char jenis[50];
double harga;
int stok;
};
motor sport;
void main(){
strcpy(sport.merk, “ Suzuki satria FU”);
strcpy(sport.jenis, “Honda”);
sport.harga=19.000000;
sport.stok=150;
cout<<”Merk Motor Sport:”<<<<”Jenis Motor :”<<<<<”Harga Motor:”; cout<<”setprecision(0)<<<<”Stok Motor:”<<<<”Stok Motor:”<<
#include
#include
Class motor
{
private:
char merk[50];
char jenis[50];
double harga;
int stok;
public :
void daftar(char*merk, char *jenis,double harga, int stok)
{
Strcpy(merk, merk);
Strcpy(jenis, jenis);
harga=Harga;
stok=Stok;
}
void jalankan()
{
cout<<” Merk Motor Sport:”<<
cout<<”Jenis Motor :”<<
cout<
cout<<” Harga Motor :”;
cout<<<
cout<<” Stok Motor :”<<
}
};
void main()
{
clrscr();
motor sport;
sport.daftar(“Suzuki Satria FU”,”Suzuki”,19.000000,15);
sport.jalankan();
getch();
}


Posted by Imam Muamar Kharisma, Published at 06.31 and have 0 comments