SlideShare a Scribd company logo
1 of 20
Creating Objects


Objectives
In this lesson, you will learn to:
 Identify the built-in data types in C++
 Use variables in C++ programs
 Write and execute C++ programs
 Use arrays in C++ programs




Ā©NIIT                                  OOPS/Lesson 2/Slide 1 of 20
Creating Objects


Variables
 Are Named locations in memory that contain specific
  values
 Rules for naming variables in C++
     Should not have any embedded spaces or symbols
     Should be unique
     Can have any number of characters
     Must begin with a letter or an underscore, which
      may be followed by a sequence of letters, digits, or
      underscores
     Keywords cannot be used as variable names

Ā©NIIT                                 OOPS/Lesson 2/Slide 2 of 20
Creating Objects


Data Types
 Define the type of data that can be stored in a variable
 Built-in data types are:
     char - For characters and strings
     int - For integers
     float - For numbers with decimals




Ā©NIIT                                 OOPS/Lesson 2/Slide 3 of 20
Creating Objects


Data Types (Contd.)

            Number of
            Bytes on a   Minimum           Maximum
Data Type
            32-bit       Value             Value
            Computer

char        1            -128              127

int         4            -2^31             (2^31)-1

float       4            -10^39            10^39



Ā©NIIT                             OOPS/Lesson 2/Slide 4 of 20
Creating Objects


Member Variables
 Are used to implement attributes in C++
 Are declared inside the class body
 Example:
  class Car
   {
        float price;
    };




Ā©NIIT                                  OOPS/Lesson 2/Slide 5 of 20
Creating Objects

Accepting and Storing Values in Member
Variables
 The cin object is used to accept input from the user
  Example:
  class Car
   {
     float price;
     public:
     void acceptprice()
     {
        cout  ā€œEnter Price :ā€;cin 
      price;
     }
    };
Ā©NIIT                                OOPS/Lesson 2/Slide 6 of 20
Creating Objects


Writing and Executing a C++ Program
 The iostream header file
     Is called a pre-processor directive
 The main() function
     Is mandatory in C++ programming for program
      execution
 Creating objects
     Is required for reserving memory at the time of
      declaration




Ā©NIIT                                 OOPS/Lesson 2/Slide 7 of 20
Creating Objects


Compiling, Linking, and Executing a Program
 Is done by following the listed steps:
  1. The C++ program should contain the #include
     statement, the class declaration and member
     function definition, and the main() function.
  2. Save the file with a .cc extension.
  3. Compile the file using the gpp file name
     command from the command prompt.
  4. Execute the file using the a.out command from
     the command prompt.



Ā©NIIT                                 OOPS/Lesson 2/Slide 8 of 20
Creating Objects


Executing C++ Programs

              a.out executes the initial
                   startup code

              The startup code executes
                 the main() function


                 When the main() function
              finishes execution, it sends a
                 status of execution to the
                     operating system


Ā©NIIT                             OOPS/Lesson 2/Slide 9 of 20
Creating Objects


Array
 Is a collection of elements of a single data type stored
  in adjacent memory locations
 Syntax:
  data_type variable_name[dimension_size];
 Example:
  int arr[5];




Ā©NIIT                                OOPS/Lesson 2/Slide 10 of 20
Creating Objects


Declaring and Initializing an Array
 Example:
  arr[0] = 14;
  arr[1] = 15;
  arr[2] = 17;
  arr[3] = 45;
  arr[2] = 81;
 Example:
  int arr[5] = {14, 15, 17, 45, 81};
 Example:
  int arr[] = {14, 15, 17, 45, 81};



Ā©NIIT                           OOPS/Lesson 2/Slide 11 of 20
Creating Objects


Declaring and Initializing an Array (Contd.)
 Size of an array should be specified at the time of its
  declaration
  Example:
  char err[]; //ERROR!! will not compile
 An array cannot be initialized with another array
    Example:
    xyz = abc;             // ERROR!!




Ā©NIIT                                 OOPS/Lesson 2/Slide 12 of 20
Creating Objects


String Constant
 Is an array of characters terminated by a
  NULL(ā€˜0ā€™)
  Example:
  char str[] = SANDY;
  Can be schematically represented as:




Ā©NIIT                               OOPS/Lesson 2/Slide 13 of 20
Creating Objects


Problem Statement 2.D.1
As a member of a team that is developing the billing
system software for Diaz Telecommunications Inc., you
have been assigned the task of creating a software
module that accepts the following customer details and
displays it.
1.Mobile number, containing a maximum of 12
  characters
2. Name, containing a maximum of 25 characters
3. Date of birth, containing a maximum of 10 characters
4. Billing address, containing a maximum of 50
  characters

Ā©NIIT                               OOPS/Lesson 2/Slide 14 of 20
Creating Objects


Problem Statement 2.D.1 (Contd.)
5. City, containing a maximum of 25 characters
6. Residence phone number, containing a maximum of
  13 characters.
7. Amount outstanding, containing decimal values




Ā©NIIT                               OOPS/Lesson 2/Slide 15 of 20
Creating Objects


Problem Statement 2.P.1
As a part of the team that is developing the billing system
software for Diaz Telecommunications Inc., you have
been assigned the task of writing a program that accepts
dealer details. The details to be captured are given
below:
 First Name
 Last Name
 City
 Phone number




Ā©NIIT                                 OOPS/Lesson 2/Slide 16 of 20
Creating Objects


Problem Statement 2.P.1 (Contd.)
Write a C++ program to accept and display the dealer
details.
The dealer details should be displayed in the following
format:
First name:             Last name:

City:                   Phone number:




Ā©NIIT                                OOPS/Lesson 2/Slide 17 of 20
Creating Objects

Summary
In this lesson, you learned that:
 A variable is a named location in memory that
  contains a specific value
 A data type defines the type of data that can be stored
  in a variable
 Member variables are declared inside the class body
 The cin object is used to accept input from the
  keyboard
 The contents of header files are inserted into a
  program with the #include directive
 The C++ program execution starts from the first
  statement of the main()function
Ā©NIIT                                OOPS/Lesson 2/Slide 18 of 20
Creating Objects


Summary (Contd.)
 Comment entries are notes that a programmer writes
  anywhere in the code so that any programmer reading
  the code will understand it better
 An object is an instance of a class
 The compiler is a software that translates a program
  written in a language like C++ into machine language
  and the file containing the translated program is called
  the object code of your program
 Linking combines your object code with the object
  code of the functions you use and adds some
  standard startup code to produce a run-time version of
  your program
Ā©NIIT                                   OOPS/Lesson 2/Slide 19 of 20
Creating Objects


Summary (Contd.)
 The Dos-based DJGPP compiler for C++ generates
  the executable code and stores it in a file named
  a.exe
 An array is a collection of elements of a single data
  type stored in adjacent memory locations
 The array can be initialized when it is defined or later
 An array must be given a constant dimension size,
  which should be at least 1
 Each element of an array can be accessed by its
  subscript number


Ā©NIIT                                 OOPS/Lesson 2/Slide 20 of 20

More Related Content

What's hot

Python-oop
Python-oopPython-oop
Python-oopRTS Tech
Ā 
08 iec t1_s1_oo_ps_session_11
08 iec t1_s1_oo_ps_session_1108 iec t1_s1_oo_ps_session_11
08 iec t1_s1_oo_ps_session_11Niit Care
Ā 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamySrichandan Sobhanayak
Ā 
04 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_0504 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_05Niit Care
Ā 
Sem1 plt xp_02
Sem1 plt xp_02Sem1 plt xp_02
Sem1 plt xp_02Niit Care
Ā 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
Ā 
10 iec t1_s1_oo_ps_session_14
10 iec t1_s1_oo_ps_session_1410 iec t1_s1_oo_ps_session_14
10 iec t1_s1_oo_ps_session_14Niit Care
Ā 
Pinkle Makhijani ,BCA 2nd Year
Pinkle  Makhijani ,BCA 2nd YearPinkle  Makhijani ,BCA 2nd Year
Pinkle Makhijani ,BCA 2nd Yeardezyneecole
Ā 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingNYversity
Ā 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1mohamedsamyali
Ā 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08Niit Care
Ā 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
Ā 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questionsestoredesignerclothi
Ā 
11 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_1611 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_16Niit Care
Ā 

What's hot (19)

Python-oop
Python-oopPython-oop
Python-oop
Ā 
08 iec t1_s1_oo_ps_session_11
08 iec t1_s1_oo_ps_session_1108 iec t1_s1_oo_ps_session_11
08 iec t1_s1_oo_ps_session_11
Ā 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Ā 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
Ā 
Oops Quiz
Oops QuizOops Quiz
Oops Quiz
Ā 
04 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_0504 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_05
Ā 
Sem1 plt xp_02
Sem1 plt xp_02Sem1 plt xp_02
Sem1 plt xp_02
Ā 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
Ā 
10 iec t1_s1_oo_ps_session_14
10 iec t1_s1_oo_ps_session_1410 iec t1_s1_oo_ps_session_14
10 iec t1_s1_oo_ps_session_14
Ā 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
Ā 
Pinkle Makhijani ,BCA 2nd Year
Pinkle  Makhijani ,BCA 2nd YearPinkle  Makhijani ,BCA 2nd Year
Pinkle Makhijani ,BCA 2nd Year
Ā 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
Ā 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
Ā 
Unit i
Unit iUnit i
Unit i
Ā 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08
Ā 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Ā 
Lec4
Lec4Lec4
Lec4
Ā 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
Ā 
11 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_1611 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_16
Ā 

Similar to Creating Objects in C

T2
T2T2
T2lksoo
Ā 
Oops recap
Oops recapOops recap
Oops recapNiit Care
Ā 
Dbva dotnet programmer_guide_chapter8
Dbva dotnet programmer_guide_chapter8Dbva dotnet programmer_guide_chapter8
Dbva dotnet programmer_guide_chapter8Shakeel Mujahid
Ā 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13Niit Care
Ā 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkAbdullahNadeem78
Ā 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
Ā 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
Ā 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...Make Mannan
Ā 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Peter R. Egli
Ā 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperMalathi Senthil
Ā 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
Ā 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1studrohassanie
Ā 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
Ā 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
Ā 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfjorgeulises3
Ā 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming Rokonuzzaman Rony
Ā 

Similar to Creating Objects in C (20)

2621008 - C++ 1
2621008 -  C++ 12621008 -  C++ 1
2621008 - C++ 1
Ā 
T2
T2T2
T2
Ā 
Oops recap
Oops recapOops recap
Oops recap
Ā 
Dbva dotnet programmer_guide_chapter8
Dbva dotnet programmer_guide_chapter8Dbva dotnet programmer_guide_chapter8
Dbva dotnet programmer_guide_chapter8
Ā 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13
Ā 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net framework
Ā 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
Ā 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
Ā 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
Ā 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Ā 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
Ā 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
Ā 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question Paper
Ā 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
Ā 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
Ā 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
Ā 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
Ā 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
Ā 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming
Ā 
C Theory
C TheoryC Theory
C Theory
Ā 

More from Niit Care

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 bNiit Care
Ā 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 bNiit Care
Ā 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 aNiit Care
Ā 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 cNiit Care
Ā 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 bNiit Care
Ā 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 aNiit Care
Ā 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 cNiit Care
Ā 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 bNiit Care
Ā 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 aNiit Care
Ā 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 cNiit Care
Ā 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 aNiit Care
Ā 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 cNiit Care
Ā 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-cNiit Care
Ā 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-bNiit Care
Ā 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-aNiit Care
Ā 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-cNiit Care
Ā 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-bNiit Care
Ā 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-aNiit Care
Ā 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 bNiit Care
Ā 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 cNiit Care
Ā 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
Ā 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
Ā 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
Ā 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
Ā 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
Ā 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
Ā 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
Ā 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
Ā 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
Ā 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
Ā 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
Ā 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
Ā 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
Ā 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
Ā 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
Ā 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
Ā 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
Ā 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
Ā 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
Ā 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
Ā 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĆŗjo
Ā 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
Ā 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
Ā 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
Ā 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜RTylerCroy
Ā 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
Ā 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Ā 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
Ā 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Ā 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
Ā 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Ā 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Ā 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
Ā 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Ā 

Creating Objects in C

  • 1. Creating Objects Objectives In this lesson, you will learn to: Identify the built-in data types in C++ Use variables in C++ programs Write and execute C++ programs Use arrays in C++ programs Ā©NIIT OOPS/Lesson 2/Slide 1 of 20
  • 2. Creating Objects Variables Are Named locations in memory that contain specific values Rules for naming variables in C++ Should not have any embedded spaces or symbols Should be unique Can have any number of characters Must begin with a letter or an underscore, which may be followed by a sequence of letters, digits, or underscores Keywords cannot be used as variable names Ā©NIIT OOPS/Lesson 2/Slide 2 of 20
  • 3. Creating Objects Data Types Define the type of data that can be stored in a variable Built-in data types are: char - For characters and strings int - For integers float - For numbers with decimals Ā©NIIT OOPS/Lesson 2/Slide 3 of 20
  • 4. Creating Objects Data Types (Contd.) Number of Bytes on a Minimum Maximum Data Type 32-bit Value Value Computer char 1 -128 127 int 4 -2^31 (2^31)-1 float 4 -10^39 10^39 Ā©NIIT OOPS/Lesson 2/Slide 4 of 20
  • 5. Creating Objects Member Variables Are used to implement attributes in C++ Are declared inside the class body Example: class Car { float price; }; Ā©NIIT OOPS/Lesson 2/Slide 5 of 20
  • 6. Creating Objects Accepting and Storing Values in Member Variables The cin object is used to accept input from the user Example: class Car { float price; public: void acceptprice() { cout ā€œEnter Price :ā€;cin price; } }; Ā©NIIT OOPS/Lesson 2/Slide 6 of 20
  • 7. Creating Objects Writing and Executing a C++ Program The iostream header file Is called a pre-processor directive The main() function Is mandatory in C++ programming for program execution Creating objects Is required for reserving memory at the time of declaration Ā©NIIT OOPS/Lesson 2/Slide 7 of 20
  • 8. Creating Objects Compiling, Linking, and Executing a Program Is done by following the listed steps: 1. The C++ program should contain the #include statement, the class declaration and member function definition, and the main() function. 2. Save the file with a .cc extension. 3. Compile the file using the gpp file name command from the command prompt. 4. Execute the file using the a.out command from the command prompt. Ā©NIIT OOPS/Lesson 2/Slide 8 of 20
  • 9. Creating Objects Executing C++ Programs a.out executes the initial startup code The startup code executes the main() function When the main() function finishes execution, it sends a status of execution to the operating system Ā©NIIT OOPS/Lesson 2/Slide 9 of 20
  • 10. Creating Objects Array Is a collection of elements of a single data type stored in adjacent memory locations Syntax: data_type variable_name[dimension_size]; Example: int arr[5]; Ā©NIIT OOPS/Lesson 2/Slide 10 of 20
  • 11. Creating Objects Declaring and Initializing an Array Example: arr[0] = 14; arr[1] = 15; arr[2] = 17; arr[3] = 45; arr[2] = 81; Example: int arr[5] = {14, 15, 17, 45, 81}; Example: int arr[] = {14, 15, 17, 45, 81}; Ā©NIIT OOPS/Lesson 2/Slide 11 of 20
  • 12. Creating Objects Declaring and Initializing an Array (Contd.) Size of an array should be specified at the time of its declaration Example: char err[]; //ERROR!! will not compile An array cannot be initialized with another array Example: xyz = abc; // ERROR!! Ā©NIIT OOPS/Lesson 2/Slide 12 of 20
  • 13. Creating Objects String Constant Is an array of characters terminated by a NULL(ā€˜0ā€™) Example: char str[] = SANDY; Can be schematically represented as: Ā©NIIT OOPS/Lesson 2/Slide 13 of 20
  • 14. Creating Objects Problem Statement 2.D.1 As a member of a team that is developing the billing system software for Diaz Telecommunications Inc., you have been assigned the task of creating a software module that accepts the following customer details and displays it. 1.Mobile number, containing a maximum of 12 characters 2. Name, containing a maximum of 25 characters 3. Date of birth, containing a maximum of 10 characters 4. Billing address, containing a maximum of 50 characters Ā©NIIT OOPS/Lesson 2/Slide 14 of 20
  • 15. Creating Objects Problem Statement 2.D.1 (Contd.) 5. City, containing a maximum of 25 characters 6. Residence phone number, containing a maximum of 13 characters. 7. Amount outstanding, containing decimal values Ā©NIIT OOPS/Lesson 2/Slide 15 of 20
  • 16. Creating Objects Problem Statement 2.P.1 As a part of the team that is developing the billing system software for Diaz Telecommunications Inc., you have been assigned the task of writing a program that accepts dealer details. The details to be captured are given below: First Name Last Name City Phone number Ā©NIIT OOPS/Lesson 2/Slide 16 of 20
  • 17. Creating Objects Problem Statement 2.P.1 (Contd.) Write a C++ program to accept and display the dealer details. The dealer details should be displayed in the following format: First name: Last name: City: Phone number: Ā©NIIT OOPS/Lesson 2/Slide 17 of 20
  • 18. Creating Objects Summary In this lesson, you learned that: A variable is a named location in memory that contains a specific value A data type defines the type of data that can be stored in a variable Member variables are declared inside the class body The cin object is used to accept input from the keyboard The contents of header files are inserted into a program with the #include directive The C++ program execution starts from the first statement of the main()function Ā©NIIT OOPS/Lesson 2/Slide 18 of 20
  • 19. Creating Objects Summary (Contd.) Comment entries are notes that a programmer writes anywhere in the code so that any programmer reading the code will understand it better An object is an instance of a class The compiler is a software that translates a program written in a language like C++ into machine language and the file containing the translated program is called the object code of your program Linking combines your object code with the object code of the functions you use and adds some standard startup code to produce a run-time version of your program Ā©NIIT OOPS/Lesson 2/Slide 19 of 20
  • 20. Creating Objects Summary (Contd.) The Dos-based DJGPP compiler for C++ generates the executable code and stores it in a file named a.exe An array is a collection of elements of a single data type stored in adjacent memory locations The array can be initialized when it is defined or later An array must be given a constant dimension size, which should be at least 1 Each element of an array can be accessed by its subscript number Ā©NIIT OOPS/Lesson 2/Slide 20 of 20