You are on page 1of 20

C & C++ Programming

Board Infinity

A training report

Submitted in partial fulfillment of the requirements for the award of degree of

Bachelor of Technology

(Computer Science and Engineering)

Submitted to

LOVELY PROFESSIONAL UNIVERSITY

PHAGWARA, PUNJAB

From 06/01/22 to 07/01/22

SUBMITTED BY Anuj Kumar

Name of student: Anuj Kumar


Registration number: 12020641 1
Student Declaration

To whom so ever it may concern

I, Anuj Kumar, 12020641, hereby declare that the work done by me on “C&C++
Programming” from June 2022 to July 2022, is a record of original work for the partial
fulfillment of the requirements for the award of the degree, Bachelor of Technology.

2
ACKNOWLEDGEMENT

Primarily I would like to thank God for being able to learn a new technology. Then I would
like to express my special thanks of gratitude to the teacher and instructor of the course
C&C++ programming from Board infinity who provide me the golden opportunity to learn
a new technology from home.

I would like to also thank my own college Lovely Professional University for offering such
a course which not only improve my programming skill but also taught me other new
technology.

Then I would like to thank my parents and friends who have helped me with their valuable
suggestions and guidance for choosing this course.

Last but not least I would like to thank my all classmates who have helped me a lot.

3
Summer Training Certificate

4
lOMoARcPSD|167 258 01

Contents

Acknowledgements iii

1 Introduction 8
1.1 About C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Application Of C++ . . . . . . . . . . . . . . . . . . . . . . . 8

2 Data Types & Operators 9


2.1 Data Types & Their Description . . . . . . . . . . . . . . . . . 9
1.Basic Data Types . . . . . . . . . . . . . . . . . . . . . . . . 9
2. Enumerated types . . . . . . . . . . . . . . . . . . . . . . . 9
3. The Type Void . . . . . . . . . . . . . . . . . . . . . . . . . 9
4. Derived Types . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1. Relational Operator . . . . . . . . . . . . . . . . . . . . . . 10
2. Arithmetic Operator . . . . . . . . . . . . . . . . . . . . . 11
3. Logical Operator . . . . . . . . . . . . . . . . . . . . . . . 11

3 Flow Of Control 12
3.1 C++ Loop Types . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 C++ decision making statements . . . . . . . . . . . . . . . . 13

4 Functions 15
4.1 C++ Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5 Classes and Objects 17


5.1 C++ Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
C++ Class Definitions . . . . . . . . . . . . . . . . . . . . . . 17
Define C++ Objects . . . . . . . . . . . . . . . . . . . . . . . 18

References 19

References 19

iv

5
lOMoARcPSD|167 258 01

List of Figures

3.1 Control Flow Diagram Of Loop ................................................. 13


3.2 Control Flow Diagram Of If - else ............................................. 14

6
Downloaded by Magneto?V?X (maggislove18@gmail.com)
lOMoARcPSD|167 258 01

List of Tables

2.1 Rational Operators .......................................................................... 10


2.2 Arithmetic Operator ........................................................................ 11
2.3 Logical Operator .............................................................................. 11

3.1 Loop Statements . . . . . . . . . . . . . . . . . . . . . . . . . 13


3.2 Decision Making statements . . . . . . . . . . . . . . . . . . . 14

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

7
lOMoARcPSD|167 258 01

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 program-


ming 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 com-
plex 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 pro-
grammers.

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

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

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

2.2 Operators
1. Relational Operator

Table 2.1: Rational Operators

10

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

2. Arithmetic Operator

Table 2.2: Arithmetic Operator

3. Logical Operator

Table 2.3: Logical Operator

11

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

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

12

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

C++ programming language provides the following type of loops to han-


dle 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

13

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

C++ programming language provides following types of decision making


statements

Table 3.2: Decision Making statements

14

Downloaded by Magneto?V?X (maggislove1 8@gmail.com)


lOMoARcPSD|167 258 01

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

15

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

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

16

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

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 rep-
resentation 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

17

Downloaded by Magneto?V?X (maggislove18@gmail.com)


lOMoARcPSD|167 258 01

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

18

Downloaded by Magneto?V?X (maggislove18@gmail.com )


lOMoARcPSD|167 258 01

References

[1] https://www.tutorialspoint.com/cplusplus/index.htm

[2] www.w3schools.com

[3] The C++ Programming Language by Board infinity.

14

19

Downloaded by Magneto?V?X (maggislove18@gmail.com)

You might also like