This document provides an overview of the C++ programming language. It discusses key C++ concepts like classes, objects, functions, and data types. Some key points:
- C++ is an object-oriented language that is an extension of C with additional features like classes and inheritance.
- Classes allow programmers to combine data and functions to model real-world entities. Objects are instances of classes.
- The document defines common C++ terms like keywords, identifiers, constants, and operators. It also provides examples of basic programs.
- Functions are described as modular and reusable blocks of code. Parameter passing techniques like pass-by-value and pass-by-reference are covered.
- Other concepts covered include
This document provides an overview of data types in C++. It discusses fundamental data types like int, char, float, and void, as well as derived data types like arrays, functions, pointers, references, constants, classes, structures, unions, and enumerations. For each data type, it provides examples and explanations of how they are used and represented in memory. It also covers data type modifiers, variable declaration and initialization, and input/output stream manipulators for formatting output.
C++ is an object-oriented programming language that is an extension of C. It was developed in the early 1980s by Bjarne Stroustrup at Bell Labs. C++ supports concepts like inheritance, polymorphism, and encapsulation that make it suitable for large, complex programs. Inheritance allows classes to inherit properties from parent classes. Polymorphism is the ability to process objects of different types in the same way. Encapsulation combines data and functions that operate on that data within a single unit, hiding implementation details. File input/output in C++ can be handled through streams like ifstream for input and ofstream for output.
This document provides information on data types in C++ programming. It begins by explaining that data types identify the type of data that can be stored in a variable, such as integer or boolean, and determine the possible values and operations for that type. It then describes several categories of data types in C++, including primitive, derived, user-defined, and examples of each. Primitive types are basic types predefined by the language like int, float, char. Derived types are built from primitive types, such as arrays and pointers. User-defined types allow creating new types and include enums, structures, and unions. The document provides examples of basic programs using various data types.
This document provides an overview of various C++ data types including fundamental, derived, and user-defined data types. It discusses integer, character, float, double, and void fundamental data types. It also covers integer, character, and floating-point type modifiers. Additionally, it summarizes arrays, functions, pointers, references, constants, classes, structures, unions, and enumerations as derived or user-defined data types in C++.
This document provides an overview of C++ data types. It discusses fundamental data types like integer, character, float, and double. It also covers type modifiers, derived data types like arrays and functions, and other concepts like pointers, references, constants, classes, structures, unions, and enumerations. The document aims to explain the different data types and how they are used in C++.
The document discusses object-oriented programming (OOP) using C++, outlining its history, key concepts, and features. It covers C++ syntax, data types, structures, classes, constructors, destructors, and access specifiers, while emphasizing encapsulation, inheritance, and function overloading. The lecture serves as an introduction to the fundamentals of OOP and practical implementation through C++ examples.
1. The document discusses object oriented programming concepts like classes, objects, inheritance, and polymorphism in C++.
2. It begins with an introduction to procedural programming and its limitations. Object oriented programming aims to overcome these limitations by emphasizing data over procedures and allowing for inheritance, polymorphism, and encapsulation.
3. The document then covers key OOP concepts like classes, objects, constructors, and static class members in C++. It provides examples of creating classes and objects.
The document discusses object-oriented programming and C++. It begins with an introduction to OOP compared to procedural programming. Key concepts of OOP like classes, objects, inheritance and polymorphism are explained. The document then discusses C++ programming, including the structure of C++ programs, basic input/output functions, data types in C++, variables and constants. Pointers in C++ and how computer memory works with pointers are also summarized.
The document provides an overview of object-oriented programming concepts in C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance and polymorphism. It also covers procedural programming in C++ and compares it with OOP. Examples are provided to demonstrate creating classes, objects, functions, constructors and destructors. The document contains information on basic C++ programming concepts needed to understand and implement OOP principles in C++ programs.
The document covers fundamental concepts of object-oriented programming (OOP), including abstraction, encapsulation, inheritance, and polymorphism. It explains basic data types and modifiers, arrays, classes, objects, and pointers, emphasizing how these elements interact within programming languages like C++. Additionally, it illustrates practical programming examples and definitions, aimed at understanding the structure and functionality of OOP principles.
This document contains the table of contents for a course on Object Oriented Programming in C++, Data Structures, Database Management Systems, Boolean Algebra, and Networking. The course is divided into 5 units covering these topics. Unit I focuses on Object Oriented Programming in C++ and covers chapters on classes, objects, inheritance, and file handling. Unit II covers data structures like arrays, stacks, queues and linked lists. Unit III is about database management systems and SQL. Unit IV covers Boolean algebra. Unit V is about networking and communication technology.
The document discusses various data types in C++. It explains that data types define the type of data stored in variables and associated operations. There are fundamental data types like integer, character, float, double, and void provided by C++. User-defined data types include arrays, pointers, references, structures, unions, classes and enumerations. The document provides details on the size and range of standard data types like short int, int, long, float, double etc. It also explains various type modifiers and derived data types.
1. Identifiers in C++ are used to name variables, functions, and other user-defined items. They can include letters, digits, and underscores but not special characters or keywords.
2. There are two types of identifiers: standard identifiers which have special predefined meaning, and user-defined identifiers which are defined by the programmer.
3. Data types in C++ include built-in types like int and char, user-defined types like classes and structures, and derived types like arrays and pointers.
The document provides a comprehensive overview of data types and operators in C++, detailing rules for identifiers, variable declaration, and data types such as built-in, derived, and user-defined types. It discusses the use of variables, functions, pointers, references, and operators, including their types and behaviors, along with the concept of type casting and evaluation rules in expressions. Additionally, it covers object-oriented programming concepts like classes and structures, along with their access modifiers and memory management features.
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTREjatin batra
C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. It runs on a variety of platforms such as Windows, Mac OS, and various versions of UNIX. C++ builds on C by adding classes, objects, inheritance, templates and exceptions to support object-oriented programming.
The document discusses object oriented programming concepts. It describes key object oriented programming concepts like encapsulation, inheritance, polymorphism, and message passing. It also discusses benefits of object oriented programming like modularity, reusability and extensibility. Some disadvantages discussed are compiler overhead, runtime overhead and need for reorientation of developers to object oriented thinking. The document also covers C++ programming concepts like data types, control flow, functions, arrays, strings, pointers and storage classes.
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
The document introduces Object-Oriented Programming (OOP) principles, focusing on C++ programming language features. It details various data types, control structures, user-defined data types like classes, structures, and unions, and explains the role of access specifiers in classes. Additionally, it covers advanced topics on functions, arrays, pointers, references, and storage classes that define variable characteristics in C++.
The document discusses various C++ data types including built-in, derived, and user-defined data types. It describes the different built-in data types like int, char, float, double, void and their properties. It also discusses derived data types like arrays, functions, pointers, references, and constant. The document further explains user-defined data types like structures, unions and classes/objects in C++.
This document provides an overview of an intermediate computer programming course at the University of Gondar in Ethiopia. The course code is CoEng2111 and it is taught by instructor Wondimu B. Topics that will be covered in the course include C++ basics, arrays, strings, functions, and recursion. The course materials are presented over several pages that define concepts, provide code examples, and explain key ideas like variables, data types, operators, and array implementation in C++.
The document outlines the syllabus for the II Year / III Semester 20IT302 - C++ AND DATA STRUCTURES course. It covers 5 units - (1) Object Oriented Programming Fundamentals, (2) Object Oriented Programming Concepts, (3) C++ Programming Advanced Features, (4) Advanced Non-Linear Data Structures, and (5) Graphs. Some key concepts covered include classes, objects, encapsulation, inheritance, polymorphism, templates, containers, iterators, trees, and graph algorithms.
The document provides an introduction to data types in C++ programming language. It discusses the different levels of programming languages, common uses of C/C++, its character set, whitespace characters, and defines what a data type is. It then lists the primitive/built-in data types in C++ like integer, float, boolean, etc. and describes variables types and memory used. It also covers rules for constructing identifiers, variable declaration, and the four types of C/C++ instructions.
The document outlines comprehensive content on C++ and data structures, covering object-oriented programming principles such as classes, objects, inheritance, polymorphism, and encapsulation. It details advanced features like exception handling, templates, and standard libraries, along with non-linear data structures and graph algorithms. Additionally, it discusses basic C++ programming constructs including data types, member functions, constructors, destructors, and access specifiers.
This document provides an overview of the C++ programming language, including its history, features, and key concepts. It discusses how C++ extends the C language and is an intermediate-level language that incorporates both high-level and low-level features. The document also outlines important C++ concepts like object-oriented programming, data types, operators, variables, classes, and control structures. It provides examples and definitions of objects, classes, encapsulation, inheritance, polymorphism and other fundamental OOP concepts.
This document provides an overview of the key concepts covered in Chapter 2 of the C++ Programming textbook. These include basic C++ program components like functions, data types, arithmetic operators, and input/output statements. It also discusses programming fundamentals like declaring variables, writing comments, using preprocessor directives, and properly structuring a C++ program with a main function. An example is provided to demonstrate how to write a program that converts between feet/inches and centimeters.
Chp 3 C++ for newbies, learn fast and earn fastnhbinaaa112
Chapter 3 discusses C++ references, highlighting their relationship to pointers, usage as standalone references, function parameters, and return values. It covers string handling, basic array operations, object-oriented programming principles, and the definition of classes and member functions. Key concepts of OOP, including encapsulation, inheritance, and polymorphism, are also explained along with function arguments and friend functions.
The document provides an introduction to programming fundamentals in C++, including basic syntax and components of a C++ program. It covers variables and data types, input/output, comments, and how to write a simple C++ program with preprocessor directives and a main function. The key topics discussed are variable declaration, fundamental data types like int, float, char, comments, and how to write a basic "Hello World" program in C++.
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management ProcessIJDKP
Data mining and knowledge discovery in databases have been attracting a significant amount of research, industry, and media attention of late. There is an urgent need for a new generation of computational theories and tools to assist researchers in extracting useful information from the rapidly growing volumes of digital data.
This Journal provides a forum for researchers who address this issue and to present their work in a peer-reviewed open access forum. Authors are solicited to contribute to the Journal by submitting articles that illustrate research results, projects, surveying works and industrial experiences that describe significant advances in the following areas, but are not limited to these topics only.
More Related Content
Similar to OOPS (object oriented programming) unit 1 (20)
The document discusses object-oriented programming and C++. It begins with an introduction to OOP compared to procedural programming. Key concepts of OOP like classes, objects, inheritance and polymorphism are explained. The document then discusses C++ programming, including the structure of C++ programs, basic input/output functions, data types in C++, variables and constants. Pointers in C++ and how computer memory works with pointers are also summarized.
The document provides an overview of object-oriented programming concepts in C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance and polymorphism. It also covers procedural programming in C++ and compares it with OOP. Examples are provided to demonstrate creating classes, objects, functions, constructors and destructors. The document contains information on basic C++ programming concepts needed to understand and implement OOP principles in C++ programs.
The document covers fundamental concepts of object-oriented programming (OOP), including abstraction, encapsulation, inheritance, and polymorphism. It explains basic data types and modifiers, arrays, classes, objects, and pointers, emphasizing how these elements interact within programming languages like C++. Additionally, it illustrates practical programming examples and definitions, aimed at understanding the structure and functionality of OOP principles.
This document contains the table of contents for a course on Object Oriented Programming in C++, Data Structures, Database Management Systems, Boolean Algebra, and Networking. The course is divided into 5 units covering these topics. Unit I focuses on Object Oriented Programming in C++ and covers chapters on classes, objects, inheritance, and file handling. Unit II covers data structures like arrays, stacks, queues and linked lists. Unit III is about database management systems and SQL. Unit IV covers Boolean algebra. Unit V is about networking and communication technology.
The document discusses various data types in C++. It explains that data types define the type of data stored in variables and associated operations. There are fundamental data types like integer, character, float, double, and void provided by C++. User-defined data types include arrays, pointers, references, structures, unions, classes and enumerations. The document provides details on the size and range of standard data types like short int, int, long, float, double etc. It also explains various type modifiers and derived data types.
1. Identifiers in C++ are used to name variables, functions, and other user-defined items. They can include letters, digits, and underscores but not special characters or keywords.
2. There are two types of identifiers: standard identifiers which have special predefined meaning, and user-defined identifiers which are defined by the programmer.
3. Data types in C++ include built-in types like int and char, user-defined types like classes and structures, and derived types like arrays and pointers.
The document provides a comprehensive overview of data types and operators in C++, detailing rules for identifiers, variable declaration, and data types such as built-in, derived, and user-defined types. It discusses the use of variables, functions, pointers, references, and operators, including their types and behaviors, along with the concept of type casting and evaluation rules in expressions. Additionally, it covers object-oriented programming concepts like classes and structures, along with their access modifiers and memory management features.
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTREjatin batra
C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. It runs on a variety of platforms such as Windows, Mac OS, and various versions of UNIX. C++ builds on C by adding classes, objects, inheritance, templates and exceptions to support object-oriented programming.
The document discusses object oriented programming concepts. It describes key object oriented programming concepts like encapsulation, inheritance, polymorphism, and message passing. It also discusses benefits of object oriented programming like modularity, reusability and extensibility. Some disadvantages discussed are compiler overhead, runtime overhead and need for reorientation of developers to object oriented thinking. The document also covers C++ programming concepts like data types, control flow, functions, arrays, strings, pointers and storage classes.
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
The document introduces Object-Oriented Programming (OOP) principles, focusing on C++ programming language features. It details various data types, control structures, user-defined data types like classes, structures, and unions, and explains the role of access specifiers in classes. Additionally, it covers advanced topics on functions, arrays, pointers, references, and storage classes that define variable characteristics in C++.
The document discusses various C++ data types including built-in, derived, and user-defined data types. It describes the different built-in data types like int, char, float, double, void and their properties. It also discusses derived data types like arrays, functions, pointers, references, and constant. The document further explains user-defined data types like structures, unions and classes/objects in C++.
This document provides an overview of an intermediate computer programming course at the University of Gondar in Ethiopia. The course code is CoEng2111 and it is taught by instructor Wondimu B. Topics that will be covered in the course include C++ basics, arrays, strings, functions, and recursion. The course materials are presented over several pages that define concepts, provide code examples, and explain key ideas like variables, data types, operators, and array implementation in C++.
The document outlines the syllabus for the II Year / III Semester 20IT302 - C++ AND DATA STRUCTURES course. It covers 5 units - (1) Object Oriented Programming Fundamentals, (2) Object Oriented Programming Concepts, (3) C++ Programming Advanced Features, (4) Advanced Non-Linear Data Structures, and (5) Graphs. Some key concepts covered include classes, objects, encapsulation, inheritance, polymorphism, templates, containers, iterators, trees, and graph algorithms.
The document provides an introduction to data types in C++ programming language. It discusses the different levels of programming languages, common uses of C/C++, its character set, whitespace characters, and defines what a data type is. It then lists the primitive/built-in data types in C++ like integer, float, boolean, etc. and describes variables types and memory used. It also covers rules for constructing identifiers, variable declaration, and the four types of C/C++ instructions.
The document outlines comprehensive content on C++ and data structures, covering object-oriented programming principles such as classes, objects, inheritance, polymorphism, and encapsulation. It details advanced features like exception handling, templates, and standard libraries, along with non-linear data structures and graph algorithms. Additionally, it discusses basic C++ programming constructs including data types, member functions, constructors, destructors, and access specifiers.
This document provides an overview of the C++ programming language, including its history, features, and key concepts. It discusses how C++ extends the C language and is an intermediate-level language that incorporates both high-level and low-level features. The document also outlines important C++ concepts like object-oriented programming, data types, operators, variables, classes, and control structures. It provides examples and definitions of objects, classes, encapsulation, inheritance, polymorphism and other fundamental OOP concepts.
This document provides an overview of the key concepts covered in Chapter 2 of the C++ Programming textbook. These include basic C++ program components like functions, data types, arithmetic operators, and input/output statements. It also discusses programming fundamentals like declaring variables, writing comments, using preprocessor directives, and properly structuring a C++ program with a main function. An example is provided to demonstrate how to write a program that converts between feet/inches and centimeters.
Chp 3 C++ for newbies, learn fast and earn fastnhbinaaa112
Chapter 3 discusses C++ references, highlighting their relationship to pointers, usage as standalone references, function parameters, and return values. It covers string handling, basic array operations, object-oriented programming principles, and the definition of classes and member functions. Key concepts of OOP, including encapsulation, inheritance, and polymorphism, are also explained along with function arguments and friend functions.
The document provides an introduction to programming fundamentals in C++, including basic syntax and components of a C++ program. It covers variables and data types, input/output, comments, and how to write a simple C++ program with preprocessor directives and a main function. The key topics discussed are variable declaration, fundamental data types like int, float, char, comments, and how to write a basic "Hello World" program in C++.
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management ProcessIJDKP
Data mining and knowledge discovery in databases have been attracting a significant amount of research, industry, and media attention of late. There is an urgent need for a new generation of computational theories and tools to assist researchers in extracting useful information from the rapidly growing volumes of digital data.
This Journal provides a forum for researchers who address this issue and to present their work in a peer-reviewed open access forum. Authors are solicited to contribute to the Journal by submitting articles that illustrate research results, projects, surveying works and industrial experiences that describe significant advances in the following areas, but are not limited to these topics only.
Rapid Prototyping for XR: Lecture 4 - High Level Prototyping.Mark Billinghurst
This is lecture 4 in the course on Rapid Prototyping for XR, taught by Mark Billinghurst on June 11th, 2025. This lecture is about High Level Prototyping.
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...resming1
Lecture delivered in 2021. This gives an introduction to Natural Language Processing. It describes the use cases of NLP in daily life. It discusses the stages in NLP Pipeline. It highlights the challenges involved covering the different levels of ambiguity that could arise. It also gives a brief note on the present scenario with the latest language models, tools and frameworks/libraries for NLP.
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & ImpactAlqualsaDIResearchGr
Invited keynote at the Artificial Intelligence Symposium on AI-powered Research Innovation, taking place at ENSEM (L'École Nationale Supérieure d'Électricité et de Mécanique), Casablanca on June 21, 2025. I’ll be giving a keynote titled: "Generative AI & Scientific Research: Catalyst for Innovation, Ethics & Impact". Looking forward to engaging with researchers and doctoral students on how Generative AI is reshaping the future of science, from discovery to governance — with both opportunities and responsibilities in focus.
#AI hashtag#GenerativeAI #ScientificResearch #Innovation #Ethics #Keynote #AIinScience #GAI #ResearchInnovation #Casablanca
1. Thinking, Creative Thinking, Innovation
2. Societies Evolution from 1.0 to 5.0
3. AI - 3P Approach, Use Cases & Innovation
4. GAI & Creativity
5. TrustWorthy AI
6. Guidelines on The Responsible use of GAI In Research
Rapid Prototyping for XR: Lecture 3 - Video and Paper PrototypingMark Billinghurst
This is lecture 3 in the course on Rapid Prototyping for XR, taught by Mark Billinghurst on June 10th 2025. This lecture is about Video and Paper prototyping.
Microwatt is a lightweight, open-source core based on the OpenPOWER ISA.
It’s designed for FPGAs and easy experimentation in chip design.
Ideal for education, prototyping, and custom silicon development.
Fully open, it empowers developers to learn, modify, and innovate.
For any number of circumstances, obsolescence risk is ever present in the electronics industry. This is especially true for human-to-machine interface hardware, such as keypads, touchscreens, front panels, bezels, etc. This industry is known for its high mix and low-volume builds, critical design requirements, and high costs to requalify hardware. Because of these reasons, many programs will face end-of-life challenges both at the component level as well as at the supplier level.
Redesigns and qualifications can take months or even years, so proactively managing this risk is the best way to deter this. If an LED is obsolete or a switch vendor has gone out of business, there are options to proceed.
In this webinar, we cover options to redesign and reverse engineer legacy keypad and touchscreen designs.
For more information on our HMI solutions, visit https://www.epectec.com/user-interfaces.
Citizen Observatories (COs) are initiatives that empower citizens to engage in data collection, analysis and interpretation in order to address various issues affecting their communities and contribute to policy-making and community development.
Thematic co-exploration is a co-production process where citizens actively participate alongside scientists and other actors in the exploration of specific themes.
Making them a reality involves addressing the following challenges:
Data quality and reliability
Engagement and retention of participants
Integration with policy and decision-making
Deep Learning for Image Processing on 16 June 2025 MITS.pptxresming1
This covers how image processing or the field of computer vision has advanced with the advent of neural network architectures ranging from LeNet to Vision transformers. It covers how deep neural network architectures have developed step-by-step from the popular CNNs to ViTs. CNNs and its variants along with their features are described. Vision transformers are introduced and compared with CNNs. It also shows how an image is processed to be given as input to the vision transformer. It give the applications of computer vision.
4. Object:
Any Entity that has state and behaviour is known as entity.
Object is an active entity.(actual work)
Object is a instance of class.
When class is defined no memory is allocated but when it is instantiated
memory is allocated.
5. Class class_name()
{
Dataype datamember;
Datatype datafunction(){
//which task we perofrm
}
};
Int main (){
Object Obj;
Obj.function name();
Return 0;
}
6. Class:
Class is a collection of objects.
Class is a passive entity.
A class is a user defined data type which has data member and data
function.
7. Class:
Class is a collection of objects.
Class is a passive entity.
A class is a user defined data type which has data member and data
function.
9. Polymorphism:
When one task is performed by different ways are known as polymorphism.
For example, A person at the same time can have different character like
a father , a husband and employee.
So the same person can have different behaviour in different situations.
Polymorphism
Compile Time Run Time
Function
Overloading
Operator
Overloading
Virtual Function
10. Abstraction:
Hiding internal details and showing functionality.
For example, phone call we don’t know the internal processing.
In c++ we can use abstract class and interface to achieve abstraction.
11. Encapsulation:
Binding or wrapping code and data together into a single unit is known as
encapsulation.
For example, Capsule, It is wrapped with different medicine.
12. Dynamic Binding:
In dynamic binding, the code to be executed in response to function call is
decided at runtime.
C++ has virtual function to support this.
13. Message Passing:
Objects communicate with one another by sending and receiving
information to each other through message passing.
Object A Object B
Message
Sending Object Receiving Object
14. 1.1 Difference Between Procedural
Programming & OOPS
Procedural Languages Object Oriented Language
The Program is divided into small parts
called functions.
The Program is divided into small parts
called objects.
It follows a top-down approach. It follows a bottom-up approach.
No access specifier in procedural
programming.
Object-oriented programming has
access specifier like
private,public,protected.
There is no concept of data hiding
and inheritance.
It provides concept of data hiding
and inheritance.
Doesn’t have any proper way to
hiding data so it is less secure.
Provides data hiding so it is more
secure.
Overloading is not possible. Overloading is possible.
The function is more important than
the data.
Data is more important than the
function.
It is not based on the real word
example.
It is based on the real word example.
15. 1.2 Various Library(header) Files For C++
The Standard Function Library (I/O,String and character
handling,Mathematical,ide-character etc)
The Object Oriented Class Library
• The Standard C++ I/O classes
• The String Class
• The Numeric Class
• The STL Container Classes
• The STL Algorithms
• The STL Function Objects
• The STL Iterator
• Exception Handling Classes ,etc.
16. 1.3 Data Types in C++
C++ supports following data types:
1. Built-in Data Type
2. Derived Data Type
3. User-defined Data Type
17. Data Types (continue…)
1)Built-in Data Type:
It’s also known as primary data type and fundamental data type.
Built-in data type can be used directly by user to declare variables.
• Integer
• Character
• Boolean
• Floating Point
• Double Floating Point
• Void
• Wide Character
18. Data Types (continue…)
1.Integer:
Keyword is used for integer data type is int.
Integer data type require 4 bytes of memory space.
Range is from -2147483648 to 2147483647.
Long,Short,Signed,Unsigned
Example:
int a;
19. Data Types (continue…)
2.Character:
Character data type is used for storing character values.
Keyword is used for character data type is char.
Character data type require 1 bytes of memory space.
Range is from -128 to 127.
Example:
char a;
20. Data Types (continue…)
3.Boolean:
Boolean data type is used for storing logical values.
Keyword is used for boolean data type is bool.
Boolean variable can store either true or false value.
Example:
bool a;
21. Data Types (continue…)
4.Floating Point:
Floating Point data type is used for storing single-precision floating-point
value or decimal values.
Keyword is used for Floating-Point data type is float.
Float variables require 4 bytes of memory location.
Example:
float a;
22. Data Types (continue…)
5.Double Floating Point:
Double Floating Point data type is used for storing double-precision floating-
point value or decimal values.
Keyword is used for Floating-Point data type is double.
Double Float variables require 8 bytes of memory location.
Example:
double a;
23. Data Types (continue…)
5.Double Floating Point:
#include <iostream>
using namespace std;
double findSum(double x, double y)
{
return x + y;
}
int main()
{
double value1 = 10.45, value2 = 6.28;
cout << "The sum is: " << findSum(value1, value2) << "nn";
return 0;
}
24. Data Types (continue…)
5.Double Floating Point:
int main()
{
double value1 , value2;
Cout<<“Enter 1 value”<<endl;
Cin>>value1;
Cout<<“Enter 2 value”;
Cin>>value2;
cout << "The sum is: " << findSum(value1, value2) << "nn";
return 0;
}
25. Data Types (continue…)
6.Void:
Void means without any value.
Void data type represents a valueless entity.
A void data type is used for those function which does not return a value.
Example:
void function_name()
{
…
}
26. Data Types (continue…)
7.Wide Character:
Wide character data type is also a character data type but this data type has a
size grater than the normal 8-bit data type
Wide character represents by wchar_t.
It is generally 2 or 4 bytes long.
Example:
#include<iostream.h>
using namespace std;
int main(){
wchar_t wide_character = L’a’;
cout<<“The wide character is:”<<wide_character<<endl; //97
cout<<“Wide character size: “<<sizeof(wide_character); //2
}
27. Data Types (continue…)
2) Derived Data Type:
The data types that are derived from primitive or built-in data types are
referred to as Derived Data Types.
These can be of four type.
• Function
• Array
• Pointer
• Reference
28. Data Types (continue…)
1. Function:
A function is a block of code or program-segment that is define to perform a
specific task.
A function is generally defined to save the user from writing the same lines of
code again and again for the same input.
All the line of code are put together inside a single function and this can be
called anywhere required.
main() is a default function that is defined in every program of c++.
Syntax:
FunctionType FunctionName(parameters)
30. Data Types (continue…)
2. Array:
An array is a collection of items stored at continuous memory locations.
The idea of array represent many instances in one variable.
Array length = 5
First Index = 0
Last Index = 4
40 63 22 97 10
0 1 2 3 4
Array
Indices
32. Data Types (continue…)
3. Pointers:
Pointer are symbolic representation of addresses.
They enable programs to simulate call-by-reference as well as to create and
manipulate dynamic data structure.
Use * before the variable name.
Syntax:
datatype *var_name;
33. Data Types (continue…)
3. Pointers:
Example:
Int main()
{
int var = 10;
int* ptr; //declare pointer variable
ptr = &var; //data type of ptr and var must be same
// assign addess of a variable to a pointer
cout<<“Value Of ptr = “<<ptr<<“n”;
cout<<“Value Of Var = “<<var<<“n”;
cout<<“Value of *ptr = “<<*ptr<<“n”;
}
34. Data Types (continue…)
4. Reference:
When a variable is declared as reference,it becomes an alternative name for an existing
variable.
A variable can be declared as reference by putting ‘&’ in declaration.
Example:
int main()
{
int x =10;
int& ref = x; //ref is reference of x.
ref = 20; //value of x is now chaged to 20
cout<<“x = “<<x<<endl; //20
x=30; //calue of x is now changed to 30
cout<<“ref = “<<ref<<endl; //30
return 0;
}
35. 3.User Defined Data Type:
1. class:
A class represent a group of similar objects.
To represent classes in c++, it offers a user defined data type called class.
Once the class is defined in it objects belonging to that class can be easily
be created.
To define a class you describe what sort of information it can represent and
what sort of action can perform with that data .
36. 3.User Defined Data Type:
1. class:
Class department{
public:
int emp_no;
char name[30];
char deptname[30];
public:
void add(int emp_no,string name,string deptname);
void delete();
void display(){ cout<<emp_no<<name<<deptname };
};
Int main(){
department sales,HR,accounts;
sales.add(1,”abc”,”computer science”);
sales.display();
}
37. 3.User Defined Data Type:
#include<iostream.h>
#include<string.h>
Class MyClass{
public:
int num;
char mystring[30];
};
Int main(){
MyClass obj;
obj.num=10;
obj.mystring=“Hello World…”;
cout<<obj.num<<endl;
cout<<obj.mystring;
return 0;
}
38. 3.User Defined Data Type:
2. Structure :
A structure is a collection of variables of different data types referenced under
one name.
For every datamember it will occupy different memory location.
Struct student{
int roll_no;
char name[30];
float marks;
};
Main(){
student s1,s2,s3;
}
39. 3.User Defined Data Type:
#include<iostream.h>
#include<string.h>
Int main(){
struct{
string brand;
string model;
int year;
}c1,c2;
c1.brand=“BMW”;
c1.model=“X5”;
c1.year=1999;
c2.brand=“Ford”;
c2.model=“Mustang”;
c2.year=1969;
cout<<c1.brand<<c1.model<<c1.year;
cout<<c2.brand<<c2.model<<c2.year;
return 0;
}
40. 3.User Defined Data Type:
3.Union:
Union is a memory location that is shared by two or more different variables,
generally of different types at different times.
Defining a union is similar to defining a structure.
Element uses same memory location.(anyone)
Union share{
int a; //2
char ch; //1
}
Union share c; //make variable
41. 3.User Defined Data Type:
#include <iostream.h>
union GFG {
int Geek1;
char Geek2;
float Geek3;
};
int main()
{
union GFG G1;
G1.Geek1 = 34;
cout << "The first value at " << "the allocated memory : " << G1.Geek1 << endl;
G1.Geek2 = 34;
cout << "The next value stored "
<< "after removing the "
<< "previous value : " << G1.Geek2 << endl;
G1.Geek3 = 34.34;
cout << "The Final value value "
<< "at the same allocated "
<< "memory space : " << G1.Geek3 << endl;
return 0;
}
42. 3.User Defined Data Type:
4.Enumeration:
An alternative method for naming integer constants is often more
convenient than const.
This can be achieved by enumeration by using keyword enum.
Const int start =0;
Const int pause =1;
Const int go=2;
Or
Enum status{start=10,pause=20,go=30};
43. 3.User Defined Data Type:
#include <iostream.h>
enum detail { a1
a2
a3};
detail d1= a1;
detail d2= a2;
detail d3= a3;
int main()
{
cout << "The numerical value "<< "assigned to a1: "<< d1<< endl;
cout << "The numerical value "<< "assigned to a2: "<< d2<< endl;
cout << "The numerical value "<< "assigned to a3: "<< d3<< endl;
return 0;
}
44. 3.User Defined Data Type:
#include <iostream.h>
enum detail {
doble pi=3.14;
}
Function sum(){
sum=pi+x;
}
Int main()
{
detail d1;
cin>>10;
cout<<“The sum is: “<<sum();
return 0;
}
45. 1.4 Concept Of String
Strings are used for storing a text.
A string variable contains a collection of character surrounded by double
quotes or single quotes.
Example:
string str = “Hello”;
To use strings, must include an additional header file in the source code, the
<string> library:
#include<string>
string str = “Hello”;
46. 1.4.1 Character Array
C++ programming, the collection of characters is stored in the form of arrays.
Strings are array of type char terminated with null character, that is , 0(ASCII value
of null character is 0).
To define a String:
char str[] = “C++”;
• Here, str is a string and it holds 4 character.
• C++ has 3 character ,the null character 0 is added to the end of the string
automatically.
Alternative way to define string
char str[4] = “C++”;
char str[] = {‘C’,’+’,’+’,’0’};
char str[4] = {‘C’,’+’,’+’,’0’};
47. 1.4.1 Character Array (continue…)
A character array is a derived data type in c++ that used to store a collection
of characters or strings.
A char data type take 1 byte of memory, so a character array has memory of
the number of elements in the array. (1*number_of_element_in_array).
Each character in character array has an index that shows the position of the
character in the string.
The null character 0 is used to find the end of characters in the array and is
always stored in the index after the last character or in the last index.
0 1 2 3 4 5
H e l l o 0
48. 1.4.1 Character Array (continue…)
Example:
int main()
{
char str[30];
cout<<“Enter a string: “; //C++
cin>>str;
cout<<“You entered: “<<str<<endl;
cout<<“Enter another string: “; //Hello Word (terminating character)
cin>>str;
cout<<“You entered: “<<str<<endl;
return 0;
}
49. 1.4.2 Pointer To Character Array
An array of pointer to strings is an array of character pointers that holds the address of the first
character of a string or we can say the base address of a string.
In an array of pointers, the manipulation of strings is comparatively easier than in case of 2d
array.We can easily change the position of strings by using pointers.
Example:
char *names[5] = {“John”,
“Ravi”,
“Hetvi”,
“Om”,
“Mansi”};
We declared an array of pointer name as ‘names’ of size 5.
In this case we have done initialization at the time of declaration, so we do not need to mention
the size of array of a pointer.
We can also declared array without any size.
It is not guaranteed that all the string literals will be stored in the contiguous memory location, but
the characters of string literal are stored in contiguous memory location.
50. 1.4.2 Pointer To Character Array (continue…)
Example:
int main()
{
char *names[5] = {“John”,”Om”,”Ravi”,”Hetvi”,”Mansi”};
for(int i=0;i<5;i++)
{
cout<<names[i]<<endl;
}
return 0;
}
In this code, we have declared an array of char pointer holding 5 string literals,
and the first character of each string is holding the base address of the string.
51. 1.4.3 Use Of String.h & It’s Important Function
String.h is a header library for string.
This library has several common functions for dealing with strings stored in
arrays of characters.
The string.h header file to be included before using any string function.
To define we can write,
#include<string.h>
So many functions are used.
strcpy()
strlen()
strcmp()
strcat()
strupr()
strlwr()
52. 1.4.3 Functions Of String.h Header File
1. strcpy():
Strcpy() is a standard library function in C/C++ and is ued to copy one string
to another.
The stcpy() function takes two arguments :
• taget - Pointer to the destination array where the content is to be
copied.
• source – string which will be copied.
It copies the character string pointed by the source to the memory location
pointed by the target.
The null terminating character is also copied.
Syntax:
char *strcpy(char *dest, const char *src);
53. 1.4.3 Functions Of String.h Header File
1. strcpy():
Example:
#include<string.h>
#include<iostream.h>
using namespace std;
int main()
{
char s[] = “Hello World”;
char *s1[];//large enough to store content of src
cout<<“copied String: “<<strcpy(s1,s);
return 0;
}
54. 1.4.3 Functions Of String.h Header File
2. strlen():
The strlen() function calculates the length of a given string.
The strlen() function is defined in string.h header file.
It doesn’t count null character ‘0’.
Syntax:
strlen(const char *str);
• Str – It represents the string variable whose length we have to find.
55. 1.4.3 Functions Of String.h Header File
2. strlen():
Example:
#include<string.h>
#include<iostream.h>
int main()
{
char str[] = “Hello”;
cout<<“Length of string is = “<<strlen(str);
return 0;
}
56. 1.4.3 Functions Of String.h Header File
3. strcmp():
This function takes two strings as arguments and compare these two strings.
Synatx:
strcmp(const char *str1,const char *str2);
Example:
int main(){
char s1[] = “Hello”;
char s2[] = “Hello”;
int returnvalue = strcmp(s1,s2);
if(returnvalue==0){
cout<<“Strings are equal”;
}
else{
cout<<“Strings are unequal”;
}
cout<<“n Value returned by strcmp() is: “<<returnvalue;
return 0;
}
57. 1.4.3 Functions Of String.h Header File
4. strcat():
This function will append a copy of the source string to the end of destination
string.
The strcat() function takes two arguments:
1. dest
2. src
Syntax:
strcat(dest,src);
59. 1.4.3 Functions Of String.h Header File
5. strrev():
This function is used to reverse the string.
Syntax:
char *strrev(char *str);
Str – The given string which is needed to be reversed.
60. 1.4.3 Functions Of String.h Header File
5. strrev():
Example:
int main()
{
char str[30] = “hello”;
cout<<“Entered string is: “<<str;
cout<<“After reversing string is: “<<strrev(str);
return 0;
}
61. 1.5 Concepts Of Class & Objective
Class:
Class in C++ is the building block that leads to object-oriented programming.
It is a user-defined data type,which holds its own data members and member
functions,which can be accessed and used by creating an instance of that
class.
A C++ class is like a blueprint for an object.
For example consider the class of cars.There may be many cars with different
names and bunds but all of them will share some common properties like all
of them will have 4 wheels,speed limit,etc.
So here, car is the class and wheels, speed limits are their properties.
An Object is an instance of a class.When a class is defined,no memory is
allocated but when it is instantiated memory is allocated.
62. 1.5 Concepts Of Class & Objective
Class:
A class is defined in c++ using the keyword class followed by the name of
class.
The body of the class is defined inside the curly brackets and terminated by a
semicolon at the end.
class ClassName
{
Access specifier; //can be private,public or protected
Data members; //variables to be used
Member Functions(){} //methods to access data members
}; //class name ends with a semicolon
63. 1.5 Concepts Of Class & Objective
Declaring Objects:
when a class is defined,only the specification for the object is
defined;no memory or storage is allocated.
Syntax:
ClassName ObjectName;
If we want to access member function using object which we can create.
Object.datamember;
Object.memberfunction();
64. 1.5 Concepts Of Class & Objective
Class student()
{
public:
int rno;
string name;
double marks;
void display()
{
cout<<name<<rno<<marks;
}
};
Int main()
{
student s1;
s1.rno=1;
s1.name=“abc”;
s1.marks=50.67;
s1.display();
return 0;
}