Presentation is loading. Please wait.

Presentation is loading. Please wait.

Elemen Dasar C++ Pertemuan 3

Similar presentations


Presentation on theme: "Elemen Dasar C++ Pertemuan 3"— Presentation transcript:

1

2 Elemen Dasar C++ Pertemuan 3
Matakuliah : T0456 / Algoritma dan Metode Object Oriented Programming Tahun : 2007 Elemen Dasar C++ Pertemuan 3

3 Learning Outcomes Pada akhir pertemuan ini, diharapkan:
Mahasiswa dapat menggunakan elemen-elemen dasar C++ untuk membuat program dengan bahasa C++. Buku Referensi: C++ - How to program, Deitel & Deitel, Prentice Hall, 2001. Websites: 3 Bina Nusantara

4 Outline Materi Identifier Variabel Key Words Tipe Data Komentar
Operator 4 Bina Nusantara

5 Identifier Adalah nama berbagai elemen program: variable, fungsi, object, class, dsb. Aturan Penamaan identifier: Diawali dengan huruf atau garis bawah ( _ ). Diikuti dengan huruf, angka atau garis bawah ( _ ). Panjang maksimum 32 karakter (ANSI). Huruf besar dianggap berbeda dengan huruf kecil (case sensitive). Bukan kata kunci (Keyword) Tidak menggunakan operator atau spasi Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 5 Bina Nusantara

6 Variable Variabel adalah identifier yang digunakan untuk menampung data/informasi. Pada C++ variable dapat dideklarasikan diantara statement, tidak selalu harus diawal fungsi. Syntax : tipe variableName; tipe variableName=initialValue; Contoh : int a; double k=30.17; long fileSize, diskSize, total; Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 6 Bina Nusantara

7 Key Words (Kata Kunci) Merupakan pengenal system yang mempunyai makna khusus bagi compiler. Kegunaanya tidak dapat diubah, sehingga kata kunci tidak dapat digunakan sebagai pengenal / identifier yang dibuat oleh programmer. Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 7 Bina Nusantara

8 Daftar Kata Kunci (Key words) dalam C++
asm else operator template auto enum private this break extern protected typedef case float public union char for register unsigned class friend return virtual const goto short void continue if signed volatile default inline sizeof while delete int static do long struct double new switch 8 Bina Nusantara

9 Tipe Data Pada C++, tipe data terdiri atas 2 jenis: Abstract Data Type
Tipe data ini merupakan tipe data yang dibuat oleh user/programer (user defined), yaitu object yang dibuat dengan deklarasi class. Ini merupakan salah satu konsep dari OOP. Contoh: Titik, Lingkaran, Mahasiswa, Mobil, dll Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. Built In Data Type Merupakan tipe data yang dikenal oleh kompiler C/C++. Tipe data ini merupakan dasar untuk membuat abstract data type. Contoh: int, char, float, double, void 9 Bina Nusantara

10 Kontanta (Constant) Constant adalah identifier yang memiliki nilai tetap, terdapat 2 jenis yaitu : macro based dan named constant (formal). Pada C++, deklarasi const tidak membutuhkan alokasi memory (berbeda variable). Macro-based - Syntax: Contoh: #define Const_Name Const_Value #define Month_of_Year 12 Named Constant (Formal) Named constant dapat dipergunakan untuk kasus dimana diperlukan suatu bilangan konstan yang mempunyai karakteristik seperti variable. - Syntax : const data Type ConstName = ConstValue. - Contoh : const Month_of_Year = 12; Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 10 Bina Nusantara

11 Komentar Komentar merupakan bagian yang penting dalam program, karena membantu programmer dalam membuat penjelasan mengenai program dan bagian-bagiannya. Penjelasan pada komentar bisa berisi: • Tujuan dan fungsi program • Saat program dibuat dan direvisi • Keterangan sejumlah kegunaan dan pernyataan program. Untuk membuat komentar dipakai tanda // untuk satu baris dan /* … */ untuk lebih dari satu baris. Contoh: // Komentar baris /* komentar lebih dari satu baris */ Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 11 Bina Nusantara

12 Deklarasi dan definisi pada C++
Deklarasi (prototipe) digunakan untuk memperkenalkan suatu identifier kepada kompiler. Definisi (implementation) merupakan tubuh fungsi atau variable yang akan dicipta. Dalam C deklarasi dan definisi harus berada pada awal blok program, sedang dalam C++ deklarasi dan definisi biasa berada dimana saja dalam blok program. Contoh: int luas(int p, int l); //prototipe fungsi luas void main() { } int luas(int p, int l) //implementasi fungsi luas (tubuh fungsi luas) { return(p*l); } Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 12 Bina Nusantara

13 Operator Operator adalah simbol yang mengolah nilai pada operan dan menghasilkan satu nilai baru. Setiap operator mengolah data dengan satu cara tertentu. Operator Operasi Tipe Data Contoh + Unary Plus Numeric X = +y + 3 - Unary Minus X = -y Tambah Z = y + x Kurang Z = y – x * Kali Z = y * x / Bagi Z = y / x % Modulus Integer Z = y % x Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 13 Bina Nusantara

14 Increment dan Decrement Operator
Increment Operators Syntax : variable++ // post-increment ++variable // pre-increment contoh : LineNumber++; ++index; Decrement Operators Syntax : variable-- // post-decrement --variable // pre-decrement contoh : LineNumber--; --index; Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 14 Bina Nusantara

15 Assignment Operator Assignment Operator Operasi Contoh x + = y
x = x + y x + = 12  x = x + 12 x - = y x = x – y x - = 34  x = x – 34 x * = y x = x * y x * = 10  x = x * 10 x / = y x = x / y x / = 2  x = x / 2 x % = y x = x % y x % = 3  x = x % 3 Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. 15 Bina Nusantara

16 Relational dan Logical Operators
Arti Contoh && Logical AND if (I > 1 && I < 10) || Logical OR if (c == 0 || c != 9) ! Logical NOT if (!(c > 1 && c < 9)) < Less than if (i < 0) <= Less than or equal to if (i <= 0) > Greater than if (i > 10) >= Greater than or equal to if (j >= 14) == Equal to if (i == 0) != Not equal to if (i != 0) Currently, governments around the world, multinational corporations, and a multitude of companies are interested, even concerned with the concept of knowledge management. Indeed, even individual Canadian provinces have an interest in understanding the flow of knowledge within their confines, trying to become more aware of the structures that exist within their hierarchies. For example, "Prince Edward Island has agreed to become the first world test site for KAM, a new 'Knowledge Assessment Methodology' devised by the U.S. National Research Council in Washington, and coordinated by the Institute of Island Studies. The KAM will assess the capacity of Prince Edward Island to compete to world standards in what pundits have dubbed 'The Knowledge Economy'. As computers shrink our world, distance begins to disappear; the distinction between center and periphery narrows to insignificance. For Prince Edward Island, where small population and a paucity of natural resources have traditionally been economic inhibitors, the Knowledge Economy provides the potential for significant, environmentally benign economic growth." To understand more about the whys of measuring the flow of knowledge in any institution, one must understand more about knowledge. The real change has come from the necessity for less information and more knowledge. There has been a shift from information to knowledge. Shift from bureaucracies to networks. The traditional hierarchical designs that served the industrial era are not flexible enough to harness an organization's full intellectual capability. Shift from training/development to learning. The role of education has become paramount in all organizations, public and private. Shift from local/national to transnational. Organizations can no longer rely purely upon national approaches to maintain their profitable growth. More and more, companies and industries of all types must globalize in order to maximize their profits. Bina Nusantara 16

17 Diskusi dan Tanya Jawab Latihan soal
17 Bina Nusantara


Download ppt "Elemen Dasar C++ Pertemuan 3"

Similar presentations


Ads by Google