This document provides an introduction to the basic structure of C++ programs, including comments, preprocessor directives, header files, the main function, and return statements. It discusses the different types of comments in C++ and how preprocessor directives are used. Header files are described as include files that contain declarations to be shared between code files. The main function is outlined as the entry point of a C++ program. Key elements like curly braces and statements ending with semicolons are also introduced. Finally, the importance of following coding standards is highlighted.
Peristiwa Fathul Makkah terjadi karena pelanggaran perjanjian Hudaibiyah oleh Bani Bakr yang menyerang Bani Khuza'ah. Nabi Muhammad SAW memimpin pasukan Islam masuk ke Makkah secara damai pada 8 H/630 M. Setelah memasuki Makkah, Nabi SAW menghancurkan berhala-berhala di sekitar Ka'bah dan menyatakan Islam sebagai agama resmi di Makkah. Nabi kemudian melakukan ekspedisi ke berbagai suku
Ibnu Taimiyah dikritik kerana pandangan-pandangannya yang menyeleweng dan tidak selari dengan iktikad majoriti umat Islam. Dia dituduh menyeleweng dalam isu-isu akidah seperti mengatakan makhluk wujud sejak azali, menyifatkan had pada Allah, mengatakan Allah duduk dan mempunyai arah, serta mengatakan wujud itu mesti berjirim. Pandangan-pandangannya ini dinafikan oleh ulama-ul
Peristiwa Fathul Makkah terjadi karena pelanggaran perjanjian Hudaibiyah oleh Bani Bakr yang menyerang Bani Khuza'ah. Nabi Muhammad SAW memimpin pasukan Islam masuk ke Makkah secara damai pada 8 H/630 M. Setelah memasuki Makkah, Nabi SAW menghancurkan berhala-berhala di sekitar Ka'bah dan menyatakan Islam sebagai agama resmi di Makkah. Nabi kemudian melakukan ekspedisi ke berbagai suku
Ibnu Taimiyah dikritik kerana pandangan-pandangannya yang menyeleweng dan tidak selari dengan iktikad majoriti umat Islam. Dia dituduh menyeleweng dalam isu-isu akidah seperti mengatakan makhluk wujud sejak azali, menyifatkan had pada Allah, mengatakan Allah duduk dan mempunyai arah, serta mengatakan wujud itu mesti berjirim. Pandangan-pandangannya ini dinafikan oleh ulama-ul
Perang Khandaq terjadi pada Maret-April 627 antara umat Muslim di Madinah melawan konfederasi 10.000 pasukan dari suku Arab dan Yahudi. Umat Muslim yang jumlahnya hanya 3.000 orang berhasil mengalahkan musuh dengan taktik menggali parit pertahanan, meski mereka kalah jumlah. Perang ini berakhir dengan mundurnya pasukan konfederasi setelah dua minggu karena kehabisan makanan.
Tulisan ini mengungkap Tafsir Syiah Zaydiyah yang paparkan oleh Imam al-Syaukani dalam Tafsir Fath al-Qadir. Yang menarik dari tulisan ini, kendati madzhabnya syiah Zaidiyah, namun gagasan dan pemikirannya sering sejalan dengan Ahlus Sunnah wal Jamaah. selain itu, tulisan ini menelisik corak pemikiran kalam dalam tafsir Fath al-Qadir.
Dokumen tersebut membahas sejarah usrah dan peranan naqib. Ia menjelaskan bahawa Allah telah mengambil janji kepada Bani Israel untuk mengangkat dua belas orang sebagai naqib. Dokumen ini juga membincangkan faktor-faktor yang mendekatkan hubungan antara da'ie dan mad'u serta beberapa penyakit yang mungkin dialami oleh naqib jika tidak melaksanakan tanggungjawabnya dengan baik. Ia juga men
Dokumen tersebut membahas tentang syurga dan neraka sebagai tempat pembalasan bagi umat manusia di akhirat. Dibahas mengenai nama-nama syurga dan neraka, kenikmatan yang ada di syurga seperti sungai, buah-buahan, dan pelayanan, serta kesengasraan di neraka seperti api dan air yang mendidih. Juga dibahas mengenai sifat-sifat yang dapat memasukkan seseorang ke syurga atau neraka,
Dokumen tersebut membahas tentang pengertian, cara mengetahui, ciri-ciri, dan klasifikasi ayat Makiyyah dan Madaniyyah serta kegunaan mempelajarinya. Ayat Makiyyah diturunkan sebelum hijrah Nabi ke Madinah sedangkan Madaniyyah sesudahnya. Pengetahuan tentang Makiyyah dan Madaniyyah membantu memahami Al-Quran dan mengambil pelajaran untuk dakwah.
Dokumen tersebut merangkum tentang pemahaman sejarah kebudayaan Islam. Secara garis besar membahas pengertian, tujuan, dan bentuk-bentuk kebudayaan Islam serta manfaat mempelajari sejarah kebudayaan Islam. Dokumen ini juga menjelaskan karakteristik sejarah dan kegunaannya dalam kehidupan.
1. Pengembangan kurikulum melibatkan perumusan Capaian Pembelajaran Lulusan (CPL) berdasarkan analisis kebutuhan pemangku kepentingan dan pengembangan ilmu di program studi, serta pembentukan mata kuliah untuk mencapai CPL tersebut.
Teks tersebut membahas tentang ulumul qur'an, yang merupakan ilmu yang membahas berbagai aspek terkait Al-Qur'an. Ia menjelaskan pengertian, ruang lingkup, sejarah perkembangan, dan beberapa karya kunci di bidang ulumul qur'an era modern.
The document discusses the basics of C programming language. It defines commands, programs, and software. C was created in 1972 and is well-suited for systems programming and operating systems. The structure of a C program includes main functions, delimiters, comments, and the standard library. Problems are solved through algorithms, pseudocode, and flowcharts which use symbols to represent program logic and control flow.
The document provides an overview of problem solving and C programming at a basic knowledge level. It covers various topics including introduction to problem solving, programming languages, introduction to C programming, selection structures, arrays and strings, pointers, functions, structures and unions, and files. The objective is to understand problem solving concepts, appreciate program design, understand C programming elements, and write effective C programs. It discusses steps in program development, algorithms, modular design, coding, documentation, compilation and more.
Perang Khandaq terjadi pada Maret-April 627 antara umat Muslim di Madinah melawan konfederasi 10.000 pasukan dari suku Arab dan Yahudi. Umat Muslim yang jumlahnya hanya 3.000 orang berhasil mengalahkan musuh dengan taktik menggali parit pertahanan, meski mereka kalah jumlah. Perang ini berakhir dengan mundurnya pasukan konfederasi setelah dua minggu karena kehabisan makanan.
Tulisan ini mengungkap Tafsir Syiah Zaydiyah yang paparkan oleh Imam al-Syaukani dalam Tafsir Fath al-Qadir. Yang menarik dari tulisan ini, kendati madzhabnya syiah Zaidiyah, namun gagasan dan pemikirannya sering sejalan dengan Ahlus Sunnah wal Jamaah. selain itu, tulisan ini menelisik corak pemikiran kalam dalam tafsir Fath al-Qadir.
Dokumen tersebut membahas sejarah usrah dan peranan naqib. Ia menjelaskan bahawa Allah telah mengambil janji kepada Bani Israel untuk mengangkat dua belas orang sebagai naqib. Dokumen ini juga membincangkan faktor-faktor yang mendekatkan hubungan antara da'ie dan mad'u serta beberapa penyakit yang mungkin dialami oleh naqib jika tidak melaksanakan tanggungjawabnya dengan baik. Ia juga men
Dokumen tersebut membahas tentang syurga dan neraka sebagai tempat pembalasan bagi umat manusia di akhirat. Dibahas mengenai nama-nama syurga dan neraka, kenikmatan yang ada di syurga seperti sungai, buah-buahan, dan pelayanan, serta kesengasraan di neraka seperti api dan air yang mendidih. Juga dibahas mengenai sifat-sifat yang dapat memasukkan seseorang ke syurga atau neraka,
Dokumen tersebut membahas tentang pengertian, cara mengetahui, ciri-ciri, dan klasifikasi ayat Makiyyah dan Madaniyyah serta kegunaan mempelajarinya. Ayat Makiyyah diturunkan sebelum hijrah Nabi ke Madinah sedangkan Madaniyyah sesudahnya. Pengetahuan tentang Makiyyah dan Madaniyyah membantu memahami Al-Quran dan mengambil pelajaran untuk dakwah.
Dokumen tersebut merangkum tentang pemahaman sejarah kebudayaan Islam. Secara garis besar membahas pengertian, tujuan, dan bentuk-bentuk kebudayaan Islam serta manfaat mempelajari sejarah kebudayaan Islam. Dokumen ini juga menjelaskan karakteristik sejarah dan kegunaannya dalam kehidupan.
1. Pengembangan kurikulum melibatkan perumusan Capaian Pembelajaran Lulusan (CPL) berdasarkan analisis kebutuhan pemangku kepentingan dan pengembangan ilmu di program studi, serta pembentukan mata kuliah untuk mencapai CPL tersebut.
Teks tersebut membahas tentang ulumul qur'an, yang merupakan ilmu yang membahas berbagai aspek terkait Al-Qur'an. Ia menjelaskan pengertian, ruang lingkup, sejarah perkembangan, dan beberapa karya kunci di bidang ulumul qur'an era modern.
The document discusses the basics of C programming language. It defines commands, programs, and software. C was created in 1972 and is well-suited for systems programming and operating systems. The structure of a C program includes main functions, delimiters, comments, and the standard library. Problems are solved through algorithms, pseudocode, and flowcharts which use symbols to represent program logic and control flow.
The document provides an overview of problem solving and C programming at a basic knowledge level. It covers various topics including introduction to problem solving, programming languages, introduction to C programming, selection structures, arrays and strings, pointers, functions, structures and unions, and files. The objective is to understand problem solving concepts, appreciate program design, understand C programming elements, and write effective C programs. It discusses steps in program development, algorithms, modular design, coding, documentation, compilation and more.
This document provides an overview of fundamental computer programming concepts in Chapter 1. It begins with defining what a computer program and programming are, and reasons for studying programming such as career opportunities and developing logical thinking. It then covers the program development life cycle and an overview of programming languages and paradigms. The remainder of the document discusses specific aspects of C++ programs including compilation processes, program structure, input/output streams, library functions, preprocessor directives, variables and data types.
The document discusses Unit 4 of the Programming for Problem Solving course. It covers functions and pointers in C programming. Specifically, it discusses function declaration, definition, user-defined functions, storage classes, function prototypes, parameter passing methods (call by value and call by reference), recursion, pointers, pointer arithmetic, and dynamic memory allocation using pointers.
This document discusses the C programming language and data structures. It covers the basic structure of C programs, including functions, main functions, and sections like documentation, definitions, declarations, and subprograms. It also discusses basic C programs, data types, operators, control structures, arrays, pointers, structures, unions, and file I/O. The document is intended to introduce students to C language concepts and data structures.
Problem Solving Techniques and Introduction to CPrabu U
This document provides an overview of problem solving techniques, programs, and the program development cycle. It discusses:
1. The steps of problem solving techniques include defining the problem, formulating a mathematical model, developing an algorithm using a flowchart or pseudocode, writing code, and testing the program.
2. A program consists of a series of instructions and fixed data to perform required operations. The program development cycle involves problem analysis, design, coding, compilation and execution, debugging and testing, and documentation.
3. An algorithm is a finite sequence of steps to solve a problem. Flowcharts use graphical symbols to represent the steps of an algorithm and show the program logic through connections between these symbols.
This document discusses the basics of C programming, including:
1) The structure of a C program which includes documentation, link, definition, global declaration, main(), and sub programs sections.
2) The compilation process of a C program which involves preprocessing, compilation, assembly, and linking to create an executable file.
3) What occurs during each phase of compilation including removing comments, expanding macros/included files, conditional compilation, assembling machine-level instructions, and linking function calls.
The document provides an introduction and overview of the COIT29222 Structured Programming course, including information about the textbook, assessments, topics to be covered, and a simple C++ program example. Students are instructed to contact their local lecturer/tutor if they have any problems or questions. Plagiarism is strictly prohibited and assignments must follow a five-step software development process using pseudocode to design programs that will be written and tested in C++, compiling the code using Visual C++.
The document discusses the C programming language and data structures. It covers the basic structure of C programs, data types, operators, control flow statements, arrays, strings, functions, pointers, structures, unions and file I/O. The chapters are outlined and key concepts like algorithms, flowcharts and program development steps are explained in detail. The history and evolution of C language is presented along with its features, applications and importance. A simple C program example is also provided and analyzed.
Notes of c programming 1st unit BCA I SEMMansi Tyagi
This document discusses the basics of the C programming language. It covers the structure of a basic C program, which must include a main function with declaration and executable parts. C tokens like keywords, identifiers, constants, operators and strings are also introduced. The document then discusses C program development steps like understanding the problem, planning input/output, designing an algorithm, coding, testing and debugging. It provides a high-level overview of the C language and programming in C.
The document provides an introduction to the C programming language including its history, importance, basic structure, and key concepts. It was developed in 1972 by Dennis Ritchie at Bell Labs. C is a high-level language well-suited for system programming like operating systems and compilers. The basic structure of C programs includes sections for documentation, headers, preprocessor directives, global declarations, the main function, and subprograms. The document also discusses C tokens, variables, data types, input/output functions, and assignment statements.
This document discusses embedded C programming. It defines embedded C and compares it to conventional C and assembly programming. Key differences between embedded C and other languages include embedded C being microcontroller dependent rather than processor dependent, more portable code, and easier readability. Embedded C allows direct hardware access and optimization for limited embedded systems. The document outlines rules for developing optimized embedded C programs, including scope of variable declarations, function parameters, and register usage. Cross-compilers are used to compile embedded C code into executable hex files for microcontrollers.
The document discusses several basic concepts in C programming including writing a simple "Hello, World" program, the general form of a C program, comments, and functions. It explains that a C program typically includes preprocessor directives, main function, and statements. Functions allow grouping of statements and are either defined by the programmer or come from standard libraries. Comments are ignored by the compiler and used for documentation.
This document provides an overview of the C programming language course including the course code, name, and units covered. Unit 1 covers an introduction to C including its history, importance, constants, variables, data types, input/output operations, and expressions. The document also discusses why C is widely used, facts about C, the basic structure of C programs, and the importance of C as a structured, high-level, machine-independent language suitable for both systems and business applications.
Object oriented programming 7 first steps in oop using c++Vaibhav Khanna
Advantages of C++
Portability. C++ offers the feature of portability or platform independence which allows the user to run the same program on different operating systems or interfaces at ease. ...
Object-oriented. ...
Multi-paradigm. ...
Low-level Manipulation. ...
Memory Management. ...
Large Community Support. ...
Compatibility with C. ...
Scalability.
This document provides an introduction to the C programming language. It covers C program structure, variables, expressions, operators, input/output, loops, decision making statements, arrays, strings, functions, pointers, structures, unions, file input/output and dynamic memory allocation. The document uses examples and explanations to introduce basic C syntax and concepts.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
Leveraging Generative AI to Drive Nonprofit InnovationTechSoup
In this webinar, participants learned how to utilize Generative AI to streamline operations and elevate member engagement. Amazon Web Service experts provided a customer specific use cases and dived into low/no-code tools that are quick and easy to deploy through Amazon Web Service (AWS.)
1. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DFC 20113
PROGRAMMING
FUDAMENTALS
CHAPTER 1
INTRODUCTION TO FUNDAMENTALS
OF PROGRAMMING
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
2. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
COURSE LEARNING
OUTCOMES
CLO 1: Implement programming element
and articulate how they are used to achieve
a working program.
( C3, PLO 2 )
CLO 2: Show simple programs by
developing code to solve problems in a
computer using C++ programming
language. ( P2, PLO 3 )
3. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
at the end of this sub-chapter, students should be able
to:
• Describe the item in C++ program
structure
• Comments
• Preprocessor directives
• Header files
• main() function
• return statements.
• Describe two types of comments that
supported by C++ program
• Explain coding standard best practices
1.1 Define
the C++
program
basic
structure
4. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
• Probably the best way to start learning a programming
language is by writing a program.
• Therefore, here is our first program:
// my first program in C++
#include <iostream.h>
int main ()
{
cout << “My First Program!";
return 0;
}
Output:
My First Program!
OUTPUT
SOURCE CODE
5. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
a) Comment Style
•Entries in the source code which are ignored by the compiler
•C++ support 2 style/form of comments:
i.//Single Line Comments
for simple 'side' notes
best places to put these comments are next to variable
declarations, and next to pieces of code that may need
explanation.
ii./ *block comment */or /*Multi-Line Comments*/
most useful for long explanations of code.
useful for two reasons: They make your functions easier
to understand, and they make it easier to spot errors in
code.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
6. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Illustrate the valid & invalid comments within a program.
Comment statements
// this program displays a message valid
/ this program displays a message invalid
// this comment is invalid because its
extend over two lines
invalid
// this comment is used a comment that
//extend across two lines
valid
/*this comment is a block comment that
spans
three lines*/
valid
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
7. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Pre Processor Directive
• What’s a #?
• Any line that begins with # symbol is a pre-processor directive
• Processed by preprocessor before compiling
• What’s pre-processor?
• A utility program, which processes special instructions are written in a
C/C++ program.
• Include a library or some special instructions to the compiler about
some certain terms used in the program
• Different preprocessor directives (commands) perform different tasks.
• Uses for?
• It is a message directly to the compiler.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
8. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• How to write/syntax ?
• Begin with #
• No semicolon (;) is expected at the end of a preprocessor directive.
• Example:
Pre-processor directive Meaning
#include <iostream> Tells preprocessor to include the input/output stream
header file <iostream>
#define NAME “BOB” Define a constant
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
9. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
c) Header File
• sometimes known as an include file. Header files
almost always have a .h extension.
• Why use?
• For big projects having all the code in one file is impractical. But if we
split the project into smaller files, how can we share functions between
them? Headers!
The purpose of a header file?
To hold declarations for other files to use.
When we use the line #include <iostream>, we are telling the compiler
to locate and then read all the declarations from a header file named
“iostream”.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
10. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Consider the following program:
Program never declare cout, so how does the compiler know what
cout is?
The answer is that cout has been declared in a header file
called “iostream”.
Bear in mind that
header files typically
only contain
declarations. They do
not define how
something is
implemented
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
11. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
d) Main Function
• This line corresponds to the beginning of the definition of the
main function.
• A part of every C++ program and identify the start of the
program
Exactly one function in a program must be main
main is a Keyword.
• Keyword : A word in code that is reserved by C++ for
a specific use.
• Header of function main?
int main( )
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
12. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• The structure of a main Function:
int main ( )
{
C++ program statements goes here;
return 0;
}
Function
body
Type of
return value
Function name An empty
argument list
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
13. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• 4 common ways of main declaration:
int main()
{
return 0;
}
void main()
{
}
main(void)
{
}
main( )
{
}
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
14. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
e) Curly Braces {}
• Body is delimited by braces ({ })
• Identify a segment / body of a program
The start and end of a function
The start and end of the selection or repetition block.
• Since the opening brace indicates the start of a segment
with the closing brace indicating the end of a segment,
there must be just as many opening braces as closing
braces
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
15. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
f) C++ statement
• What's?
A specification of an action to be taken by the computer as the program
executes.
Instruct the program to perform an action
• Syntax?
All statements end with a semicolon (;)
• Statement has two parts :
Declaration
• The part of the program that tells the compiler the
names of memory cells in a program
Executable statements
• Program lines that are converted to machine language instructions
and executed by the computer
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
16. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
g) Return Statement
• Means?
The return statement causes the main function to finish.
Return may be followed by a return code (in our example
is followed by the return code with a value of zero).
A return code of 0 for the main function is generally
interpreted as the program worked as expected without
any errors during its execution.
• When used?
At the end of main
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
17. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Two situations for return statement:
a) Return optional in void functions
A void function doesn't have to have a return statement when the end is
reached, it automatically returns.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
18. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Return required in non-void functions
If a function returns a value, it must have a return
statement that specifies the value to return.
It's possible to have more than one return.
Example 1: return 0;
Return the value
0 to the
computer's
operating system
to signal that the
program has
completed
successfully
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
19. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Coding Standards Best Practices
Refer this link:
https://google.github.io/styleguide/cppguide.html
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
20. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Importance of following coding standards best practices:
easier for a developer to understand
easier to find and correct bugs
provides a better view of how that code fits within the
larger application
easier for someone to maintain that code
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
21. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
PROGRAMMING EXERCISE
Ahmad are asked to create a program that can calculate the
area of rectangle. He need to identify the IPO, draw a
flowchart and create a program. You are asked to help
Ahmad.
22. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
at the end of this sub-chapter, students should
be able to:
• Explain identifier, variable and
constant.
• State the rules for naming an identifier.
• Name the variables according the
standards
• Explain the data types.
• List the data types and their respective
range with examples:
• Integer
• Floating point
• Character
• Boolean
• String
1.2 Explain
identifier
and data
types
23. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• IDENTIFIER: Words used to represent certain program
entities (variables, function names, etc).
• VARIABLE is identifier whose value can change during the
course of execution of a program
• KEYWORDS (reserved words) have standard, predefined
meanings and must be used only for their intended purpose. It
cannot be used as an identifier.
• CONSTANTS are values that do not change during program
execution. They can be any type of integer, character or
floating-point.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
24. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
a) Identifier
• Words used to represent certain program entities
(variables, function names, etc).
• Example:
• int number;
• number is an identifier used as a program variable
• void CalculateTotal (int value)
• CalculateTotal is an identifier used as a function name
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
25. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Variables
• What's? Is a Location in memory which:
we can refer to by an identifier, and
in which a data value that can be change
Where value can be stored
• Common data types (fundamental, primitive or built-in)
int – integer numbers : 1, 2, 4,….
char – characters : ‘a’, ‘c’, …
float, double: floating point numbers: 2.5, 4.96
• The value of a variable could be changed while the program is
running.
• Declaring a variable means specifying both its name and its data
type.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
26. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
EXAMPLE OF VARIABLES
int is an abbreviation for integer.
• Integer store value: 3, 102, 3211, -456, etc.
• Example variable : number_of_bars
double represents numbers with a fractional
component
• double store value: 1.34, 4.0, -345.6, etc.
• Example variable : one_weight ,total_weight
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
27. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
c) Constant
• Entities that appear in the program code as fixed values.
• Any attempt to modify a CONSTANT will result in error.
• Declared using the const qualifier
• Also called named constants or read-only variables
• Must be initialized with a constant expression when they are
declared and cannot be modified
• Example: const int size = 5;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
28. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of constant:
1. Literals
Literals are the most obvious kind of
constants.
They are used to express particular values
within the source code of a program.
e.g:
a=5;
grade=‘A’;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
29. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of constant:
2. Define Constant (#define)
You can define your own names for constants that
you use very often without having to resort to
memory-consuming variables, simply by using the
#define preprocessor directive.
Its format is:
#define identifier value
Examples:
#define PI 3.14159
#define GRAVITY 9.8
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
30. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of Constant:
3. Declared Constants
With the const prefix you can declare constants with
A specific type in the same way as you would do with
A variable:
const int pathwidth = 100;
const char grade = ‘A';
They are treated just like regular variables except
that their values cannot be modified after their
definition.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
31. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Rules Example
Can contain a mix of character and numbers. However it cannot start
a number
H2o
First character must be a letter or underscore Number1,
_area
Can be of mixed cases including underscore character XsquAre
my_num
Cannot contain any arithmetic operators R*S+T
… or any other punctuation marks #@x%!!
Cannot be a C keyword/reserved word struct; cout;
Cannot contain a space My height
… identifiers are case sensitive Tax != tax
NAMING CONVENTION RULES FOR IDENTIFIER
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
32. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• They are formed by combining letters, digits & underscores.
• Blank space is not allowed in an identifier.
• The first character of an identifier must be a letter.
Valid Invalid Reason
Monthly_Salary Monthly Salary Blank space cannot be used
Month1 1stMonth Digit cannot be used as a first
character
Email_add email@ Special characters cannot be
used
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
33. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Why variables needed in programming?
Variables are used to store information to be referenced and
manipulated in a computer program.
They also provide a way of labeling data with a descriptive name, so
our programs can be understood more clearly by the reader and
ourselves.
It is helpful to think of variables as containers that hold
information.
Their purpose is to label and store data in memory. This data can
then be used throughout a program.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
34. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• When we create a program, we store the variables in
our computer's memory.
• But the computer has to know what kind of data we
want to store in them.
• Since it is not going to occupy the same amount of
memory to store a simple number than to store a
single letter or a large number.
• They are not going to be interpreted the same way.
Basic Data Types
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
35. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DATA
TYPES
Numeric
• int
• float
• double
Non-numeric
• char
• string
• bool
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
36. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Name Description Size* Range*
string Sequence of character.
10 bytes +
string length
0 to approximately 2 billion
char Character or small integer. 1byte
signed: -128 to 127
unsigned: 0 to 255
bool
Boolean value. It can take one
of two values: true or false.
1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
int Integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
double
Double precision floating
point number.
8bytes +/- 1.7e +/- 308 (~15 digits)
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
37. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• There are 6 basic data types :
i. char
• equivalent to ‘letters’ in English language
• Example of characters:
• Numeric digits: 0 - 9
• Lowercase/uppercase letters: a - z and A - Z
• Space (blank)
• Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
• single character
• keyword: char
• Example code:
• Sample values
‘B’ ‘d’ ‘4’ ‘?’ ‘*’
The
declared
character
must be
enclosed
within a
single
quote!
char my_letter;
my_letter = 'U';
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
38. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
ii. int
• used to declare numeric program variables of integer type
• whole numbers, positive and negative
• keyword: int
• Example code :
• Sample values:
4578 -4578 0
int number;
number = 12;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
39. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
iii. double
• used to declare floating point variable of higher
precision or higher range of numbers
• exponential numbers, positive and negative
• keyword: double
• Code example:
double valuebig;
valuebig = 12E-3;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
40. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
iv. float
• fractional parts, positive and negative
• real numbers with a decimal point
• keyword: float
• Example code:
• sample values
95.274 95.5 2.265
float height;
height = 1.72;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
41. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
v. bool
• The bool data type is capable of holding a
Boolean value.
• Objects of type bool may have only the values
true or false.
• To declare a variable of type bool:
bool old_enough;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
42. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
vi. string
• a string is a sequence of characters enclosed in
double quotes
• string sample values:
“Hello” “Year 2000” “1234”
• the empty string (null string) contains no
characters and is written as “ ”
• Example code:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
string name = “Ahmad Albab”;
43. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
// operating with variables
#include <iostream>
Using namespace std;
int main ()
{
// declaring variables
int a, b, result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
return 0;
}
Output:
4
Example 1:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
44. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
// operating with variables
#include <iostream>
using namespace std;
int main ()
{
// declaring variables
string name;
//get input from user
cout<<“Enter your name: “;
cin>>name;
// print out name:
cout <<“Your name: “<<name;
// terminate the program:
return 0;
}
Output:
Enter your
name: ALI
Your name:
ALI
Example 2:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
45. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
AT THE END OF THIS SUB-CHAPTER,
STUDENTS SHOULD BE ABLE TO:
• Describe the features of C++
language.
• Develop C++ program using
Integrated Development
Enviroment (IDE).
• Get started with IDE
• Create a project file
• Create a simple C++ program
• Compile a C++ program
• Run a C++ program
1.3 Identify
the basic of
computer
program
46. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
Features of C++ language
C++ is object oriented programming language and it is a very simple and easy
language, this language have following features.
47. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Simple
Every C++ program can be written in simple English language so that it is very easy to
understand and developed by programmer.
• Portability
It is the concept of carrying the instruction from one system to another system. In C++
Language .cpp file contain source code, we can edit also this code. .exe file contain application,
only we can execute this file. When we write and compile any C++ program on window
operating system that program easily run on other window based system.
• Powerful
C++ is a very powerful programming language, it have a wide verity of data types, functions,
control statements, decision making statements, etc.
• Platform dependent
A language is said to be platform dependent whenever the program is execute in the same
operating system where that was developed and compiled but not run and execute on other
operating system. C++ is platform dependent language.
• Object oriented
This main advantage of C++ is, it is object oriented programming language. It follow concept
of oops like polymorphism, inheritance, encapsulation, abstraction.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
48. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Case sensitive
C++ is a case sensitive programming language. In C++ programming 'break and BREAK'
both are different. If any language treats lower case latter separately and upper case latter
separately than they can be called as case sensitive programming language [Example c, c++,
java, .net are sensitive programming languages.] other wise it is called as case
insensitive programming language [Example HTML, SQL is case insensitive programming
languages].
• Compiler based
C++ is a compiler based programming language that means without compilation no C++
program can be executed. First we need compiler to compile our program and then execute.
• Syntax based language
C++ is a strongly tight syntax based programming language. If any language follow rules and
regulation very strictly known as strongly tight syntax based language. Example C, C++,
Java, .net etc. If any language not follow rules and regulation very strictly known as loosely
tight syntax based language.
Example HTML.
• Use of Pointers
Pointers is a variable which hold the address of another variable, pointer directly direct
access to memory address of any variable due to this performance of application is improve.
In C++ language also concept of pointer are available.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
49. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Integrated Development Environment
An integrated development environment (IDE) is a software
application that provides comprehensive facilities to computer
programmers for software development.
All of the tools for writing, compiling and
testing code in one place.
An IDE normally consists of:
- a source code editor
- a compiler and/or an interpreter
- build automation tools
- a debugger
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
50. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Get start with IDE Software: Dev C++
Compile
Execute
New file
Compile & Execute
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
51. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Create a simple C++ program:
• Compile and run your code. Then display the output.
Write a program to display your name,
registration number and department in separate
line.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
52. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
S
O
L
U
T
I
O
N
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
53. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
AT THE END OF THIS SUB-CHAPTER,
STUDENTS SHOULD BE ABLE TO:
•Describe the compiling process of a
program
•Source code
•Compiler
•Linker
•Executable file
•Describe with example the errors in
programming:
•Syntax/ compile time errors
•Run time errors
•Logical errors
•Identify effective debugging process
•Debug simple programs to demonstrate
syntax/ compile time, run time and logical
error
1.4
Describe the
compiling and
debugging
process and
errors in
programming
54. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
COMPILING PROCESS
• A compiler is a computer program (or set of programs)
that transforms source code written in a computer
language (the source language) into another computer
language (the target language, often having a binary form
known as object code).
• The most common reason for wanting to transform source
code is to create an executable program.
55. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
56. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
HOW C++ WORKS?
https://www.youtube.com/watch?v=ZTu0kf-7h08
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
57. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
ERRORS IN PROGRAMMING
ERRORS
Syntax/
Compile
Run
Time
Logical
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
58. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Error Descriptions Common examples
Syntax
errors/
compile
error
Grammar errors in the
of the programming
language.
Misspelled variable and function names.
Missing semicolons(;)
Improperly matches parentheses, square
], and curly braces{ }
Incorrect format in selection and loop statements
Run time
errors
Occur when a program
with no syntax errors asks
the computer to do
something that the
computer is unable to
reliably do.
Trying to divide by a variable that contains a
of zero
Trying to open a file that doesn't exist
There is no way for the compiler to know about
these kinds of errors when the program is
Logic
errors
Logic errors occur when
there is a design flaw in
your program.
Multiplying when you should be dividing
Adding when you should be subtracting
Opening and using data from the wrong file
Displaying the wrong message
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
59. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
SPECIAL CHARACTERS IN C++ PROGRAMMING SYNTAX
Character Name Meaning
// Double slash Beginning of a comment
# Pound sign Beginning of preprocessor
directive
< > Open/close brackets Enclose filename in #include
( ) Open/close parentheses Used when naming a function
{ } Open/close brace Encloses a group of statements
" " Open/close quotation
marks
Encloses string of characters
; Semicolon End of a programming
statement
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
60. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
WHAT IS DEBUGGING???
• Debugging is the process of locating and fixing or by
passing bugs (errors) in computer program code or
the engineering of a hardware device.
• Debugging is a generalized term which essentially
means to step through a process in order to
systematically eliminate errors.
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
61. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DEBUG PROGRAMS WITH SYNTAX /
COMPILE TIME, RUN TIME AND
LOGICAL ERROR
Do in Lab Activity 1