0% found this document useful (0 votes)
4 views3 pages

PBO

The document presents an object-oriented programming assignment in C++ that defines an 'Employee' class with private, protected, and public attributes. It also includes a derived 'Manager' class that inherits from 'Employee' and has its own method to display manager-specific information. The main function demonstrates the creation of 'Employee' and 'Manager' objects and displays their information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

PBO

The document presents an object-oriented programming assignment in C++ that defines an 'Employee' class with private, protected, and public attributes. It also includes a derived 'Manager' class that inherits from 'Employee' and has its own method to display manager-specific information. The main function demonstrates the creation of 'Employee' and 'Manager' objects and displays their information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tugas Pemrograman Berorientasi Objek

A. Input

#include <iostream>
#include <string>

using namespace std;

// Class Employee
class Employee {
private:
string nama; // Private attribute
int umur; // Private attribute

protected:
float gaji; // Protected attribute

public:
string jabatan; // Public attribute

Employee(const string &nama, int umur, float gaji, const string &jabatan) {
this->nama = nama;
this->umur = umur;
this->gaji = gaji;
this->jabatan = jabatan;
}

// Setter for nama


void setNama(const string &nama) {
this->nama = nama;
}

// Setter for umur


void setUmur(int umur) {
this->umur = umur;
}

// Protected method to set gaji


void setGaji(float gaji) {
this->gaji = gaji;
}
// Public method to set jabatan
void setJabatan(const string &jabatan) {
this->jabatan = jabatan;
}

// Method to display employee information


void info() {
cout << "=== Informasi Karyawan ===" << endl;
cout << "Nama : " << nama << endl;
cout << "Umur : " << umur << " tahun" << endl;
cout << "Jabatan : " << jabatan << endl;
cout << "Gaji : USD " << gaji << endl;
}
};

// Class turunan Manager


class Manager : public Employee {
public:
Manager(const string &nama, int umur, float gaji, const string &jabatan = "Manager")
: Employee(nama, umur, gaji, jabatan) {}

// Method to display manager-specific information


void showInfo() {
cout << "=== Informasi Manager ===" << endl;
cout << "Jabatan : " << jabatan << endl;
cout << "Gaji : USD " << gaji << endl;
}
};

int main() {
// Membuat objek Employee
Employee karyawan("Uzumaki Naruto", 30, 5000, "Manager");
karyawan.info();

// Membuat objek Manager


Manager manager("Uzumaki Naruto", 30, 5000);
manager.showInfo();

return 0;
}
B. Ouput

You might also like