SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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

Was ist angesagt? (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
 

Ähnlich wie Creating Objects in C

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

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Kürzlich hochgeladen (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

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