5. Pengenalan Kepada C++ Edit Source Code C++ .cpp .c .cc .C .cxx compiler linker Object code .obj .o executable Proses berlaku secara transparent Standard library I/O Comm library
17. Jenis data C++ 2.33345 12.4333434343 6 angka bernilai 15 angka bernilai 32 64 Float double 20000000 -2147483648 hingga 2147483647 32 long int -12, 55 -128 hingga 127 8 short int 12, 99 0 hingga 65535 16 unsigned int 30566 , -2323 -32768 hingga 32767 16 int A, b, @ 0 hingga 255 8 char Contoh Julat Bit Jenis data
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37. Operator-operator ‘escape’ di dalam C++: Contoh-contoh lain bagaimana teks boleh dicetak di atas skrin ditunjuk di beberapa slide yg berikutnya.
38. Welcome to C++! 1 // Fig. 1.4: fig01_04.cpp 2 // Printing a line with multiple statements 3 #include <iostream> 4 5 int main() 6 { 7 cout << "Welcome "; 8 cout << "to C++!"; 9 10 return 0; // indicate that program ended successfully 11 } Unless new line '' is specified, the text continues on the same line.
39. Welcome to C++! 1 // Fig. 1.5: fig01_05.cpp 2 // Printing multiple lines with a single statement 3 #include <iostream> 4 5 int main() 6 { 7 cout << "WelcometoC++!"; 8 9 return 0; // indicate that program ended successfully 10 } Multiple lines can be printed with one statement.
54. Enter first integer 45 Enter second integer 72 Sum is 117 1 // Fig. 1.6: fig01_06.cpp 2 // Addition program 3 #include <iostream> 4 5 int main() 6 { 7 int integer1, integer2, sum; // declaration 8 9 cout << "Enter first integer"; // prompt 10 cin >> integer1; // read an integer 11 cout << "Enter second integer"; // prompt 12 cin >> integer2; // read an integer 13 sum = integer1 + integer2; // assignment of sum 14 cout << "Sum is " << sum << endl; // print sum 15 16 return 0; // indicate that program ended successfully 17 } Notice how cin is used to get user input. Variables can be output using cout << variableName . endl flushes the buffer and prints a newline.