--Your friends at LectureNotes

Note for Object Oriented Programming Using Cpp - OOP By Koushik Sen

  • Object Oriented Programming Using Cpp - OOP
  • Note
  • Vijaya college of engineering - Jntuh
  • 11 Topics
  • Uploaded 1 year ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

C++ INDEX Introduction: Instructions for use Basics of C++: Structure of a program Variables. Data Types. Constants Operators Basic Input/Output Control Structures: Control Structures Functions (I) Functions (II) Compound Data Types: Arrays Character Sequences Pointers Dynamic Memory Data Structures Other Data Types Object Oriented Programming: Classes (I) Classes (II) Friendship and inheritance Polymorphism Advanced Concepts: Templates Namespaces Exceptions Type Casting Preprocessor directives C++ Standard Library: Input/Output with files VIJAYA COLLEGE Page 1

Text from page-2

C++ What is C, What is C++, and What is the Difference? C is a programming language originally developed for developing the Unix operating system. It is a low-level and powerful language, but it lacks many modern and useful constructs. C++ is a newer language, based on C, that adds many more modern programming language features that make it easier to program than C. Basically, C++ maintains all aspects of the C language, while providing new features to programmers that make it easier to write useful and sophisticated programs. For example, C++ makes it easier to manage memory and adds several features to allow "object-oriented" programming and "generic" programming. Basically, it makes it easier for programmers to stop thinking about the nitty-gritty details of how the machine works and think about the problems they are trying to solve. So, what is C++ used for? C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++. How do you learn C++? No special knowledge is needed to learn C++, and if you are an independent learner, you can probably learn C++ from online tutorials or from books. There are plenty of free tutorials online, including Cprogramming.com's C++ tutorial - one which requires no prior programming experience. You can also pick out programming books from our recommendations. While reading a tutorial or a book, it is often helpful to type - not copy and paste (even if you can!) - the code into the compiler and run it. Typing it yourself will help you to get used to the typical typing errors that cause problems and it will force you to pay attention to the details of programming syntax. Typing your program will also familiarize you with the general structure of programs and with the use of common commands. After running an example program - and after making certain that you understand how it works - you should experiment with VIJAYA COLLEGE Page 2

Text from page-3

C++ it: play with the program and test your own ideas. By seeing which modifications cause problems and which sections of the code are most important to the function of the program, you should learn quite a bit about programming. Try our C++ Beginner to C++ Expert recommended book series, a sixbook set designed to get you maximal information and help take you from beginner to C++ master. You may also want to read about The 5 Most Common Problems New Programmers Face--And How You Can Solve Them. What do you need to program in C or C++? In order to make usable programs in C or C++, you will need a compiler. A compiler converts source code - the actual instructions typed by the programmer - into an executable file. Numerous compilers are available for C and C++. Listed on the sidebar are several pages with information on specific compilers. For beginners, Code::Blocks is our recommended free and easy-to-use compiler. Do I need to know C to learn C++? No. C++ is a superset of C; (almost) anything you can do in C, you can do in C++. If you already know C, you will easily adapt to the object-oriented features of C++. If you don't know C, you will have to learn the syntax of C-style languages while learning C++, but you shouldn't have any conceptual difficulties. BASICS OF C++ 1. Structure of a program 2. 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++ Hello World! #include <iostream> using namespace std; VIJAYA COLLEGE Page 3

Text from page-4

int main () { cout << "Hello World!"; return 0; } C++ The first panel shows the source code for our first program. The second one shows the result of the program once compiled and executed. The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program. The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written: // my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is. #include <iostream> Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program. using namespace std; All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. VIJAYA COLLEGE Page 4

Lecture Notes