lOMoARcPSD|16501318 Summer training report Data Structures and algorithm (Rajasthan Technical University) StuDocu is not sponsored or endorsed by any college or university Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Summer Training Report On Basic C++ Language Submitted by Abhishek Dubey (18EEJCS002) Under the Supervision of Pratham Pareta Pratham Computer Solutions Jhalawar - 326001 Department of Computer Science and Engineering Engineering College Jhalawar Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 CERTIFICATE This is to certify that the work contained in this Report entitled “Basics Of C++” is submitted by Mr.Abhishek Dubey (18EEJCS002) to the Department of Computer Science and Engineering, Engineering College Jhalawar, for the partial fulfillment of the requirements for the workshop in Computer Science and Engineering. Mr. Pratham Pareta Pratham Computers,Jhalawar Pt. Yogesh Sharma HOD, Department of CSE Engineering College Jhalawar Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Acknowledgment I find great pleasure in expressing our deep sense of gratitude toward all those who have made it possible for me to complete this project with success. I would first of all like to thanks to Department of computer science and information. I would like to thank my teacher for all their support and guidance. I would like to thank Computer Science Department and Pareta Computers who helped me during the Training for providing me the specific guidance in Learning whenever needed. iii Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Contents Acknowledgements iii 1 Introduction 1.1 About C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Application Of C++ . . . . . . . . . . . . . . . . . . . . . . . 3 3 3 2 Data Types & Operators 2.1 Data Types & Their Description . 1.Basic Data Types . . . . . . . . 2. Enumerated types . . . . . . . 3. The Type Void . . . . . . . . . 4. Derived Types . . . . . . . . . 2.2 Operators . . . . . . . . . . . . . 1. Relational Operator . . . . . . 2. Arithmetic Operator . . . . . 3. Logical Operator . . . . . . . . . . . . . . . . 4 4 4 4 4 4 5 5 6 6 3 Flow Of Control 3.1 C++ Loop Types . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 C++ decision making statements . . . . . . . . . . . . . . . . 7 7 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Functions 10 4.1 C++ Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5 Classes and Objects 12 5.1 C++ Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 C++ Class Definitions . . . . . . . . . . . . . . . . . . . . . . 12 Define C++ Objects . . . . . . . . . . . . . . . . . . . . . . . 13 References 14 References 14 iv Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 List of Figures 3.1 3.2 Control Flow Diagram Of Loop . . . . . . . . . . . . . . . . . Control Flow Diagram Of If - else . . . . . . . . . . . . . . . . 1 Downloaded by Yash Mittal (ymittal5277@gmail.com) 7 8 lOMoARcPSD|16501318 List of Tables 2.1 2.2 2.3 Rational Operators . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Operator . . . . . . . . . . . . . . . . . . . . . . . Logical Operator . . . . . . . . . . . . . . . . . . . . . . . . . 5 6 6 3.1 3.2 Loop Statements . . . . . . . . . . . . . . . . . . . . . . . . . Decision Making statements . . . . . . . . . . . . . . . . . . . 8 9 2 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Chapter 1 Introduction 1.1 About C++ 1. C++ is a compiled, object oriented language. 2. It is the “successor ” to c, a procedural language. • The “c++” is called the successor operator in C++. • C++ was developed in the early 1980’s by Bjarne Stroustrup of ATT Bell Labs. 3. C++ is a statically typed, compiled, case-sensitive , free-form programming language that support procedural, object oriented, and generic programming(graphs, arrays). 1.2 Application Of C++ 1. C++ is a versatile (flexible) language for handling very large programs. It is suitable for virtually and programming task including development of editors, compilers, database, communication systems and any complex real-life application systems. 2. Since C++ allows us to create hierarchy-related object, we can build special object-oriented libraries which can be used later by many programmers. 3 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Chapter 2 Data Types & Operators 2.1 Data Types & Their Description 1.Basic Data Types They are arithmetic types and are further classified into: • Integer Type • Floating type 2. Enumerated types They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program. 3. The Type Void The type specifier void indicates that no value is available. 4. Derived Types They include • Pointer types • Array types • Structure types • Union types • Function types 4 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 2.2 Operators 1. Relational Operator Table 2.1: Rational Operators 5 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 2. Arithmetic Operator Table 2.2: Arithmetic Operator 3. Logical Operator Table 2.3: Logical Operator 6 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Chapter 3 Flow Of Control 3.1 C++ Loop Types There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages Figure 3.1: Control Flow Diagram Of Loop 7 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 C++ programming language provides the following type of loops to handle looping requirements. Table 3.1: Loop Statements 3.2 C++ decision making statements Following is the general form of a typical decision making structure found in most of the programming languages Figure 3.2: Control Flow Diagram Of If - else 8 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 C++ programming language provides following types of decision making statements Table 3.2: Decision Making statements 9 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Chapter 4 Functions 4.1 C++ Functions A function is a group of statements that together perform a task. Every C++ program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is such that each function performs a specific task. A function declaration tells the compiler about a function’s name, return type, and parameters. A function definition provides the actual body of the function. The general form of a C++ function definition is as follows 10 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 A C++ function definition consists of a function header and a function body. Here are all the parts of a function • Return Type : A function may return a value. The returnType is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the returnType is the keyword void. • Function Name : This is the actual name of the function. The function name and the parameter list together constitute the function signature. • Parameters : A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters. • Function Body : The function body contains a collection of statements that define what the function does. Example : 11 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 Chapter 5 Classes and Objects 5.1 C++ Classes The main purpose of C++ programming is to add object orientation to the C programming language and classes are the central feature of C++ that supports object-oriented programming and are often called user-defined types. A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class. C++ Class Definitions When you define a class, you define a blueprint for a data type. This doesn’t actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations. 12 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 For example, we defined the Box data type using the keyword class as follows The keyword public determines the access attributes of the members of the class that follows it. A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private or protected which we will discuss in a sub-section. Define C++ Objects A class provides the blueprints for objects, so basically an object is created from a class. We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types. Following statements declare two objects of class Box Both of the objects Box1 and Box2 will have their own copy of data members. 13 Downloaded by Yash Mittal (ymittal5277@gmail.com) lOMoARcPSD|16501318 References [1] https://www.tutorialspoint.com/cplusplus/index.htm [2] www.w3schools.com [3] The C++ Programming Language by Bjarne Stroustrup 14 Downloaded by Yash Mittal (ymittal5277@gmail.com)