[go: up one dir, main page]

0% found this document useful (0 votes)
50 views21 pages

Anmol Sip-1

Lalit Kumar submitted an internship report on C++ during their Bachelor of Technology degree. The report includes: 1) An introduction to C++ that describes it as a compiled, object-oriented language that is the successor to C and was developed in the 1980s. It discusses C++'s versatility for large programs and object-oriented libraries. 2) Sections on data types and operators in C++, including basic and derived types as well as relational, arithmetic, and logical operators. 3) Explanations of flow control in C++ through loops and decision-making statements like if/else, including diagrams. 4) A section on functions that defines their purpose and

Uploaded by

lalitrajput44818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views21 pages

Anmol Sip-1

Lalit Kumar submitted an internship report on C++ during their Bachelor of Technology degree. The report includes: 1) An introduction to C++ that describes it as a compiled, object-oriented language that is the successor to C and was developed in the 1980s. It discusses C++'s versatility for large programs and object-oriented libraries. 2) Sections on data types and operators in C++, including basic and derived types as well as relational, arithmetic, and logical operators. 3) Explanations of flow control in C++ through loops and decision-making statements like if/else, including diagrams. 4) A section on functions that defines their purpose and

Uploaded by

lalitrajput44818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

SUMMER INTERNSHIP REPORT

ON

C++
Submitted in partial fulfilment of the requirements for the Degree Of

Bachelor of Technology
Uttaranchal Institute of Technology

Submitted To: Submitted By:


Dr. R.B. Singh Ayga Lalit Kumar
Roll No-31
B.Tech -7th sem
ACKNOWLEDGEMENT
The most awaited moment of any endeavor is successful completion, but nothing can be done successfully
if done alone. Success is the outcome of the contribution and consistent help of various persons and we
thank those who helped us in the successful completion of this project.

Primarily I would like to thank Dr. S.D Pandey, Dean UIT for providing a healthy and encouraging
environment to study.

I profusely thankful to the department of computing Science, and Dr. Sumit Chaudhary, HOD. I am
also thankful to my mentor Mr.Ashok Kumar sir for guiding me throughout the internship period.
He has been generous enough to provide me an opportunity and accepting my candidature for the most
valuable guidance and affordable treatment given to us at every stage to boost my morale.

Student Name: Lalit Kumar


Enrollment Number: UU2001010071
DECLARATION
I hereby declare that Anmol Kothiyal submits the internship report entitled C++ to Uttaranchal
INSTITUTE OF TECHNOLOGY . The internship was done under the guidance of Mr.Ashok Kumar . I
further declare that the work reported in this internship has not been submitted and will not be submitted,
either in part or in full, for the award of any other degree or diploma in this university or any other
university or institute.

Date:

(Signature)

Lalit Kumar

B.tech Cse-7th sem


CERTIFICATE OF CORIGINALITY

This is to certify that the internship entitled “C++” by Lalit kumar has been submitted in partial fulfilment
of the requirements for the award of the degree of B.TECH CSE from Uttaranchal University, Dehradun.
The results embodied in this project have not been submitted to any other University or Institution for the
record of any degree.

Under the guidance of:

Dr. Madhu Kirola


Assistant Professor Uttaranchal
University Dehradun
CERTIFICATE OF ORIGINALITY
Table of Contents

1. Introduction 1.1. About C++


1.2. Application of C++
2. Data Types & Operators
2.1. Data Types & Their Description
- Basic Data Types
- Enumerated Types
- The Type Void
- Derived Types
2.2. Operators
- Relational Operator
- Arithmetic Operator
- Logical Operator
3. Flow of Control
3.1. C++ Loop Types
3.2. C++ Decision Making Statements
- Control Flow Diagram of Loop
- Control Flow Diagram of If-Else
4. Functions
4.1. C++ Functions
5. Classes and Objects
5.1. C++ Classes
- C++ Class Definitions
- Define C++ Objects
6. Array
6.1. Properties of Arrays in C++
7. Linked List
8. Project: C++ Book Management System
- Source Code
- Project Description
9. References
List of Figures

3.1 Control Flow Diagram Of Loop.................................................. 7


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

List of Tables
2.1 Rational Operators

2.2 Arithmetic Operator

2.3 Logical Operator

3.1 Loop Statements

3.2 Decision Making statements


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.

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

2.2 Operators
1. Relational Operator
2. Arithmetic Operator

3.Logical Operator

Flow Of Control
2.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
C++ programming language provides the following type of loops to han- dle
looping requirements.

Table 3.1: Loop Statements


1.1 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


C++ programming language provides following types of decision-making statements
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

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 :

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 beperformed 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.
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.

6 .Array
an array is a data structure that is used to store multiple values of similar data types in a
contiguous memory location.
For example, if we have to store the marks of 4 or 5 students then we can easily store
them by creating 5 different variables but what if we want to store marks of 100 students
or say 500 students then it becomes very challenging to create that numbers of variable
and manage them. Now, arrays come into the picture that can do it easily by just creating
an array of the required size.

6.1 Properties of Arrays in C++

• An Array is a collection of data of the same data type, stored at a contiguous memory location.
• Indexing of an array starts from 0. It means the first element is stored at the 0th index, the second at 1st,
and so on.
• Elements of an array can be accessed using their indices.
• Once an array is declared its size remains constant throughout the program.
• An array can have multiple dimensions.
• The number of elements in an array can be determined using the sizeof operator.
• We can find the size of the type of elements stored in an array by subtracting adjacent addresses.
Array Declaration in C++
In C++, we can declare an array by simply specifying the data type first and then the name of an array with
its size.
data_type array_name[Size_of_array];
Example
int arr[5];

Initialization of Array in C++

In C++, we can initialize an array in many ways but we will discuss some most common ways to initialize
an array. We can initialize an array at the time of declaration or after declaration.
1. Initialize Array with Values in C++
We have initialized the array with values. The values enclosed in curly braces ‘{}’ are assigned to the array.
Here, 1 is stored in arr[0], 2 in arr[1], and so on. Here the size of the array is 5.
int arr[5] = {1, 2, 3, 4, 5};
2. Initialize Array with Values and without Size in C++
We have initialized the array with values but we have not declared the length of the array, therefore, the
length of an array is equal to the number of elements inside curly braces.
int arr[] = {1, 2, 3, 4, 5};
3. Initialize Array after Declaration (Using Loops)
We have initialized the array using a loop after declaring the array. This method is generally used when we
want to take input from the user or we cant to assign elements one by one to each index of the array. We
can modify the loop conditions or change the initialization values according to requirements.
for (int i = 0; i < N; i++) {
arr[i] = value;
}
4. Initialize an array partially in C++
Here, we have declared an array ‘partialArray’ with size ‘5’ and with values ‘1’ and ‘2’ only. So, these
values are stored at the first two indices, and at the rest of the indices ‘0’ is stored.
int partialArray[5] = {1, 2};
5. Initialize the array with zero in C++
We can initialize the array with all elements as ‘0’ by specifying ‘0’ inside the curly braces. This will
happen in case of zero only if we try to initialize the array with a different value say ‘2’ using this method
then ‘2’ is stored at the 0th index only.
int zero_array[5] = {0};
Accessing an Element of an Array in C++
Elements of an array can be accessed by specifying the name of the array, then the index of the element
enclosed in the array subscript operator []. For example, arr[i].
Example 1: The C++ Program to Illustrate How to Access Array Elements

// C++ Program to Illustrate How to Access


Array Elements
#include <iostream>
using namespace std;

int main()
{

int arr[3];

// Inserting elements in an array


arr[0] = 10;
arr[1] = 20;
arr[2] = 30;

// Accessing and printing elements of the


array
cout << "arr[0]: " << arr[0] << endl;
cout << "arr[1]: " << arr[1] << endl;
cout << "arr[2]: " << arr[2] << endl;

return 0;
}

Output
arr[0]: 10
arr[1]: 20
arr[2]: 30

7. Link list
The Linked Lists are linear data structures where the data is not stored at contiguous memory locations so we
can only access the elements of the linked list in a sequential manner. Linked Lists are used to overcome the
shortcoming of arrays in operations such as deletion, insertion, etc.
Types of Linked List
1. Singly Linked List
2. Doubly Linked List
3. Circular Linked List
4. Circular Doubly Linked List
5. Header Linked List

Project Description
The C++ Book Management System project allows users to manage a library of books. Users can add books to the
library, display the list of books, and exit the system. The project incorporates classes, functions, and arrays to create a
simple yet functional book management system.

#include <iostream>
#include <string>
// Define the Book class
class Book {
public:
std::string title;
std::string author;
int publicationYear;

// Constructor
Book(std::string t, std::string a, int year) : title(t), author(a), publicationYear(year) {}
// Function to display book details
void displayDetails() {
std::cout << "Title: " << title << "\nAuthor: " << author << "\nYear of Publication: " << publicationYear <<
"\n\n";
}
};

// Function to display menu


void displayMenu() {
std::cout << "========== Book Management System ==========\n";
std::cout << "1. Add a Book\n";
std::cout << "2. Display All Books\n";
std::cout << "3. Exit\n";
std::cout << "============================================\n";
}

int main() {
const int maxBooks = 10;
Book library[maxBooks]; // Array to store books
int bookCount = 0;

while (true) {
displayMenu();

int choice;
std::cout << "Enter your choice: ";
std::cin >> choice;

switch (choice) {
case 1: // Add a Book
if (bookCount < maxBooks) {
std::string title, author;
int year;

std::cin.ignore(); // Clear the input buffer


std::cout << "Enter the title: ";
std::getline(std::cin, title);
std::cout << "Enter the author: ";
std::getline(std::cin, author);

std::cout << "Enter the year of publication: ";


std::cin >> year;

library[bookCount++] = Book(title, author, year);


std::cout << "Book added successfully!\n\n";
} else {
std::cout << "Library is full. Cannot add more books.\n\n";
}
break;

case 2: // Display All Books


if (bookCount > 0) {
std::cout << "========== List of Books ==========\n";
for (int i = 0; i < bookCount; ++i) {
library[i].displayDetails();
}
std::cout << "===================================\n\n";
} else {
std::cout << "No books in the library.\n\n";
}
break;

case 3: // Exit
std::cout << "Exiting the Book Management System. Goodbye!\n";
return 0;

default:
std::cout << "Invalid choice. Please enter a valid option.\n\n";
}
}

return 0;
}
Sample Output

========== Book Management System ==========


1. Add a Book
2. Display All Books
3. Exit
============================================
Enter your choice: 1
Enter the title: The Catcher in the Rye
Enter the author: J.D. Salinger
Enter the year of publication: 1951
Book added successfully!

========== Book Management System ==========


1. Add a Book
2. Display All Books
3. Exit
============================================
Enter your choice: 1
Enter the title: To Kill a Mockingbird
Enter the author: Harper Lee
Enter the year of publication: 1960
Book added successfully!

========== Book Management System ==========


1. Add a Book
2. Display All Books
3. Exit
============================================
Enter your choice: 2
========== List of Books ==========
Title: The Catcher in the Rye
Author: J.D. Salinger
Year of Publication: 1951

Title: To Kill a Mockingbird


Author: Harper Lee
Year of Publication: 1960
===================================

========== Book Management System ==========


1. Add a Book
2. Display All Books
3. Exit
============================================
Enter your choice: 3
Exiting the Book Management System. Goodbye!

References

[1] https://www.tutorialspoint.com/cplusplus/index.htm
[2] www.w3schools.com
[3] The C++ Programming Language by Bjarne Structure

You might also like