Introduction to C++ Basics PDF
Document Details
Uploaded by AdoringCouplet
PROF. O. R. VINCENT
Tags
Summary
This document provides an introduction to C++ programming, covering fundamental concepts such as object-oriented programming (OOP), programming style, variable declaration, input/output statements, and other crucial elements.
Full Transcript
Introduction to C++ CSC 201 By PROF. O. R. VINCENT Textbooks: (i) Teach Yourself C++ (Second Edition) by Herbert Schildt (ii) Computer Programming with C++ by Kunal Pimparkhede 1 Programming Styl...
Introduction to C++ CSC 201 By PROF. O. R. VINCENT Textbooks: (i) Teach Yourself C++ (Second Edition) by Herbert Schildt (ii) Computer Programming with C++ by Kunal Pimparkhede 1 Programming Style Input Phase – Variable Declaration of input(s) – Read in input – Initialisation Process Phase – Compute the method Output Phase – Output result 2 Object-oriented programming (OOP) is a programming language organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Examples of objects range from human beings (described by name, address, and so forth) to buildings and floors (whose properties can be described and managed) down to the little 3 The concepts and rules used in object-oriented programming provide these important benefits: i)The concept of a data class makes it possible to define subclasses of data objects that share some or all of the main class characteristics, called inheritance. This property of OOP forces a more thorough data analysis, reduces development time, and ensures more accurate coding. ii) Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids 4 unintended data corruption. iii) The definition of a class is reuseable not only by the program for which it is initially created but also by other object-oriented programs (and, for this reason, can be more easily distributed for use in networks). iv) The concept of data classes allows a programmer to create any new data type that is not already defined in the language itself. Java, Python, C++, Visual Basic.NET and Ruby are the most popular OOP languages today. 5 OOP languages, like C++, share three common defining traits: Encapsulation – Binding code and data Polymorphism- A quality that allows one name to be used for two or more related but technically different purposes Inheritance – Process by which one object can acquire the properties of another 6 In OOP, Header e.g #include Main() Input Stage – Declaration of input(s) e.g int j – Read in input cin >> – Initialisation e.g sum = 0 Process Stage Output stage – Output result e.g cout a; cin >> b >> c; cin >> x; cin >> my-character; 16 Output statements cout