You are on page 1of 36

“C++ PROGRAMMING”

AN
INDUSTRIAL TRAINING REPORT
Submitted
In partial fulfillment
for the award of the degree of

Bachelor of Technology
In Department of Computer Science & Engineering

SUBMITTED TO: - SUBMITTED BY: -


Mr. Toofan Mukherjee NAME: Chitrank Shukla
HOD(CSE Department), Roll No.-19ESBCS006
SBCET, Jaipur

Department of Computer Science and


Engineering Sri Balaji College of Engineering and
Technology Rajasthan Technical University, Kota
December, 2022
ACKNOWLEDGEMENT

I acknowledge the contribution of all those individuals who have support and
encouraged me in carrying out this work.
First and foremost, I express my sincere gratitude to Mr. Toofan Mukherjee,
Head of Department, Department of Computer Science & Engineering, Sri
Balaji College of Engineering & Technology, Jaipur for his inspiration,
encouragement & support provided by him whenever I needed it. His keen
interest and timely suggestion with kindness help me at every stage of this
dissertation.
I express my thanks to Dr. (Engg.) I.P. Meel, Principal, and Dr. Surendra
Choudhary, Vice Principal, Sri Balaji College of Engineering & Technology,
Jaipur for extending support.
I thank to all the faculty member of department of computer science and
engineering profusely for their kind help and Co-operation. I am incredibly
thankful to all my friends for their help, moral support and their valuable
suggestions. Most importantly I good like to thanks my family, my brother and
other supporting person for their unconditional support.

Name: Chitrank Shukla


Roll no: 19ESBCS006

i
CANDIDATE’S DECLARATION

I hereby declare that I have given the whole introduction and technologies with
conclusion of python and it is a record of an original work done by me under the
guidance of Mr. Toofan Mukherjee Head Of Department, Dept of Computer
Science and Engineering, Sri Balaji College of Engineering and Technology,
and this project work will be submitted in the partial fulfilment of the
requirements for the award of the degree of Bachelor of Technology in
Computer Science and Engineering.

Name: Chitrank Shukla


Roll Number: 19ESBCS006
Branch: CSE
Sri Balaji College of Engineering and Technology

Counter Signed by
Mr.Toofan Mukherjee
HOD (CSE Department)
SBCET, Jaipur

ii
CERTIFICATE

iii
List of Content
Title Page No
1. Acknowledgement i
2. Candidate Declaration ii
3. Certificate iii
4. List of Content iv
5. Abstract 1
6. Introduction of Robotics 2
7.Classification of Robots 3
8.The Main Parts of Robots 8
9. Robot Architectures 15
10. Connection Between Robotics and some Related 25
Subjects
11. Conclusion 32
33
12.Reference

iv
ABSTRACT

I am a student of Engineering College, Ajmer and studying in CSE 7 th semester. As a part of our degree we
have undergone in a training process for 45 days.

Present is the age of computers and technologies. Practical knowledge has its own importance. Without practical
knowledge one cannot be specialized in one’s field. We have automated the practical knowledge of institutes and
their working in the project.

5
CONTENTS

S. No Content Page No.


1 Brief history of C 5
2 Data types in C 6
3 Operations in C 9
4 Types of loop 11
5 C-Functions 12
6 Pointers
7 File Handling in C 14
8 OOP-Introduction 16
9 Constructor and 18
Destructor

10 Inheritance 23
11 Polymorphism 26
12 Exception Handling 29
in C++
13 Templates in C++ 30
14 File Handling in C++ 31

6
Brief History of C Programming Language

C is a general-purpose programming language which features economy of


expression, modern control flow and data structures, and a rich set of operators.
C is not a "very high level" language, nor a "big" one, and is not specialized to
any particular area of application. But its absence of restrictions and its
generality make it more convenient and effective for many tasks than
supposedly more powerfullanguages.
ThehistoryofCprogramminglanguageis quiteinteresting.Cwasoriginally
designedforandimplementedontheUNIXoperatingsystemontheDEC PDP-ll,
byDennis Ritchie. C isthe result of a development process that
startedwithanolderlanguagecalledBCPL.BCPLwasdevelopedbyMartin
Richards,anditinfluencedalanguagecalledB,whichwasinventedbyKen
Thompson.B ledto thedevelopmentof C inthe1970s.
Formanyyears,thedefactostandardforCwastheversionsuppliedwith the
UNIXoperating system. In thesummer of 1983 a committee was established to
create an ANSI (American National Standards Institute) standard that would
define the C language. The standardizationprocess took six years (much longer
thananyonereasonably expected).
TheANSIC standardwas finallyadoptedinDecember1989

7
Constants and Variables in C language

:Constant
As the name suggests the name constants is given to such variables or values in C
programming language which cannot be modified once they are defined. They are fixed
values in a program. There can be any types of constants like integer, float, octal,
hexadecimal, character constants etc. Every constant has some range. The integers that are
too big to fit into an int will be taken as a long. Now there are various ranges that differ
from unsigned to signed bits. Under the signed bit, the range of an int varies from -128 to
+127 and under the unsigned bit, int varies from 0 to 255.

Variables in c

In programming, a variable is a container (storage area) to hold data.

To indicate the storage area, each variable should be given a unique name (identifier). Variable
names are just the symbolic representation of a memory location

Data types in C Language


Data types specify how we enter data into our programs and what type of data we enter. C language has
some predefined set of data types to handle various kinds of data that we canuse in our
program. These datatypes have different storage capacities.
C language supports 2 different type of data types:

1. Primary datatypes:

ThesearefundamentaldatatypesinCnamelyinteger(int),floatingpoint(float),
character(char) and void.

2. Derived datatypes:

8
Derived data types are nothing but primary datatypes but a little twisted or grouped together
like array, stucture, union and pointer. These are discussed in details later.
Data type determines the type of data a variable will hold. If a variable xis declared as int. it
means x can hold only integer values. Every variable which is used in the program mustbe
declared as what data-type itis.

Integer type:
Integers are used to store whole numbers.

Size and range of Integer type on 16-bit machine:

Type Size(bytes) Range

int or signed int 2 -32,768 to 32767

unsigned int 2 0 to 65535

short int or signed short int 1 -128 to 127

unsigned short int 1 0 to 255

long int or signed long int 4 -2,147,483,648 to 2,147,483,647

unsigned long int 4 0 to 4,294,967,295

9
Floating point type:
Floating types are used to store real numbers.
Size and range of Integer type on 16-bit machine

Type Size(bytes) Range

Float 4 3.4E-38 to 3.4E+38

Double 8 1.7E-308 to 1.7E+308

long double 10 3.4E-4932 to 1.1E+4932

Character type:
Character types are used to store characters value.
Size and range of Integer type on 16-bit machine

Type Size(bytes) Range

char or signed char 1 -128 to 127

unsigned char 1 0 to 255

void type:
voidtype means no value. This is usually used to specify the type of functions which returns nothing. We will get
acquainted to this datatype as we start learning more advanced topics in C language, like functions, pointers etc.

10
C Programming Operators
 C ArithmeticOperators

An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc
on numerical values (constants and variables).

 C Increment and DecrementOperators


Cprogramminghastwooperatorsincrement++anddecrement--tochangethevalueofanoperand (constant or
variable) by1.
Increment ++increases the value by 1 whereas decrement --decreases the value by 1. These two operators are
unary operators, meaning they only operate on a single operand.

 C Assignment Operators
An assignment operator is used for assigning a value to a variable. The most common assignment operator is =
 C Relational Operators

A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the
relation is false, it returns value 0.

 C LogicalOperators
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or
false. Logical operators are commonly used in decision making in C programming.

Oper Meaning Example


ator
If c = 5 and d = 2 then, expression ((c==5)
Logical AND. True only if all operands are
&& (d>5)) equals to 0.
&& true

Logical OR. True only if either one Ifc=5andd=2then,expression((c==5)||


|| operand is true (d>5)) equals to1.

! Logical NOT. True only if the operand is 0

11
C Bitwise Operators

During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted
to bit-level which makes processing faster and saves power.

Bitwise operators are used in C programming to perform bit-level operations.

Opera Meaning of
tors operators
& Bitwise AND

| Bitwise OR

^ Bitwise exclusive OR

~ Bitwise complement

<< Shift left

>> Shift right

12
TYPES OF LOOP CONTROL STATEMENTS IN C:
There are 3 types of loop control statements in C language. They are,

1. for
2. while
3. do-while
Syntax for each C loop control statements are given in below table with description.

Loop Name Syntax

for (exp1; exp2; expr3)


{ statements; }Where,
exp1 – variable initialization ( Example: i=0, j=2, k=3 ) exp
( Example: i>5, j<3, k=3 ) exp3 – increment/decrement
( Example: ++i, j–, ++k )

For

while (condition)
{ statements; }where, condition might be a>5, i<10
While

do { statements; }
while (condition);where, condition might be a>5, i<10
do while

ARRAY-
Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An
array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables
of the sametype.

13
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array
variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables.
A specific element in an array is accessed by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the
highest address to the last element.

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 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 C standard library provides numerous built-in functions that your program can
call. For example, strcat

14
What are Pointers?
A pointer is a variable whose value is the address of another variable, i.e.,
direct address of the memory location. Like any variable or constant, you
must declare a pointer before using it to store any variable address. The
general form of a pointer variable declaration is −
type *var-name;
Here, type is the pointer's base type; it must be a valid C data type andvar-
name is the name of the pointer variable. The asterisk * used to declare a
pointer is the same asterisk used for multiplication. However, in this
statement the asterisk is being used to designate a variable as a pointer.
Take a look at some of the valid pointer declarations−
int *ip; /* pointer to an integer */
doubl *dp; /* pointer to a double */
e
float *fp; /* pointer to a float */
char *ch /* pointer to a character */
The actual data type of the value of all pointers, whether integer, float,
character, or otherwise, is the same, a long hexadecimal number that
represents a memory address. The only difference between pointers of
different data types is the data type of the variable or constant that the
pointer points to.

15
() to concatenate two strings, memcpy() to copy one memory location to another location, and many more
functions.
A function can also be referred as a method or a sub-routine or a procedure, etc.

Basics of File Handling in C


So far the operations using C program are done on a prompt / terminal which is not stored anywhere. But in the software
industry, most of the programs are written to store the information fetched from the program. One such way is to store the
fetched information in a file. Different operations that can be performed on a file are:

1. Creation of a new file (fopen with attributes as “a” or “a+” or “w” or“w++”)
2. Opening an existing file(fopen)
3. Reading from file (fscanf orfgetc)
4. Writing to a file (fprintf orfputs)
5. Moving to a specific location in a file (fseek,rewind)
6. Closing a file (fclose)
7. FILE*filePointer;
8. So, the file can be openedas
9. filePointer = fopen(“fileName.txt”,“w”)
opening a file

FILE * filePointer;
filePointer = fopen(“fileName.txt”, “r”);
fscanf(filePointer,"%s%s%s%d",str1,str2,str3,&year);
writing a file

FILE *filePointer;
filePointer = fopen(“fileName.txt”, “w”);
fprintf(filePointer, "%s %s %s %d", "We", "are", "in", 2012);

16
WhyC++?
• PnpuIoF and relevant (used in nearly every applicationdomain):
— end-user applications (Word, Encel, PowerPoint, Photoshop, Acrobat,
Quicken,games)
opemtingsystem(Windows9x,NT,XP,IBM’sK4t,sonicAppleOSX) larg ale
web servers/apps (Amazon,Google)
— central datahase control (Israel’s census bureau; Amsdeus;Morgan-
$tsnIeyfinanciaJmadeiing)
tontmurtitations(Alcatel;Noida;800telephonenumbers;rriajortrRrtsntission
codes in Germany andFrantet
— numerical / graphics (Maya)
device drivers under real-timetortstrairits
• Stablt, cDMpatible,scalable

• C++ is Cincremented
• C-1-+ is moreexpressive
(yewer C++ suuzcc lines needed than C souzcelincs for same program)

(an¿4hing you can do in C can also be done in C-i-+)


• Cm can be just ase,tJicien›
(mostC++ expressions need no run-time support,
C-+-+ allows ¿’ou to
— ntanlpulatebitsdirectlyandInterfacewithbard»'are»'ltbootregardforcfc
or ease ofcoropcebeaszoo.BUT
— bidetbesedetailsbebiadasafe,cleao,elegantiatez•face)
• C++ is moremaintainable
(/#00 liuecnfcnde— even brute force, spaghetticode will work,
700 000 lines of z'ode— nced good stzuctuze, or new czzors will be
introduced as quictd¿' as old errors are removed)

17
What is OOPS?
Object Oriented Programming is a programming concept that works on the principle that objects are
the most important part of your program. It allows users create the objects that they want and then
create methods to handle those objects. Manipulating these objects to get results is the goal of Object
Oriented Programming.

Object Oriented Programming popularly known as OOP, is used in a modern programming language
like Java

1) Class
2) Object
3) Inheritance
4) Polymorphism
5) Encapsulation
18
1) Class
The class is a group of similar entities. It is only an logical component and not the physical
entity. For example, if you had a class called “Expensive Cars” it could have objects like
Mercedes, BMW, Toyota, etc. Its properties(data) can be price or speed of these cars.
While the methods may be performed with these cars are driving, reverse, braking etc.

2) Object

An object can be defined as an instance of a class, and there can be multiple instances of a class in
a program. An Object contains both the data and the function, which operates on the data. For
example - chair, bike, marker, pen, table, car, etc.

3) Inheritance

Inheritance is an OOPS concept in which one object acquires the properties and behaviors of the
parent object. It’s creating a parent-child relationship between two classes. It offers robust and
natural mechanism for organizing and structure of any software.

4) Polymorphism

Polymorphism refers to the ability of a variable, object or function to take on multiple forms. For
example, in English, the verb run has a different meaning if you use it with a laptop, a foot race, and
business. Here, we understand the meaning of run based on the other words used along with it.The
same also applied to Polymorphism.

5) Encapsulation

Encapsulation is an OOP technique of wrapping the data and code. In this OOPS concept, the
variables of a class are always hidden from other classes. It can only be accessed using the methods of
their current class. For example - in school, a student cannot exist without a class.

19
Constructors and Destructors in C++
Constructors are special class functions which performs initialization of every object. The Compiler callsthe
Constructor whenever an object is created. Constructors initialize values to object members after storage is
allocated to theobject.
Whereas, Destructor on the other hand is used to destroy the class object.
While defining a contructor you must remeber that the name of constructor will be same as the name of the
class, and contructors will never have a return type.
Constructorscanbedefinedeitherinsidetheclassdefinitionoroutsideclassdefinitionusingclassname and scope
resolution ::operator.

Types of Constructors in C++


Constructors are of three types:

1. DefaultConstructor
2. ParametrizedConstructor
3. CopyCOnstructor

20
Default Constructors
Default constructor is the constructor which doesn't take any argument. It has no parameter.

Syntax:

class_name(parameter1, parameter2, ...)


{
// constructorDefinition
}

Parameterized Constructors
These are the constructors with parameter. Using this Constructor you can provide different values
to data members of different objects, by passing the appropriate values as argument.

Copy Constructors
These are special type of Constructors which takes an object as argument, and is used to copy
values of data members of one object into other object. We will study copyconstructorsin detail
later.

Destructors in C++
Destructor is a special class function which destroys the object as soon as the scope of object ends.
The destructor is called automatically by the compiler when the object goes out of scope.
Destructor will not have any argument.
The syntax for destructor is same as that for the constructor, the class name is used for the name of
destructor, with a tilde ~sign as prefix to it.
classA
{
public:
// defining destructor for class
~A()
{
//statement
}
}

21
22
23
C++ functionmechanisms
• O›’erloaded functionnames
— Cleaner aitd safer
p:c1n6 (1n6) ,prlnc (Z1 oak I iBut hewnre
print{int}; print(int*}: print(0}:
• Defaultparameters
void print(int a, int b-D, int c-0):
• Operatoroverloading
Mstrix& operator+-(const Mstrix&other}:
• Implicit cons'ersionoperator
operator[nt() coneD(| // converts tDint
Provides cnnvenient syntax, but potentially dangerous so use sparingly

Namespaces
• Namespace expresses logicalgrouping
• uginqdeclaration
— Don’t use global usr.ng except for transition to
oldercode
— Ok in nsmespscetiircomposition
— Ok in t“unction for notsGonalconx'enience
• Namespaces areopen
• Unnamed namespaces restrict code to local
translationunit
• Aliases ( namespaceShortName= LongName;)

24
C++ Inheritance

In C++, inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In
such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class.

In C++, the class which inherits the members of another class is called derived class and the classwhose members are inherited is
called base class. The derived class is the specialized class for the baseclass.

Advantage of C++ Inheritance


Code reusability: Now you can reuse the members of your parent class. So, there is no need to define the member again. So, less
code is required in the class.

25
Types of Inheritance

C++ supports five types of inheritance:

o Single inheritance
o Multipleinheritance
o Hierarchicalinheritance
o Multilevelinheritance
o Hybridinheritance

C++ Single Inheritance


Single inheritance is defined as the inheritance in which a derived class is inherited from the only one base class.

Where 'A' is the base class, and 'B' is the derived class.

C++ Multilevel Inheritance


Multilevel inheritance is a process of deriving a class from another derived class.

C++ Multiple Inheritance

Multiple inheritance is the process of deriving a new class that inherits the attributes from two or more classes.

26
C++ Hybrid Inheritance
Hybrid inheritance is a combination of more than one type of inheritance.

C++ Hierarchical Inheritance


Hierarchical inheritance is defined as the process of deriving more than one class from a base class.

27
Polymorphism in C++

The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of
classes and they are related by inheritance.
C++ polymorphism means that a call to a member function will cause a different function to be executed
depending on the type of object that invokes the function.

28
Virtual Function
A virtual function is a function in a base class that is declared using the keyword virtual. Defining in a base class
a virtual function, with another version in a derived class, signals to the compiler that we don't want static linkage
for thisfunction.
What we do want is the selection of the function to be called at any given point in the program to be based on the
kind of object for which it is called. This sort of operation is referred to as dynamic linkage, or late binding.

29
30
Pure Virtual Functions
It is possible that you want to include a virtual function in a base class so that it may be redefined in a derived
class to suit the objects of that class, but that there is no meaningful definition you could give for the function in
the baseclass.

One of the advantages of C++ over C is Exception Handling. Exceptions are run-time anomalies or abnormal conditions that a
program encounters during its execution. There are two types of exceptions: a) Synchronous, b) Asynchronous(Ex:which are
beyond the program’s control, Disc failure etc.). C++ provides following specialized keywords for this purpose.

try: represents a block of code that can throw an exception.


catch: represents a block of code that is executed when a particular exception is thrown. throw:
Used to throw an exception. Also used to list the exceptions that a function throws, but doesn’t
handle itself.

31
- -
Templates in C++
A template is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a parameter so
that we don’t need to write the same code for different data types. For example, a software company may need
sort() for different data types. Rather than writing and maintaining the multiple codes, we can write one sort() and
pass data type as a parameter.
C++ adds two new keywords to support templates: ‘template’ and ‘typename’. The second keyword can always be
replaced by keyword ‘class’.
How templates work?
Templates are expanded at compiler time. This is like macros. The difference is, compiler does type checking
before template expansion. The idea is simple, source code contains only function/class, but compiled code may
contain multiple copies of same function/class.

32
File Handling through C++ Classes

In C++, files are mainly dealt by using three classes fstream, ifstream, ofstream available in fstream header file.
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.
Now the first step to open the particular file for read or write operation. We can open file by
1. passing file name in constructor at the time of objectcreation
2. using the openmethod
For e.g.
Open File by using constructor
ifstream (const char* filename, ios_base::openmode mode = ios_base::in);
ifstream fin(filename, openmode) by default openmode = ios::in
ifstream fin(“filename”);

Open File by using open method


Calling of default constructor ifstream
fin;

33
fin.open(filename, openmode)
fin.open(“filename”);

END OF REPORT

1
2

You might also like