SlideShare a Scribd company logo
1 of 36
An Introduction To Software
Development Using C++
Class #2:
An Introduction To
C++
What’s In A Name?
• The “C” programming language was developed by Dennis Ritchie at Bell
Laboratories 1969-1973. He wanted to port the Unix operating system from a
PDP-7 to a PDP-11 & he didn’t want to do it in assembly language.
• Yes, the “B” language already existed. However, it sucked so he created “C”
• C is available for most computers and is hardware independent. With careful
design, it’s possible to write C programs that are portable to most computers.
• The widespread use of C with various kinds of computers (sometimes called
hardware platforms) unfortunately led to many variations. A standard version of C
was needed.
• The American National Standards Institute (ANSI) cooperated with the
International Organization for Standardization (ISO) to standardize C worldwide;
the joint standard document was published in 1990 and is referred to as ANSI/ISO
9899: 1990.
What Is C++?
• C++, an extension of C, was developed by
Bjarne Stroustrup in the early 1980s at Bell
Laboratories.
• C++ provides a number of features that
“spruce up” the C language, but more
importantly, it provides capabilities for
object-oriented programming.
What Do You Have To Do To
“Learn” C++?
Learn the C++
Language
Learn how to use the
classes and functions
in the
C++ Standard Library
#1 #2
A Typical C++ Program
Development Environment
Step #1: Write the program!
// Text-printing program.
#include <iostream> // allows program to output data to the screen
// function main begins program execution
int main()
{
std::cout << "Welcome to C++!n"; // display message
return 0; // indicate that program ended successfully
} // end function main
A Typical C++ Program
Development Environment
Step #2: Preprocess the program
// Text-printing program.
#include <iostream> // allows program to output data to the screen
// function main begins program execution
int main()
{
std::cout << "Welcome to C++!n"; // display message
return 0; // indicate that program ended successfully
} // end function main
iostream
A Typical C++ Program
Development Environment
Step #3: Compile the C++ program
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
A Typical C++ Program
Development Environment
Step #4: Link the C++ program
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
A Typical C++ Program
Development Environment
Step #5: Load the C++ program
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
00000100 00010010 00010001 00100100
00000000 11111001 00000111 01010101
What’s Up With This Object
Orientated Stuff?
Procedural Languages
One long piece of code
where data and logic
are all mixed in
together.
1 #
2 # Sample program that demonstrates the print function.
3 #
4
5 # Prints 7
6 print(3 + 4)
7
8 # Prints “Hello World!” in two lines.
9 print("Hello")
10 print("World!")
11
12 # Prints multiple values with a single print function call.
13 print("My favorite numbers are", 3 + 4, "and", 3 + 10)
14
15 # Prints three lines of text with a blank line.
16 print("Goodbye")
17 print()
18 print("Hope to see you again")
What’s Up With This Object
Orientated Stuff?
• Each object represents a different part
of the application.
• Each object contains it’s own data & it’s
own logic.
• The objects communicate between
themselves.
• Objects are designed to represent how
you talk and think about the actual
problem.
• Objects are meant to make thinking
about your program easier.
• Object orientation is just an idea that is
supported by C++
I Know How To Program, Why
Bother With This C++ Stuff?
• Why is so much attention today focused on object-oriented programming
in general and C++ in particular?
ANSWER: Object-oriented programming enables the programmer to build
reusable software components that model items in the real world.
Building software quickly, correctly, and economically has been an elusive
goal in the software industry.
The modular, object-oriented design and implementation approach has
been found to increase productivity 10 to 100 times over conventional
programming languages while reducing development time, errors, and
cost. C++ is extremely popular because it is a superset of the widely used C
programming language. Programmers already familiar with C have an
easier time learning C++.
Image Credit: www.dreamstime.com
What are “Objects”?
Objects (both software and real)
have two ways that they can
be represented:
A. Attributes
B. Behaviors
What are “Objects”?
The gas pedal hides from the driver the complex
mechanisms that actually make the car go faster,
just as the brake pedal hides the mechanisms that
slow the car, and the steering wheel “hides” the
mechanisms that turn the car.
This enables people with little or no knowledge of
how engines, braking and steering mechanisms
work to drive a car easily.
Objects work the same way – they hide your code
from other developers so that they don’t have to
know HOW you did something, just what your
code DOES.
Member Functions and Classes
Performing a task in a program requires a member function, which houses
the program statements that actually perform its task. The member function
hides these statements from its user, just as the accelerator pedal of a car
hides from the driver the mechanisms of making the car go faster.
In C++, we create a program unit called a class to house the set of
member functions that perform the class’s tasks.
For example, a class that represents a bank account might contain one
member function to deposit money to an account, another to withdraw
money from an account and a third to inquire what the account’s current
balance is.
A class is similar in concept to a car’s engineering drawings, which house
the design of an accelerator pedal, steering wheel, and so on.
What Is A Class?
• It’s a blueprint, the definition, the description.
• It is not the thing itself!
Image Credit: www.chickslovethecar.com
Example Classes
Restaurant Review User
Textbox Button Window
Date Timezone Daylight Savings
Instantiation
You must build an object of a class before a program can perform the tasks
that the class’s member functions define.
The process of doing this is called instantiation. An object is then referred to
as an instance of its class.
Object
• The object is created from the class
• One class can create multiple objects
Image Credit: http://8z4.net/images/blueprint-/5.html
Reuse
You can reuse a class many times to build many objects.
Reuse of existing classes when building new classes and programs saves
time and effort.
Reuse also helps you build more reliable and effective systems, because
existing classes and components often have gone through extensive testing,
debugging and performance tuning.
Messages and
Member Function Calls
When you drive a car, pressing its gas pedal sends a message to the car to
perform a task—that is, to go faster.
Similarly, you send messages to an object.
Each message is implemented as a member function call that tells a member
function of the object to perform its task.
For example, a program might call a particular bank account object’s deposit
member function to increase the account’s balance.
Attributes and Data Members
A car, besides having capabilities to accomplish tasks, also has attributes,
such as its color, its number of doors, the amount of gas in its tank, its current
speed and its record of total miles driven (i.e., its odometer reading).
As you drive an actual car, these attributes are carried along with the car.
Every car maintains its own attributes. For example, each car knows how
much gas is in its own gas tank, but not how much is in the tanks of other
cars.
An object, similarly, has attributes that it carries along as it’s used in a
program. These attributes are specified as part of the object’s class. For
example, a bank account object has a balance attribute that represents the
amount of money in the account. Each bank account object knows the
balance in the account it represents, but not the balances of the other
accounts in the bank. Attributes are specified by the class’s data members.
What Does A Class Define?
Attributes
Name
Height
Weight
Gender
Age
Behavior
Walk
Run
Jump
Speak
Sleep
Let’s say that our
class is designed
to describe a
person…
Encapsulation
Classes encapsulate (i.e., wrap) attributes and member functions into
objects—an object’s attributes and member functions are intimately related.
Objects may communicate with one another, but they’re normally not allowed
to know how other objects are implemented—implementation details are
hidden within the objects themselves.
This information hiding, as we’ll see, is crucial to good software engineering.
Encapsulation
Encapsulated
Inheritance
A new class of objects can be created quickly and conveniently by
inheritance—the new class absorbs the characteristics of an existing class,
possibly customizing them and adding unique characteristics of its own.
In our car analogy, an object of class “convertible” certainly is an object of the
more general class “automobile,” but more specifically, the roof can be raised
or lowered.
Object-Oriented Analysis
and Design (OOAD)
To create the best solutions, you should follow a detailed analysis process for
determining your project’s requirements (i.e., defining what the system is supposed
to do) and developing a design that satisfies them (i.e., deciding how the system
should do it).
Ideally, you’d go through this process and carefully review the design (and have your
design reviewed by other software professionals) before writing any code.
If this process involves analyzing and designing your system from an object-oriented
point of view, it’s called an object-oriented analysis and design (OOAD) process.
Languages like C++ are object oriented. Programming in such a language, called
object-oriented programming (OOP), allows you to implement an object-oriented
design as a working system.
In-Class Fun:
Running A C++ Program
What you are going to be doing:
1. Locate and download the working C++ program that I’ve given you
2. Start up the C++ compiler
3. Compile the code
4. Run the code
5. Quit the compiler
What We Covered Today
1. Where did C / C++ come
from?
2. What happens when you
compile a C++ program?
3. What are “objects”?
4. Compiling and running
your very 1st C++
program.
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. Taking apart our first
C++ program
2. Displaying data on the
screen
3. Output streams
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/
An Introduction To Software
Development Using C++
Class #2:
Introduction To The
In-Class Programming
Assignment
Today’s In-Class C++
Programming Assignment
• Write a C++ program that will ask you to enter
your age. It will then print out the following
statement:
Hello, you have been alive for <x> days.
Assume every year has 365 days.
Answer To Today’s Challenge
// In-Class Exercise #1- Days Alive
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int main()
{
int age;
cout << "Please Enter Your Age ";
cin >> age;
cout << "Hello, you have been alive for " << age * 365 << " days.";
return(0);
}
Image Credit: www.clipartpanda.com
What’s In Your C++Toolbox?
cout
cin
What We Covered Today
1. Got our first in-class
programming
assignment.
2. Found out how many
days we’ve been alive.
3. Found out how many
days we’ll probably live
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. How to find out which
number is larger?
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

More Related Content

What's hot

Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
JavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGIJavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGIAashish Jain
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Ranel Padon
 
C# classes
C#   classesC#   classes
C# classesTiago
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperNyros Technologies
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPsRavi Bhadauria
 

What's hot (20)

Dot net introduction
Dot net introductionDot net introduction
Dot net introduction
 
OOP Programs
OOP ProgramsOOP Programs
OOP Programs
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
 
Php Oop
Php OopPhp Oop
Php Oop
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Class 1 blog
Class 1 blogClass 1 blog
Class 1 blog
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
JavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGIJavaScript, VBScript, AJAX, CGI
JavaScript, VBScript, AJAX, CGI
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
 
C# classes
C#   classesC#   classes
C# classes
 
Application package
Application packageApplication package
Application package
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Csharp
CsharpCsharp
Csharp
 
Oops in php
Oops in phpOops in php
Oops in php
 

Similar to Intro To C++ - Class 2 - An Introduction To C++

Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...NicheTech Com. Solutions Pvt. Ltd.
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementationthe_wumberlog
 
Online advertising management system
Online advertising management systemOnline advertising management system
Online advertising management systemYesu Raj
 
Online advertising management system
Online advertising management systemOnline advertising management system
Online advertising management systemYesu Raj
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptxHeadoftheDepartment
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentationMennan Tekbir
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0DivyaR219113
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programmingrprajat007
 
Over view of Technologies
Over view of TechnologiesOver view of Technologies
Over view of TechnologiesChris Mitchell
 
Required computer skills program devlopment
Required computer skills program devlopmentRequired computer skills program devlopment
Required computer skills program devlopmentHubert Shanthan
 
Online bus pass registration
Online bus pass registrationOnline bus pass registration
Online bus pass registrationYesu Raj
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEMMansi Tyagi
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]Rome468
 

Similar to Intro To C++ - Class 2 - An Introduction To C++ (20)

Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementation
 
Online advertising management system
Online advertising management systemOnline advertising management system
Online advertising management system
 
Online advertising management system
Online advertising management systemOnline advertising management system
Online advertising management system
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programming
 
Over view of Technologies
Over view of TechnologiesOver view of Technologies
Over view of Technologies
 
Required computer skills program devlopment
Required computer skills program devlopmentRequired computer skills program devlopment
Required computer skills program devlopment
 
10tait
10tait10tait
10tait
 
Chapter 10
Chapter 10 Chapter 10
Chapter 10
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Oops index
Oops indexOops index
Oops index
 
Online bus pass registration
Online bus pass registrationOnline bus pass registration
Online bus pass registration
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
C++ & VISUAL C++
C++ & VISUAL C++ C++ & VISUAL C++
C++ & VISUAL C++
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Intro To C++ - Class 2 - An Introduction To C++

  • 1. An Introduction To Software Development Using C++ Class #2: An Introduction To C++
  • 2. What’s In A Name? • The “C” programming language was developed by Dennis Ritchie at Bell Laboratories 1969-1973. He wanted to port the Unix operating system from a PDP-7 to a PDP-11 & he didn’t want to do it in assembly language. • Yes, the “B” language already existed. However, it sucked so he created “C” • C is available for most computers and is hardware independent. With careful design, it’s possible to write C programs that are portable to most computers. • The widespread use of C with various kinds of computers (sometimes called hardware platforms) unfortunately led to many variations. A standard version of C was needed. • The American National Standards Institute (ANSI) cooperated with the International Organization for Standardization (ISO) to standardize C worldwide; the joint standard document was published in 1990 and is referred to as ANSI/ISO 9899: 1990.
  • 3. What Is C++? • C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories. • C++ provides a number of features that “spruce up” the C language, but more importantly, it provides capabilities for object-oriented programming.
  • 4. What Do You Have To Do To “Learn” C++? Learn the C++ Language Learn how to use the classes and functions in the C++ Standard Library #1 #2
  • 5. A Typical C++ Program Development Environment Step #1: Write the program! // Text-printing program. #include <iostream> // allows program to output data to the screen // function main begins program execution int main() { std::cout << "Welcome to C++!n"; // display message return 0; // indicate that program ended successfully } // end function main
  • 6. A Typical C++ Program Development Environment Step #2: Preprocess the program // Text-printing program. #include <iostream> // allows program to output data to the screen // function main begins program execution int main() { std::cout << "Welcome to C++!n"; // display message return 0; // indicate that program ended successfully } // end function main iostream
  • 7. A Typical C++ Program Development Environment Step #3: Compile the C++ program 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101
  • 8. A Typical C++ Program Development Environment Step #4: Link the C++ program 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101
  • 9. A Typical C++ Program Development Environment Step #5: Load the C++ program 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101 00000100 00010010 00010001 00100100 00000000 11111001 00000111 01010101
  • 10. What’s Up With This Object Orientated Stuff? Procedural Languages One long piece of code where data and logic are all mixed in together. 1 # 2 # Sample program that demonstrates the print function. 3 # 4 5 # Prints 7 6 print(3 + 4) 7 8 # Prints “Hello World!” in two lines. 9 print("Hello") 10 print("World!") 11 12 # Prints multiple values with a single print function call. 13 print("My favorite numbers are", 3 + 4, "and", 3 + 10) 14 15 # Prints three lines of text with a blank line. 16 print("Goodbye") 17 print() 18 print("Hope to see you again")
  • 11. What’s Up With This Object Orientated Stuff? • Each object represents a different part of the application. • Each object contains it’s own data & it’s own logic. • The objects communicate between themselves. • Objects are designed to represent how you talk and think about the actual problem. • Objects are meant to make thinking about your program easier. • Object orientation is just an idea that is supported by C++
  • 12. I Know How To Program, Why Bother With This C++ Stuff? • Why is so much attention today focused on object-oriented programming in general and C++ in particular? ANSWER: Object-oriented programming enables the programmer to build reusable software components that model items in the real world. Building software quickly, correctly, and economically has been an elusive goal in the software industry. The modular, object-oriented design and implementation approach has been found to increase productivity 10 to 100 times over conventional programming languages while reducing development time, errors, and cost. C++ is extremely popular because it is a superset of the widely used C programming language. Programmers already familiar with C have an easier time learning C++. Image Credit: www.dreamstime.com
  • 13. What are “Objects”? Objects (both software and real) have two ways that they can be represented: A. Attributes B. Behaviors
  • 14. What are “Objects”? The gas pedal hides from the driver the complex mechanisms that actually make the car go faster, just as the brake pedal hides the mechanisms that slow the car, and the steering wheel “hides” the mechanisms that turn the car. This enables people with little or no knowledge of how engines, braking and steering mechanisms work to drive a car easily. Objects work the same way – they hide your code from other developers so that they don’t have to know HOW you did something, just what your code DOES.
  • 15. Member Functions and Classes Performing a task in a program requires a member function, which houses the program statements that actually perform its task. The member function hides these statements from its user, just as the accelerator pedal of a car hides from the driver the mechanisms of making the car go faster. In C++, we create a program unit called a class to house the set of member functions that perform the class’s tasks. For example, a class that represents a bank account might contain one member function to deposit money to an account, another to withdraw money from an account and a third to inquire what the account’s current balance is. A class is similar in concept to a car’s engineering drawings, which house the design of an accelerator pedal, steering wheel, and so on.
  • 16. What Is A Class? • It’s a blueprint, the definition, the description. • It is not the thing itself! Image Credit: www.chickslovethecar.com
  • 17. Example Classes Restaurant Review User Textbox Button Window Date Timezone Daylight Savings
  • 18. Instantiation You must build an object of a class before a program can perform the tasks that the class’s member functions define. The process of doing this is called instantiation. An object is then referred to as an instance of its class.
  • 19. Object • The object is created from the class • One class can create multiple objects Image Credit: http://8z4.net/images/blueprint-/5.html
  • 20. Reuse You can reuse a class many times to build many objects. Reuse of existing classes when building new classes and programs saves time and effort. Reuse also helps you build more reliable and effective systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning.
  • 21. Messages and Member Function Calls When you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster. Similarly, you send messages to an object. Each message is implemented as a member function call that tells a member function of the object to perform its task. For example, a program might call a particular bank account object’s deposit member function to increase the account’s balance.
  • 22. Attributes and Data Members A car, besides having capabilities to accomplish tasks, also has attributes, such as its color, its number of doors, the amount of gas in its tank, its current speed and its record of total miles driven (i.e., its odometer reading). As you drive an actual car, these attributes are carried along with the car. Every car maintains its own attributes. For example, each car knows how much gas is in its own gas tank, but not how much is in the tanks of other cars. An object, similarly, has attributes that it carries along as it’s used in a program. These attributes are specified as part of the object’s class. For example, a bank account object has a balance attribute that represents the amount of money in the account. Each bank account object knows the balance in the account it represents, but not the balances of the other accounts in the bank. Attributes are specified by the class’s data members.
  • 23. What Does A Class Define? Attributes Name Height Weight Gender Age Behavior Walk Run Jump Speak Sleep Let’s say that our class is designed to describe a person…
  • 24. Encapsulation Classes encapsulate (i.e., wrap) attributes and member functions into objects—an object’s attributes and member functions are intimately related. Objects may communicate with one another, but they’re normally not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. This information hiding, as we’ll see, is crucial to good software engineering.
  • 26. Inheritance A new class of objects can be created quickly and conveniently by inheritance—the new class absorbs the characteristics of an existing class, possibly customizing them and adding unique characteristics of its own. In our car analogy, an object of class “convertible” certainly is an object of the more general class “automobile,” but more specifically, the roof can be raised or lowered.
  • 27. Object-Oriented Analysis and Design (OOAD) To create the best solutions, you should follow a detailed analysis process for determining your project’s requirements (i.e., defining what the system is supposed to do) and developing a design that satisfies them (i.e., deciding how the system should do it). Ideally, you’d go through this process and carefully review the design (and have your design reviewed by other software professionals) before writing any code. If this process involves analyzing and designing your system from an object-oriented point of view, it’s called an object-oriented analysis and design (OOAD) process. Languages like C++ are object oriented. Programming in such a language, called object-oriented programming (OOP), allows you to implement an object-oriented design as a working system.
  • 28. In-Class Fun: Running A C++ Program What you are going to be doing: 1. Locate and download the working C++ program that I’ve given you 2. Start up the C++ compiler 3. Compile the code 4. Run the code 5. Quit the compiler
  • 29. What We Covered Today 1. Where did C / C++ come from? 2. What happens when you compile a C++ program? 3. What are “objects”? 4. Compiling and running your very 1st C++ program. Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 30. What We’ll Be Covering Next Time 1. Taking apart our first C++ program 2. Displaying data on the screen 3. Output streams Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/
  • 31. An Introduction To Software Development Using C++ Class #2: Introduction To The In-Class Programming Assignment
  • 32. Today’s In-Class C++ Programming Assignment • Write a C++ program that will ask you to enter your age. It will then print out the following statement: Hello, you have been alive for <x> days. Assume every year has 365 days.
  • 33. Answer To Today’s Challenge // In-Class Exercise #1- Days Alive #include <iostream> using std::cout; using std::endl; using std::cin; int main() { int age; cout << "Please Enter Your Age "; cin >> age; cout << "Hello, you have been alive for " << age * 365 << " days."; return(0); } Image Credit: www.clipartpanda.com
  • 34. What’s In Your C++Toolbox? cout cin
  • 35. What We Covered Today 1. Got our first in-class programming assignment. 2. Found out how many days we’ve been alive. 3. Found out how many days we’ll probably live Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 36. What We’ll Be Covering Next Time 1. How to find out which number is larger? Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Editor's Notes

  1. New name for the class I know what this means Technical professionals are who get hired This means much more than just having a narrow vertical knowledge of some subject area. It means that you know how to produce an outcome that I value. I’m willing to pay you to do that.
  2. New name for the class I know what this means Technical professionals are who get hired This means much more than just having a narrow vertical knowledge of some subject area. It means that you know how to produce an outcome that I value. I’m willing to pay you to do that.