class explanation

#include <iostream>
using namespace std;

// making a class named kelas1
class KELAS1 {
int A;
public:
void set_A(int AA);
int get_A();
void show_A();
};

// making a class named kelas2
class KELAS2 {
int B;
public:
void set_B(int BB);
int get_B();
void show_B();
};

// creating a class named kelas1
class KELAS3 {
int C;
public:
void set_C(int CC);
int get_C();
void show_C();
};
// Implementation of the function in class KELAS1
void KELAS1::set_A(int AA) {
A = AA;
}

int KELAS1::get_A() {
return A;
}
void KELAS1::show_A() {
cout<<"Nilai A : "<<A<<endl;
}

// Implementation of the function in class KELAS2
void KELAS2::set_B(int BB) {
B = BB;
}

int KELAS2::get_B() {
return B;
}

void KELAS2::show_B() {
cout<<"Nilai B : "<<B<<endl;
}

// Implementation of the function in class KELAS1
void KELAS3::set_C(int CC) {
C = CC;
}
int KELAS3::get_C() {
return C;
}
void KELAS3::show_C() {
cout<<"Nilai C : "<<C<<endl;
}
// defining a main function
int main()
{
// declare object OB1, OB2 dan OB3 for the container for the classes
KELAS1 OB1; // OB1 typed as KELAS1
KELAS2 OB2; // OB2 typed as KELAS2
KELAS3 OB3; // OB3 typed as KELAS3

// set the value for objects
OB1.set_A(10);
OB2.set_B(20);
OB3.set_C(30);

// show the output
OB1.show_A();
OB2.show_B();
OB3.show_C();

system ("pause");
return 0;
}


Question :
a. please explain this code meaning please...
b. why is there "(int AA) after the void set_A, is that a rules?? give me a clue please..

class KELAS1 {
int A;
public:
void set_A(int AA);
int get_A();
void show_A();
};
int AA is the parameter list for the set_A function. You need to define your functions like this if you are passing values to them, it's basic function design.

Edit: OOps, realized those were definitions, not declarations.
Last edited on
Topic archived. No new replies allowed.