1. Simpan code berikut dengan nama customer.h

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

enum c_kind {general, wholesale, retail};

class customer{
public:
void set_id(int id){
id_number=id;
cout<< "id number : "<<(id)<<endl;
}

void set_name(const string& last, const string& first){
last_name= last;
first_name= first;
}

c_kind get_kind() const{
return t;
}

void set_kind(c_kind k){
t=k;
}

void print() const{
cout<< (first_name+" "+last_name)<<endl;
}

double price_discount() const;

private:
string last_name, first_name;
int id_number;
c_kind t;
};

2. Simpan kode di bawah dengan nama customer.cpp

//customer.cpp
#include "customer.h"
double customer::price_discount() const{
if(t==wholesale)
return 0.20;
else
return 0.1;
}

3. Simpan kode terakhir berikut dengan nama democustomer.cpp

//democustomer.cpp
#include<iostream>
#include "customer.h"
using namespace std;

int main(){
customer c;
c.set_name("taufik","abidin");
c.set_kind(retail);
c.print();
c.set_id(2);
cout<< "your PC costs: $"<< 900*(1-c.price_discount())<<endl;
}

4. Kompile program dengan cara

c++ -Wall -o demo democustomer.cpp customer.cpp

Categories: ,

Leave a Reply

~:: I'am Rikki Satria,,

Nama lengkap ku Rikki Satria S
Kelahiran Bireuen 1991 dan kini aq Kuliah di Universitas Syiah Kuala
Fakultas MIPA :: Jurusan Matematika :: Prodi D3 Manajement Informatika // sangat rumit meski hanya 3 tahun di kampus ini,,
Kreatif dalam hal WEB designer meski kemampuan hanya 80% dan edit serta manipulasi gambar..
Kegiatan seharian Edit Blog hingga terasa cucho' di mata,, he he he
Selain itu aq juga hobi NGEBASS alias nge-BASKET.. jika ingin anda juga dapat bergabung
di groub basket aq yg bernama Vector BNA..