1. Simpan code berikut dengan nama customer.h
2. Simpan kode di bawah dengan nama customer.cpp
3. Simpan kode terakhir berikut dengan nama democustomer.cpp
4. Kompile program dengan cara
#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;
};
#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;
}
#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;
}
#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