Computer Programming Reviewer (Faa_BSIT- IT11S11) PDF

Summary

This document provides an introduction to computer programming, focusing on C++. It covers fundamental concepts including what is a computer or programming, and what is programming.

Full Transcript

Introduction to Computer Programming What is a computer or program? ​ A computer or a program is a sequence of statements whose objectives is to accomplish a task. What is programming? ​ Programming is a process of planning and creating a program. ​...

Introduction to Computer Programming What is a computer or program? ​ A computer or a program is a sequence of statements whose objectives is to accomplish a task. What is programming? ​ Programming is a process of planning and creating a program. ​ C++ is a portable language that works equally well on Microsoft Windows, Apple Mac OS, Linux and Unix systems which was developed by Bjarne Stroustrup (B-yar-ne Stro-stroop) ​ Bjarne Stroustrup (B-yar-ne Stro-stroop), a Danish computer scientist at Bell Labs in the United States What is C++ ? ​ C++ is based on C and it retains much of that language, including a rich operator set. ​ C++ is a highly portable language, and translators for it exist on many different machines and systems. ​ C++ compilers are highly compatible with the existing C programs because maintaining such compatibility was a design objective. ​ Programming in C++ does not require a graphics environment, and C++ programs do not incur runtime expense from type checking or garbage collection. ​ C++ has improved on C in significant ways, especially in supporting strong typing. ​ The class syntax was added to the language which was an extension of the struct construct in C. ​ C++ is superior than C in supporting object-oriented programming. C++ may even replace C in becoming a general purpose programming language. ​ C++ program is a collection of functions. ​ Every C++ program has a function called main. ​ OOP (Object-Oriented Programming): C++ is an object-oriented language, unlike C which is a procedural language. This is one of the most important features of C++. It employs the use of objects while programming. ​ Platform or Machine Independent/ Portable: In simple terms, portability refers to using the same piece of code in varied environments. C++ is ultra portable and has compilers available on more platforms than you can shake a stick at. Languages like Java are typically touted as being massively cross platform, ironically they are in fact usually implemented in C++, or C ​ Simple: When we start off with a new language, we expect to understand in depth. The simple context of C++ gives an appeal to programmers, who are eager to learn a new programming language. ​ Mid-level programming language: C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. It is a superset of C, and that virtually any legal C program is a legal C++ program. ​ Case sensitive: Just like C, it is pretty clear that the C++ programming language treats the uppercase and lowercase characters in a different manner. ​ Compiler-Based: Unlike Java and Python that are interpreter-based, C++ is a compiler based language and hence it a relatively much faster than Python and Java. ​ DMA (Dynamic Memory Allocation): Since C++ supports the use of pointers, it allows us to allocate memory dynamically. We may even use constructors and destructors while working with classes and objects in C++. ​ Rich Library: The C++ programming language offers a library full of in-built functions that make things easy for the programmer. These functions can be accessed by including suitable header files. ​ Fast: C++ is compiler-based hence it is much faster than other programming languages like Python and Java that are interpreter-based. ​ Recursion: When function is called within the same function, it is known as recursion in C++. The function which calls the same function, is known as recursive function Comments in C++ 1.​ Single-line Comment: Starts with //, ignored by the compiler. ○​ Example: // my first program in C++ 2.​ Multi-line Comment: Enclosed between , ignored by the compiler. ○​ Example: C/C++ Line 2: #include 1.​ Preprocessor Directive: Starts with # and is processed before compilation. 2.​ #include : Includes the iostream library for input (cin) and output (cout). Line 3: using namespace std; 1.​ Namespace: Identifies where to find standard library elements. 2.​ Avoids errors when using cout, cin, endl, etc. ○​ Example without it: std::cout. Line 4: int main() 1.​ Function Declaration: Declares the main function where the program execution starts. 2.​ Special Function: All C++ programs begin execution with main. Lines 5 and 7: { and } 1.​ Braces: Enclose the body of the function. ○​ { indicates the start. ○​ } indicates the end. Line 6: cout

Use Quizgecko on...
Browser
Browser