1664651116711C With C - Training Report - 40 Pages
1664651116711C With C - Training Report - 40 Pages
ON
C with C++
COMPLETED AT
YCT Academy, BHOPAL
BY
xxxxxxxxxx
ROLL NO. 0110CSE15GT007
While working on this project, their patience and valuable hints helped us in
sailing through the rough seas. They were generous enough to lend us their time,
experience and expertise.
We also acknowledge, with great thanks, our Head of the Centre and Program
Coordinator Mr.Pankaj Panjwani for their encouragement and suggestions that we
were provided at different stages while working on this project and all the staff
members of our department for all the help that they have extended to us.
Last but not the least, we are also thankful to all our friends without whose
help this process would have been unexpectedly protracted and the meeting of
deadlines would have been impossible.
xxxxxxxxxx
TABLE OF CONTENTS
1. Abstract ………….………………………………………… .
2. Introduction of Training……………………………………….
3. Introduction of the Organization..…………………………….
4. Training Details (with topics)………………………………….
Module 1: ………………………………………………
Module 2:………………………………………………
Module 3:………………………………………………….
Module 4:………………………………………………
5. Conclusion………………………………………………………..
6. Bibliography……………………………………………………..
1. ABSTRACT
This report discusses the training program at YCT Academy. It states the
concept of C and C++.
The purpose of industrial Training is to provide exposure for the students on practical
engineering fields. Through this exposure, students will have better understanding of engineering
practical in general and sense of frequent and possible problems. This training is part of learning
process. So the exposure that uplifts the knowledge and experience of a student needs to be
properly documented in the form of a report. Through this report, the experience gained can be
delivered to their peers. A properly prepared report can facilitate the presentation of the practical
experience in an orderly, precise and interesting manner.
I have chosen C and C++ as my training because it will help me in several ways. I have chosen
my languages course in C++ and by having little bit knowledge in this Subject will help me in
carrier growth. During learning this I came to understand much more concepts of other language.
A competence to design, write, compile, test and execute straightforward programs using a high level
language;
An awareness of the need for a professional approach to design and the importance of good
documentation to the finished programs
Description:
It is founded on 12th Aug 2014.YCT Academy also known as Your Computer Teacher Academy
providing best training to engineering candidate in almost all the branches ,so students gets
campus selected in various Organization like Microsoft, MicoBosch, IBM,L
&T ,Mahindra ,HCL,TCS,MUSIGMA,SINTEL,WIPRO INFOTECH. ETC.
.NET
PHP
C/C++
CORE JAVA
ADVANCED JAVA
ORACLE
ANDROID
MINOR/MAJOR/LIVE PROJECTS
EMBEDDED SYSTEM
Soft Skills
AUTOCAD
4. TRAINING CONTENT
Module 1
What is C Language
The C Language is developed for creating system applications that directly interact with the
hardware devices such as drivers, kernels, etc.
C programming is considered as the base for other programming languages, that is why it is
known as mother language.
History of C Language
First C Program
To write the first c program, open the C console and write the following code:
1. #include <stdio.h>
2. int main(){
3. printf("Hello C Language");
4. return 0;
5. }
Variables in C
A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be
reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
1. type variable_list;
The example of declaring the variable is given below:
1. int a;
2. float b;
3. char c;
Data Types in C
A data type specifies the type of data that a variable can store such as integer, floating, character,
etc.
Keywords in C
A keyword is a reserved word. You cannot use it as a variable name, constant name, etc. There
are only 32 reserved words (keywords) in the C language.
C Operators
An operator is simply a symbol that is used to perform operations. There can
be many types of operations like arithmetic, logical, bitwise, etc.
o Arithmetic Operators
o Relational Operators
o Shift Operators
o Logical Operators
o Bitwise Operators
o Ternary or Conditional Operators
o Assignment Operator
o Misc Operator
Precedence of Operators in C
The precedence of operator species that which operator will be evaluated
first and next. The associativity specifies the operator direction to be
evaluated; it may be left to right or right to left.
1. int value=10+20*10;
\a Alarm or Beep
\b Backspace
\f Form Feed
\n New Line
\r Carriage Return
\t Tab (Horizontal)
\v Vertical Tab
\\ Backslash
\0 Null
C Control Statements
If Statement
The if statement is used to check some given condition and perform some
operations depending upon the correctness of that condition. It is mostly
used in the scenario where we need to perform the different operations for
the different conditions. The syntax of the if statement is given below.
1. if(expression){
2. //code to be executed
3. }
1. #include<stdio.h>
2. int main(){
3. int number=0;
4. printf("Enter a number:");
5. scanf("%d",&number);
6. if(number%2==0){
7. printf("%d is even number",number);
8. }
9. return 0;
10. }
Output
Enter a number:4
4 is even number
enter a number:5
If-else Statement
The if-else statement is used to perform two operations for a single
condition. The if-else statement is an extension to the if statement using
which, we can perform two different operations, i.e., one is for the
correctness of that condition, and the other is for the incorrectness of the
condition. Here, we must notice that if and else block cannot be executed
simiulteneously. Using if-else statement is always preferable since it always
invokes an otherwise case with every if condition. The syntax of the if-else
statement is given below.
1. if(expression){
2. //code to be executed if condition is true
3. }else{
4. //code to be executed if condition is false
5. }
Let's see the simple example to check whether a number is even or odd
using if-else statement in C language.
1. #include<stdio.h>
2. int main(){
3. int number=0;
4. printf("enter a number:");
5. scanf("%d",&number);
6. if(number%2==0){
7. printf("%d is even number",number);
8. }
9. else{
10. printf("%d is odd number",number);
11. }
12. return 0;
13. }
Output
enter a number:4
4 is even number
If else-if ladder Statement
1. if(condition1){
2. //code to be executed if condition1 is true
3. }else if(condition2){
4. //code to be executed if condition2 is true
5. }
6. else if(condition3){
7. //code to be executed if condition3 is true
8. }
9. ...
10. else{
11. //code to be executed if all the conditions are false
12. }
1. #include<stdio.h>
2. int main(){
3. int number=0;
4. printf("enter a number:");
5. scanf("%d",&number);
6. if(number==10){
7. printf("number is equals to 10");
8. }
9. else if(number==50){
10. printf("number is equal to 50");
11. }
12. else if(number==100){
13. printf("number is equal to 100");
14. }
15. else{
16. printf("number is not equal to 10, 50 or 100");
17. }
18. return 0;
19. }
Output
enter a number:4
number is not equal to 10, 50 or 100
enter a number:50
number is equal to 50
C Switch Statement
The switch statement in C is an alternate to if-else-if ladder statement which
allows us to execute multiple operations for the different possibles values of
a single variable called switch variable. Here, We can define various
statements in the multiple cases for the different values of a single variable.
1. switch(expression){
2. case value1:
3. //code to be executed;
4. break; //optional
5. case value2:
6. //code to be executed;
7. break; //optional
8. ......
9.
10. default:
11. code to be executed if all cases are not matched;
12. }
Let's see a simple example of c language switch statement.
1. #include<stdio.h>
2. int main(){
3. int number=0;
4. printf("enter a number:");
5. scanf("%d",&number);
6. switch(number){
7. case 10:
8. printf("number is equals to 10");
9. break;
10. case 50:
11. printf("number is equal to 50");
12. break;
13. case 100:
14. printf("number is equal to 100");
15. break;
16. default:
17. printf("number is not equal to 10, 50 or 100");
18. }
19. return 0;
20. }
Output
enter a number:4
number is not equal to 10, 50 or 100
C Loops
The looping can be defined as repeating the same process multiple times
until a specific condition satisfies. There are three types of loops used in the
C language.
The looping simplifies the complex problems into the easy ones. It enables
us to alter the flow of the program so that instead of writing the same code
again and again, we can repeat the same code for a finite number of times.
For example, if we need to print the first 10 natural numbers then, instead
of using the printf statement 10 times, we can print inside a loop which runs
up to 10 iterations.
Advantage of loops in C
2) Using loops, we do not need to write the same code again and again.
2) Using loops, we can traverse over the elements of data structures (array
or linked lists).
do while loop in C
The syntax of the C language do-while loop is given below:
1. do{
2. //code to be executed
3. }while(condition);
Example 1
1. #include<stdio.h>
2. #include<stdlib.h>
3. void main ()
4. {
5. char c;
6. int choice,dummy;
7. do{
8. printf("\n1. Print Hello\n2. Print C Programming\n3. Exit\n");
9. scanf("%d",&choice);
10. switch(choice)
11. {
12. case 1 :
13. printf("Hello");
14. break;
15. case 2:
16. printf("C Programming ");
17. break;
18. case 3:
19. exit(0);
20. break;
21. default:
22. printf("please enter valid choice");
23. }
24. printf("do you want to enter more?");
25. scanf("%d",&dummy);
26. scanf("%c",&c);
27. }while(c=='y');
28. }
Output
1. Print Hello
2. Print C Programming
3. Exit
1
Hello
do you want to enter more?
y
1. Print Hello
2. Print C Programming
3. Exit
2
C Programming
do you want to enter more?
n
do while example
There is given the simple program of c language do while loop where we are
printing the table of 1.
1. #include<stdio.h>
2. int main(){
3. int i=1;
4. do{
5. printf("%d \n",i);
6. i++;
7. }while(i<=10);
8. return 0;
9. }
Output
1
2
3
4
5
6
7
8
9
10
while loop in C
1. while(condition){
2. //code to be executed
3. }
Let's see the simple program of while loop that prints table of 1.
1. #include<stdio.h>
2. int main(){
3. int i=1;
4. while(i<=10){
5. printf("%d \n",i);
6. i++;
7. }
8. return 0;
9. }
Output
1
2
3
4
5
6
7
8
9
10
for loop in C
The for loop in C language is used to iterate the statements or a part of
the program several times. It is frequently used to traverse the data
structures like the array and linked list.
1. for(Expression 1; Expression 2; Expression 3){
2. //code to be executed
3. }
Let's see the simple program of for loop that prints table of 1.
1. #include<stdio.h>
2. int main(){
3. int i=0;
4. for(i=1;i<=10;i++){
5. printf("%d \n",i);
6. }
7. return 0;
8. }
Output
1
2
3
4
5
6
7
8
9
10
Module 3
C Functions
In c, we can divide a large program into the basic building blocks known as
function. The function contains the set of programming statements enclosed
by {}. A function can be called multiple times to provide reusability and
modularity to the C program. In other words, we can say that the collection
of functions creates a program. The function is also known
as procedure or subroutine in other programming languages.
Advantage of functions in C
There are the following advantages of C functions.
Types of Functions
There are two types of functions in C programming:
Hello C Language
C Array
An array is defined as the collection of similar type of data items stored at
contiguous memory locations. Arrays are the derived data type in C
programming language which can store the primitive type of data such as
int, char, double, float, etc. It also has the capability to store the collection
of derived data types, such as pointers, structure, etc. The array is the
simplest data structure where each data element can be randomly accessed
by using its index number.
By using the array, we can access the elements easily. Only a few lines of
code are required to access the elements of the array.
Properties of Array
o Each element of an array is of same data type and carries the same
size, i.e., int = 4 bytes.
o Elements of the array are stored at contiguous memory locations
where the first element is stored at the smallest memory location.
o Elements of the array can be randomly accessed since we can
calculate the address of each element of the array with the given base
address and the size of the data element.
Advantage of C Array
2) Ease of traversing: By using the for loop, we can retrieve the elements
of an array easily.
3) Ease of sorting: To sort the elements of the array, we need a few lines
of code only.
4) Random Access: We can access any element randomly using the array.
Declaration of C Array
We can declare an array in the c language in the following way.
1. data_type array_name[array_size];
1. int marks[5];
1. marks[0]=80;//initialization of array
2. marks[1]=60;
3. marks[2]=70;
4. marks[3]=85;
5. marks[4]=75;
C array example
1. #include<stdio.h>
2. int main(){
3. int i=0;
4. int marks[5];//declaration of array
5. marks[0]=80;//initialization of array
6. marks[1]=60;
7. marks[2]=70;
8. marks[3]=85;
9. marks[4]=75;
10. //traversal of array
11. for(i=0;i<5;i++){
12. printf("%d \n",marks[i]);
13. }//end of for loop
14. return 0;
15. }
Output
80
60
70
85
75
Module 2
C++ Introduction
C++ is an object-oriented programming language. It is an extension to C programming.
C++ is a general purpose, case-sensitive, free-form programming language that supports object-
oriented, procedural and generic programming.
C++ is a middle-level language, as it encapsulates both high and low level language features.
C++ Basic Input/Output
C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It
makes the performance fast.
If bytes flow from main memory to device like printer, display screen, or a network connection,
etc, this is called as output operation.
If bytes flow from device like printer, display screen, or a network connection, etc to main
memory, this is called as input operation.
C++ Object and Class
Since C++ is an object-oriented language, program is designed using objects and classes in C++.
C++ Object
In C++, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc.
In other words, object is an entity that has state and behavior. Here, state means data and
behavior means functionality.
Object is an instance of a class. All the members of the class can be accessed through object.
Let's see an example to create object of student class using s1 as the reference variable.
1. Student s1; //creating an object of Student
C++ Class
In C++, object is a group of similar objects. It is a template from which objects are created. It can
have fields, methods, constructors etc.
Let's see an example of C++ class that has three fields only.
1. class Student
2. {
3. public:
4. int id; //field or data member
5. float salary; //field or data member
6. String name;//field or data member
7. }
C++ Constructor
In C++, constructor is a special method which is invoked automatically at the time of object
creation. It is used to initialize the data members of new object generally. The constructor in C++
has the same name as class or structure.
o Default constructor
o Parameterized constructor
C++ Destructor
A destructor works opposite to constructor; it destructs the objects of classes. It can be defined
only once in a class. Like constructors, it is invoked automatically.
A destructor is defined like constructor. It must have same name as class. But it is prefixed with
a tilde sign (~).
Note: C++ destructor cannot have parameters. Moreover, modifiers can't be applied on
destructors.
C++ this Pointer
In C++ programming, this is a keyword that refers to the current instance of the class. There can
be 3 main usage of this keyword in C++.
C++ static
In C++, static is a keyword or modifier that belongs to the type not instance. So instance is not
required to access the static members. In C++, static can be field, method, constructor, class,
properties, operator and event.
Memory efficient: Now we don't need to create instance for accessing the static members, so it
saves memory. Moreover, it belongs to the type, so it will not get memory each time when
instance is created.
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
class whose members are inherited is called base class. The derived class is the specialized class
for the base class.
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.
Types Of Inheritance
Derived Classes
A Derived class is defined as the class derived from the base class.
1. class derived_class_name :: visibility-mode base_class_name
2. {
3. // body of the derived class.
4. }
C++ Polymorphism
The term "Polymorphism" is the combination of "poly" + "morphs" which means many forms. It
is a greek word. In object-oriented programming, we use 3 main concepts: inheritance,
encapsulation, and polymorphism.
Real Life Example Of Polymorphism
Let's consider a real-life example of polymorphism. A lady behaves like a teacher in a classroom,
mother or daughter in a home and customer in a market. Here, a single person is behaving
differently according to the situations.
C++ Templates
A C++ template is a powerful feature added to C++. It allows you to define the generic classes
and generic functions and thus provides support for generic programming. Generic programming
is a technique where generic types are used as parameters in algorithms so that they can work for
a variety of data types.
o Function templates
o Class templates
Module 4
C++ Files and Streams
To read and write from a file we are using the standard C++ library called fstream. Let us see
the data types define in fstream library is:
Fstream It is used to create files, write information to files, and read information from files.
1. #include <iostream>
2. #include <fstream>
3. using namespace std;
4. int main () {
5. ofstream filestream("testout.txt");
6. if (filestream.is_open())
7. {
8. filestream << "Welcome to C++.\n";
9. filestream << "C++ Tutorial.\n";
10. filestream.close();
11. }
12. else cout <<"File opening is fail.";
13. return 0;
14. }
Output:
1. #include <iostream>
2. #include <fstream>
3. using namespace std;
4. int main () {
5. string srg;
6. ifstream filestream("testout.txt");
7. if (filestream.is_open())
8. {
9. while ( getline (filestream,srg) )
10. {
11. cout << srg <<endl;
12. }
13. filestream.close();
14. }
15. else {
16. cout << "File opening is fail."<<endl;
17. }
18. return 0;
19. }
Note: Before running the code a text file named as "testout.txt" is need to be created and the content of a text
file is given below:
Welcome to C++.
C++ Tutorial.
Output:
Welcome to C++.
C++ Tutorial.
1. #include <fstream>
2. #include <iostream>
3. using namespace std;
4. int main () {
5. char input[75];
6. ofstream os;
7. os.open("testout.txt");
8. cout <<"Writing to a text file:" << endl;
9. cout << "Please Enter your name: ";
10. cin.getline(input, 100);
11. os << input << endl;
12. cout << "Please Enter your age: ";
13. cin >> input;
14. cin.ignore();
15. os << input << endl;
16. os.close();
17. ifstream is;
18. string line;
19. is.open("testout.txt");
20. cout << "Reading from a text file:" << endl;
21. while (getline (is,line))
22. {
23. cout << line << endl;
24. }
25. is.close();
26. return 0;
27. }
Output:
It is naive for an Extension professional to feel that if information is delivered during a learning
activity, the educational mission has been accomplished. The broader mandate that learning
generate change in behavior, practice, or belief requires a much more sophisticated science and
art. In today's information-rich culture, Extension's store of information no longer makes the
organization unique. Rather, Extension's organizational strength and uniqueness lie in the
experience and capability of its professionals to motivate individuals and groups to action.
It is important for Extension educators to develop and field test useful models for program
design and delivery that include behavior change. It is equally important for the models to be
linked to sound educational theory that will be valued by partnering agencies and understood by
the targeted clientele.
The process described in this article accomplished these objectives and resulted in information
that now provides a framework for quality training in a broad range of programming. Further
development of the model has resulted in additional insights with practical application beyond
the scope of this article.
Bibliography
Books:-
1. Let Us C by Yashavant Kanetkar
2. Computer Science, C++ by Sumita Arora
3. The Complete Reference, C++ by Herbert Schildt
4. Software Engineering by Roger S. Pressman
References:-
www.tutorialspoint.com
www.w3school.com
www.allschoolstuff.com
https://www.youtube.com/channel/UCRhH58xS3s_fvjZGBYE12wg/