contoh program c++ untuk nomor telepon


karya:vasko gultom

#include <iostream.h>

#include <string.h>

class Telpon

{

private:

char area[5];

char kawasan[5];

char nomor[5];

public:

Telpon();

Telpon(char[],char[],char[]);

void showNumber();

void copyNumber(char[],char[],char[]);

~Telpon(){}

};

Telpon::Telpon()

{

strcpy(area,”061″);

strcpy(kawasan,”821″);

strcpy(nomor,”3793″);

}

Telpon::Telpon(char area[5],char kawasan[5],char nomor[5])

{

strcpy(Telpon::area,area);

strcpy(Telpon::kawasan,kawasan);

strcpy(Telpon::nomor,nomor);

}

void Telpon::showNumber()

{

cout<<“(“<<area<<“)”<<” “<<kawasan<<“-“<<nomor<<endl;

}

void Telpon::copyNumber(char area[5],char kawasan[5],char nomor[5])

{

strcpy(Telpon::area,area);

strcpy(Telpon::kawasan,kawasan);

strcpy(Telpon::nomor,nomor);

}

int main()

{

Telpon myTelp;

Telpon yourTelp;

char ar[5],kaw[5],no[5];

cout<<“Berikan kode wilayah, kawasan dan nomor telpon Anda: “;

cin>>ar>>kaw>>no;

yourTelp.copyNumber(ar,kaw,no);

cout<<“Nomor telpon saya: “;

myTelp.showNumber();

cout<<“Nomor telp. Anda: “;

yourTelp.showNumber();

return 0;

}

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s