SlideShare a Scribd company logo
An Introduction To Software
Development Using C++
Class #3:
An Introduction To
C++ Programming
So What’s The Plan?
1. I provide you with a C++ program
2. You load it into the Microsoft Visual C++
compiler
3. You compile the program
4. You run the program
5. We all rejoice!
You’re Very 3rd Ever C++ Program!
01: // Title: You’re Very 3rd Ever C++ Program
02: // Description: Program to print some text on the screen
03: #include <iostream> // allows program to output data to the
screen
04:
05: // function main begins program execution
06: int main()
07: {
08: std::cout << “Hello World!n"; // display message
09:
10: return 0; // indicate that program ended successfully
11: } // end function main
Now Let’s Screw Things Up…
• Delete line #11, try to run the program…
• Restore line #11
• On line #8, delete one of the “, try to run the
program…
• Restore line #8
• Save the file as “03 Class - 1st Program.c”
• Load this file and try to compile it.
C++ CSI!
C++
Taking Apart A Sony Walkman
Taking Apart Our First Program
• Comments: lines 1 & 2
– Comments each begin with //, indicating that the remainder of each line is a
comment. You insert comments to document your programs and to help other
people read and understand them.
– Comments do not cause the computer to perform any action when the
program is run—they’re ignored by the C++ compiler and do not cause any
machine-language object code to be generated.
– A comment beginning with // is called a single-line comment because it
terminates at the end of the current line.
[Note: You also may use C’s style in which a comment—possibly containing
many lines—begins with /* and ends with */.]
// Title: You’re Very 1st Ever C++ Program
// Description: Program to print some text on the screen
A Dr. Jim “Suggestion”!
• The first few lines of every program that you write should
be comments.
• You’ll want to give the name of the file that contains the
code.
• Then you’ll want to include your name – who created this
code?
• Then you’ll want to include a high-level description of just
exactly what the code does.
• The reason for doing all of this extra work is because next
week, next month, next year when you come back to this
code, you won’t be able to remember what it does.
Taking Apart Our First Program
• Preprocessor Directive: line 3
– This statement is a preprocessor directive, which is a message to the C++
preprocessor (processing done BEFORE compiling happens). Lines that begin
with # are processed by the preprocessor before the program is compiled.
– This line notifies the preprocessor to include in the program the contents of
the input/output stream header <iostream>.
– This header must be included for any program that outputs data to the screen
or inputs data from the keyboard using C++’s stream input/output.
#include <iostream> // allows program to output data to the screen
Taking Apart Our First Program
• Blank Lines and White Space: line 4
– Line 4 is simply a blank line.
– You use blank lines, space characters and tab characters (i.e.,“tabs”) to make
programs easier to read.
– Together, these characters are known as whitespace. White-space characters
are normally ignored by the compiler.
Taking Apart Our First Program
• Main Function: line 6
– The main function is a part of every C++ program.
– The parentheses after main indicate that main is a program building block
called a function.
– C++ programs typically consist of one or more functions and classes. Exactly
one function in every program must be named main.
– C++ programs begin executing at function main, even if main is not the first
function in the program.
int main()
Taking Apart Our First Program
• Main Function: line 6
– The keyword int to the left of main indicates that main “returns” an integer
(whole number) value. A keyword is a word in code that is reserved by C++ for
a specific use.
– The left brace, {, (line 7) must begin the body of every function. A
corresponding right brace, }, (line 11) must end each function’s body.
int main()
{
} // end function main
C++ Reserved Keywords
Taking Apart Our First Program
• An Output Statement: line 8
– This command instructs the computer to perform an action—namely, to print
the string of characters contained between the double quotation marks.
– White-space characters in strings are not ignored by the compiler.
– The entire line 8, including std::cout, the << operator, the string “Hello
World!n" and the semicolon (;), is called a statement.
– Every C++ statement must end with a semicolon
(also known as the statement terminator).
– Preprocessor directives (like #include) do not end with a semicolon.
std::cout << “Hello World!n"; // display message
• An Output Statement: line 8
– Output and input in C++ are accomplished with streams of characters.
– Thus, when the preceding statement is executed, it sends the stream of
characters Hello World!n to the standard output stream object—std::cout—
which is normally “connected” to the screen.
std::cout << “Hello World!n"; // display message
Taking Apart Our First Program
A Dr. Jim Suggestion!
• Your code can be dense and hard for your and everyone
else to read – indent!
• {
Indent the body of each function one level within
the braces that delimit the function’s body. This
makes a program’s functional structure stand out
and makes the program easier to read.
}
• Pick how many spaces you are going to indent and then
stick with it. Just using the “tab” key doesn’t work because
it produces different amounts of spaces on different
computers.
• Suggestion: indent everything by 3 spaces.
• The std Namespace
– The std:: before cout is required when we use names that we’ve brought into
the program by the preprocessor directive #include <iostream>.
– The notation std::cout specifies that we are using a name, in this case cout,
that belongs to “namespace” std.
– The names cin (the standard input stream) and cerr (the standard error
stream) also belong to namespace std.
– For now, you should simply remember to include std:: before
each mention of cout, cin and cerr in a program.
std::cout << “Hello World!n"; // display message
Taking Apart Our First Program
Taking Apart Our First Program
• The Stream Insertion Operator and Escape
Sequences
– The << operator is referred to as the stream insertion operator.
– When this program executes, the value to the operator’s right, the right
operand, is inserted in the output stream.
– Notice that the operator points in the direction of where the data goes. The
right operand’s characters normally print exactly as they appear between the
double quotes.
std::cout << “Hello World!n"; // display message
Taking Apart Our First Program
• The Stream Insertion Operator and Escape
Sequences
– However, the characters n are not printed on the screen. The backslash () is
called an escape character.
– It indicates that a “special” character is to be output. When a backslash is
encountered in a string of characters, the next character is combined with the
backslash to form an escape sequence.
– The escape sequence n means newline. It causes the cursor (i.e.,
the current screen-position indicator) to move to the beginning of
the next line on the screen.
std::cout << “Hello World!n"; // display message
Escape Character Sequences
Taking Apart Our First Program
• The return Statement
– The statement is one of several means we’ll use to exit a function.
– When the return statement is used at the end of main, as shown here, the
value 0 indicates that the program has terminated successfully.
– According to the C++ standard, if program execution reaches the end of main
without encountering a return statement, it’s assumed that the program
terminated successfully—exactly as when the last statement in main is a
return statement with the value 0.
– For that reason, I will omit the return statement at the end of main in
subsequent programs.
return 0; // indicate that program ended successfully
Time To Make Some Changes
• Software exists to be modified
• Customer requirements are always changing
• You will spend more time modifying existing
code than writing new code.
• Let’s now see if we can make some trivial
modifications to our code…
Software Change #1
• Change:
• To:
std::cout << “Hello World!n"; // display message
std::cout << “Hello ";
std::cout << “World!n";
What’s going on?
The first stream insertion prints Hello followed by a space, and because this string
did not end with n, the second stream insertion begins printing on the same line
immediately following the space.
Image Credit: imallvirtual.com
Software Change #2
• Change:
• To:
std::cout << “Hello ";
std::cout << “World!n";
What’s going on?
A single statement can print multiple lines by using newline characters. Each time
the n (newline) escape sequence is encountered in the output stream, the screen
cursor is positioned to the beginning of the next line. To get a blank line in your
output, place two newline characters back to back,
std::cout << “HellonWorldnn!";
Image Credit: shophopes.com
Mistakes That You’ll Make
• Common Programming Error - Forgetting to include the
<iostream> header in a program that inputs data from the
keyboard or outputs data to the screen causes the
compiler to issue an error message.
• Common Programming Error 2.2
Omitting the semicolon at the end of a C++ statement is a
syntax error. The syntax of a programming language
specifies the rules for creating proper programs in that
language. A syntax error occurs when the compiler
encounters code that violates C++’s language rules (i.e., its
syntax). The compiler normally issues an error message to
help you locate and fix the incorrect code. You cannot
execute your program until you correct all the syntax errors
in it.
Things You Need To Do
• Good Programming - Every program should begin
with a comment that describes the purpose of the
program.
• Good Programming Practice - Indent the body of
each function one level within the braces that
delimit the function’s body. This makes a program’s
functional structure stand out and makes the
program easier to read.
• Good Programming Practice - Set a convention for
the size of indent you prefer, then apply it uniformly.
The tab key may be used to create indents, but tab
stops may vary. We prefer three spaces per level of
indent.
What We Covered Today
1. Displaying data on the
screen.
2. In particular, you learned
to use the output stream
object cout to build
simple display programs.
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. We’ll explain how variables are stored in
and retrieved from memory.
2. You’ll also learn how to use arithmetic
operators to perform calculations.
3. We discuss the order in which C++ applies
operators (i.e., the rules of operator
precedence), as well as the associativity
of the operators.
4. You will learn how C++’s if statement
allows a program to make decisions.
5. Finally, we’ll introduced the equality and
relational operators, which you use to
form conditions in if statements.
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 #3:
Use Cases
An Example C++ Job Description
RESPONSIBILITIES:
• The position requires management of the design, layout, and production of client-
server and web-based applications
• Performs a developer role in building enterprise software solutions encompassing:
services and service layer, service integration to UI and data, UI components
• The candidate must work well in a team-like atmosphere in the development
information technology solutions for a wide-variety of public-sector clients
• REQUIREMENTS:
• Bachelor's degree in Programming, Computer Science or
related field plus a minimum of 3 years of related
experience
• Experienced in C, C++ coding methods and practices (2 - 5 years)
• Working knowledge of Red Hat Linux operating system
What Is UML?
• The Unified Modeling Language (UML) is a general-purpose modeling language in
the field of software engineering, which is designed to provide a standard way to
visualize the design of a system.
• It was created and developed by Grady Booch, Ivar Jacobson and James Rumbaugh
at Rational Software during 1994–95, with further development led by them
through 1996.
• In 1997 it was adopted as a standard by the Object Management Group (OMG),
and has been managed by this organization ever since. In 2005 the Unified
Modeling Language was also published by the International Organization for
Standardization (ISO) as an approved ISO standard. Since then it has been
periodically revised to cover the latest revision of UML.
• Though well-known and widely used in education and academic papers, as of 2013
UML is little-used in industry, and most such use is informal and ad hoc.
Image Credit: en.wikipedia.org
UML Diagrams
• There are three classifications of UML diagrams:
– Behavior diagrams. A type of diagram that depicts behavioral features
of a system or business process. This includes activity, state machine,
and use case diagrams as well as the four interaction diagrams.
– Interaction diagrams. A subset of behavior diagrams which emphasize
object interactions. This includes communication, interaction
overview, sequence, and timing diagrams.
– Structure diagrams. A type of diagram that depicts the elements of a
specification that are irrespective of time. This includes class,
composite structure, component, deployment, object, and package
diagrams.
Image Credit: code.google.com
UML Diagrams
A Use Case
• What is a Use Case?
– It’s a list of steps that a system needs to follow in
order to meet a goal.
• You have to define what is required and how those
requirements are going to be met
• Do NOT try to write code in a Use Case Diagram
• Consists of Shall vs. Should requirements
– A Use Case generally includes interactions with an
“Actor” (this is a human or an external system).
Image Credit: www.en.pms.ifi.lmu.de
Use Case Description
• Description
– The bank customer enters their card into
the machine and then types in their PIN.
Bank security then verifies the card. The
user selects the account to use (e.g
checking or savings). They then select an
amount to withdrawal. Security verifies if
the amount is available. The system makes
a decision as to if it is going to provide the
money. The user selects how they want
their money: in $10s or $20s. Security
provides the funds if possible. Security
provides a receipt and returns the card to
the user.
Image Credit: madamenoire.com
Use Case Description
• Trigger
– User places bank card in machine
• Actors (outside of system boundary lines)
– Customer
– Bank security
Image Credit: game-icons.net, www.zecatalist.com
Use Case Description
• Preconditions
– Secure connection to the bank
– Bank has cash
• Goals (Successful Conclusions)
– Secure client accounts
– Provide customer with funds
Image Credit: www.telegraph.co.uk
Use Case Description
Failed Conclusion
1. Invalid card
2. Invalid PIN
3. Customer insufficient
funds
4. ATM insufficient funds
5. Over daily limit
6. Stolen card
Extensions (Alternatives)
1. If invalid PIN entered 3
times – eat card.
2. If card is identified as being
stolen – eat card.
Image Credit: powershiftmagazine.com, www.principledinnovation.com
Use Case Description
• Steps of execution
(Requirements)
1. Customer inserts card
1. Card is invalid
2. Eject Card
2. Card is validated
3. Customer enters PIN
1. PIN is invalid
2. PIN is invalid 3 times
3. Card marked as stolen
4. PIN is validated
5. Account is selected
6. Amount is selected
1. Over daily maximum
2. Over account funds
available
3. Over funds in machine
4. Ask for new amount
7. Select desired $10s or
$20s.
8. Provide funds
9. Provide receipt
10. Eject card
Image Credit: www.jeffbullas.com
Sample Use Case Diagram
Actor
Actor
Actor Name
Note
Communication line
Use Case
System
Boundary
Line
(separates system from actors)
Include
(Means 2 or more use elements
|will be using another use case)
Extend
(Used when a use case is optional,
functionality is NOT required)
General Use Case
More Specific Use Case
What We Covered Today
1. What is a Use Case
2. Use Case description
3. What a Use Case Diagram
looks like
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What’s In Your C++ Toolbox?
cout / cin #include
What’s In Your C++Toolbox?
I/O
What We’ll Be Covering Next Time
1. Calculating the biggest
and the smallest from a
group of numbers.
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 (20)

PPT
Basics1
phanleson
 
PPTX
Unit 1 introduction to visual basic programming
Abha Damani
 
DOC
Csharp
vinayabburi
 
PDF
Object oriented programming c++
Ankur Pandey
 
PPTX
Application package
JAYAARC
 
PPT
Introduction to C++
Bharat Kalia
 
PDF
Book management system
SHARDA SHARAN
 
PPT
Savitch ch 11
Terry Yoast
 
DOCX
Lect '1'
reena0098
 
PPT
Savitch Ch 11
Terry Yoast
 
PDF
Deep C
Olve Maudal
 
PPTX
CSharp Presentation
Vishwa Mohan
 
PPTX
C# 101: Intro to Programming with C#
Hawkman Academy
 
PDF
SULTHAN's - C Programming Language notes
SULTHAN BASHA
 
PPTX
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
jatin batra
 
PPTX
C++ Tutorial
freema48
 
PDF
Programming in c
ankitjain851
 
PPTX
C programming
Jigarthacker
 
PDF
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Basics1
phanleson
 
Unit 1 introduction to visual basic programming
Abha Damani
 
Csharp
vinayabburi
 
Object oriented programming c++
Ankur Pandey
 
Application package
JAYAARC
 
Introduction to C++
Bharat Kalia
 
Book management system
SHARDA SHARAN
 
Savitch ch 11
Terry Yoast
 
Lect '1'
reena0098
 
Savitch Ch 11
Terry Yoast
 
Deep C
Olve Maudal
 
CSharp Presentation
Vishwa Mohan
 
C# 101: Intro to Programming with C#
Hawkman Academy
 
SULTHAN's - C Programming Language notes
SULTHAN BASHA
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
jatin batra
 
C++ Tutorial
freema48
 
Programming in c
ankitjain851
 
C programming
Jigarthacker
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 

Viewers also liked (18)

PPTX
Intro To C++ - Class #20: Functions, Recursion
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 08 - Separate Files & Set Functions
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #18: Vectors & Arrays
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #21: Files
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 2 - An Introduction To C++
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 14 - Midterm Review
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 12 - For, do … While
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #22: Inheritance, Part 1
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Blue Elephant Consulting
 
PPTX
Intro To C++ - Class #23: Inheritance, Part 2
Blue Elephant Consulting
 
Intro To C++ - Class #20: Functions, Recursion
Blue Elephant Consulting
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Blue Elephant Consulting
 
Intro To C++ - Class 08 - Separate Files & Set Functions
Blue Elephant Consulting
 
Intro To C++ - Class #18: Vectors & Arrays
Blue Elephant Consulting
 
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Blue Elephant Consulting
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Blue Elephant Consulting
 
Intro To C++ - Class #21: Files
Blue Elephant Consulting
 
Intro To C++ - Class 2 - An Introduction To C++
Blue Elephant Consulting
 
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Blue Elephant Consulting
 
Intro To C++ - Class 14 - Midterm Review
Blue Elephant Consulting
 
Intro To C++ - Class 12 - For, do … While
Blue Elephant Consulting
 
Intro To C++ - Class #22: Inheritance, Part 1
Blue Elephant Consulting
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Blue Elephant Consulting
 
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
 
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Blue Elephant Consulting
 
Intro To C++ - Class #23: Inheritance, Part 2
Blue Elephant Consulting
 
Ad

Similar to Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II (20)

PDF
Chapter 2 - Structure of C++ Program
Deepak Singh
 
PDF
C basics programming ppt by Mayanka .pdf
mayankamandal
 
PDF
fundamental of c++ for students of b.tech iii rd year student
Somesh Kumar
 
PPTX
Basics Of C++.pptx
DineshDhuri4
 
PPTX
computer programming omputer programming
Jifarnecho
 
PPTX
1.1 programming fundamentals
Jawad Khan
 
PPT
Fp201 unit2 1
rohassanie
 
PPTX
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
DOCX
The basics of c programming
Muhammed Thanveer M
 
PPT
intro to programming languge c++ for computer department
MemMem25
 
PDF
Tutorial basic of c ++lesson 1 eng ver
Qrembiezs Intruder
 
PPT
Intro to c++
Rafael Balderosa
 
PPT
C PLUS PLUS FOR BS ELECTRICAL 2ND SEMSTERLecture01.ppt
abdurrahimk182
 
PPTX
Programming Fundamentals IDE's Lec3.pptx
hafsanadeem31
 
PDF
A tutorial on C++ Programming
Prof. Erwin Globio
 
PPTX
Programming Fundamentals lecture 5
REHAN IJAZ
 
PPTX
Lecture 1
marvellous2
 
PDF
Ch02.pdf
Test835033
 
DOCX
C language industrial training report
Raushan Pandey
 
Chapter 2 - Structure of C++ Program
Deepak Singh
 
C basics programming ppt by Mayanka .pdf
mayankamandal
 
fundamental of c++ for students of b.tech iii rd year student
Somesh Kumar
 
Basics Of C++.pptx
DineshDhuri4
 
computer programming omputer programming
Jifarnecho
 
1.1 programming fundamentals
Jawad Khan
 
Fp201 unit2 1
rohassanie
 
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
The basics of c programming
Muhammed Thanveer M
 
intro to programming languge c++ for computer department
MemMem25
 
Tutorial basic of c ++lesson 1 eng ver
Qrembiezs Intruder
 
Intro to c++
Rafael Balderosa
 
C PLUS PLUS FOR BS ELECTRICAL 2ND SEMSTERLecture01.ppt
abdurrahimk182
 
Programming Fundamentals IDE's Lec3.pptx
hafsanadeem31
 
A tutorial on C++ Programming
Prof. Erwin Globio
 
Programming Fundamentals lecture 5
REHAN IJAZ
 
Lecture 1
marvellous2
 
Ch02.pdf
Test835033
 
C language industrial training report
Raushan Pandey
 
Ad

Recently uploaded (20)

PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Dimensions of Societal Planning in Commonism
StefanMz
 

Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II

  • 1. An Introduction To Software Development Using C++ Class #3: An Introduction To C++ Programming
  • 2. So What’s The Plan? 1. I provide you with a C++ program 2. You load it into the Microsoft Visual C++ compiler 3. You compile the program 4. You run the program 5. We all rejoice!
  • 3. You’re Very 3rd Ever C++ Program! 01: // Title: You’re Very 3rd Ever C++ Program 02: // Description: Program to print some text on the screen 03: #include <iostream> // allows program to output data to the screen 04: 05: // function main begins program execution 06: int main() 07: { 08: std::cout << “Hello World!n"; // display message 09: 10: return 0; // indicate that program ended successfully 11: } // end function main
  • 4. Now Let’s Screw Things Up… • Delete line #11, try to run the program… • Restore line #11 • On line #8, delete one of the “, try to run the program… • Restore line #8 • Save the file as “03 Class - 1st Program.c” • Load this file and try to compile it.
  • 6. Taking Apart A Sony Walkman
  • 7. Taking Apart Our First Program • Comments: lines 1 & 2 – Comments each begin with //, indicating that the remainder of each line is a comment. You insert comments to document your programs and to help other people read and understand them. – Comments do not cause the computer to perform any action when the program is run—they’re ignored by the C++ compiler and do not cause any machine-language object code to be generated. – A comment beginning with // is called a single-line comment because it terminates at the end of the current line. [Note: You also may use C’s style in which a comment—possibly containing many lines—begins with /* and ends with */.] // Title: You’re Very 1st Ever C++ Program // Description: Program to print some text on the screen
  • 8. A Dr. Jim “Suggestion”! • The first few lines of every program that you write should be comments. • You’ll want to give the name of the file that contains the code. • Then you’ll want to include your name – who created this code? • Then you’ll want to include a high-level description of just exactly what the code does. • The reason for doing all of this extra work is because next week, next month, next year when you come back to this code, you won’t be able to remember what it does.
  • 9. Taking Apart Our First Program • Preprocessor Directive: line 3 – This statement is a preprocessor directive, which is a message to the C++ preprocessor (processing done BEFORE compiling happens). Lines that begin with # are processed by the preprocessor before the program is compiled. – This line notifies the preprocessor to include in the program the contents of the input/output stream header <iostream>. – This header must be included for any program that outputs data to the screen or inputs data from the keyboard using C++’s stream input/output. #include <iostream> // allows program to output data to the screen
  • 10. Taking Apart Our First Program • Blank Lines and White Space: line 4 – Line 4 is simply a blank line. – You use blank lines, space characters and tab characters (i.e.,“tabs”) to make programs easier to read. – Together, these characters are known as whitespace. White-space characters are normally ignored by the compiler.
  • 11. Taking Apart Our First Program • Main Function: line 6 – The main function is a part of every C++ program. – The parentheses after main indicate that main is a program building block called a function. – C++ programs typically consist of one or more functions and classes. Exactly one function in every program must be named main. – C++ programs begin executing at function main, even if main is not the first function in the program. int main()
  • 12. Taking Apart Our First Program • Main Function: line 6 – The keyword int to the left of main indicates that main “returns” an integer (whole number) value. A keyword is a word in code that is reserved by C++ for a specific use. – The left brace, {, (line 7) must begin the body of every function. A corresponding right brace, }, (line 11) must end each function’s body. int main() { } // end function main
  • 14. Taking Apart Our First Program • An Output Statement: line 8 – This command instructs the computer to perform an action—namely, to print the string of characters contained between the double quotation marks. – White-space characters in strings are not ignored by the compiler. – The entire line 8, including std::cout, the << operator, the string “Hello World!n" and the semicolon (;), is called a statement. – Every C++ statement must end with a semicolon (also known as the statement terminator). – Preprocessor directives (like #include) do not end with a semicolon. std::cout << “Hello World!n"; // display message
  • 15. • An Output Statement: line 8 – Output and input in C++ are accomplished with streams of characters. – Thus, when the preceding statement is executed, it sends the stream of characters Hello World!n to the standard output stream object—std::cout— which is normally “connected” to the screen. std::cout << “Hello World!n"; // display message Taking Apart Our First Program
  • 16. A Dr. Jim Suggestion! • Your code can be dense and hard for your and everyone else to read – indent! • { Indent the body of each function one level within the braces that delimit the function’s body. This makes a program’s functional structure stand out and makes the program easier to read. } • Pick how many spaces you are going to indent and then stick with it. Just using the “tab” key doesn’t work because it produces different amounts of spaces on different computers. • Suggestion: indent everything by 3 spaces.
  • 17. • The std Namespace – The std:: before cout is required when we use names that we’ve brought into the program by the preprocessor directive #include <iostream>. – The notation std::cout specifies that we are using a name, in this case cout, that belongs to “namespace” std. – The names cin (the standard input stream) and cerr (the standard error stream) also belong to namespace std. – For now, you should simply remember to include std:: before each mention of cout, cin and cerr in a program. std::cout << “Hello World!n"; // display message Taking Apart Our First Program
  • 18. Taking Apart Our First Program • The Stream Insertion Operator and Escape Sequences – The << operator is referred to as the stream insertion operator. – When this program executes, the value to the operator’s right, the right operand, is inserted in the output stream. – Notice that the operator points in the direction of where the data goes. The right operand’s characters normally print exactly as they appear between the double quotes. std::cout << “Hello World!n"; // display message
  • 19. Taking Apart Our First Program • The Stream Insertion Operator and Escape Sequences – However, the characters n are not printed on the screen. The backslash () is called an escape character. – It indicates that a “special” character is to be output. When a backslash is encountered in a string of characters, the next character is combined with the backslash to form an escape sequence. – The escape sequence n means newline. It causes the cursor (i.e., the current screen-position indicator) to move to the beginning of the next line on the screen. std::cout << “Hello World!n"; // display message
  • 21. Taking Apart Our First Program • The return Statement – The statement is one of several means we’ll use to exit a function. – When the return statement is used at the end of main, as shown here, the value 0 indicates that the program has terminated successfully. – According to the C++ standard, if program execution reaches the end of main without encountering a return statement, it’s assumed that the program terminated successfully—exactly as when the last statement in main is a return statement with the value 0. – For that reason, I will omit the return statement at the end of main in subsequent programs. return 0; // indicate that program ended successfully
  • 22. Time To Make Some Changes • Software exists to be modified • Customer requirements are always changing • You will spend more time modifying existing code than writing new code. • Let’s now see if we can make some trivial modifications to our code…
  • 23. Software Change #1 • Change: • To: std::cout << “Hello World!n"; // display message std::cout << “Hello "; std::cout << “World!n"; What’s going on? The first stream insertion prints Hello followed by a space, and because this string did not end with n, the second stream insertion begins printing on the same line immediately following the space. Image Credit: imallvirtual.com
  • 24. Software Change #2 • Change: • To: std::cout << “Hello "; std::cout << “World!n"; What’s going on? A single statement can print multiple lines by using newline characters. Each time the n (newline) escape sequence is encountered in the output stream, the screen cursor is positioned to the beginning of the next line. To get a blank line in your output, place two newline characters back to back, std::cout << “HellonWorldnn!"; Image Credit: shophopes.com
  • 25. Mistakes That You’ll Make • Common Programming Error - Forgetting to include the <iostream> header in a program that inputs data from the keyboard or outputs data to the screen causes the compiler to issue an error message. • Common Programming Error 2.2 Omitting the semicolon at the end of a C++ statement is a syntax error. The syntax of a programming language specifies the rules for creating proper programs in that language. A syntax error occurs when the compiler encounters code that violates C++’s language rules (i.e., its syntax). The compiler normally issues an error message to help you locate and fix the incorrect code. You cannot execute your program until you correct all the syntax errors in it.
  • 26. Things You Need To Do • Good Programming - Every program should begin with a comment that describes the purpose of the program. • Good Programming Practice - Indent the body of each function one level within the braces that delimit the function’s body. This makes a program’s functional structure stand out and makes the program easier to read. • Good Programming Practice - Set a convention for the size of indent you prefer, then apply it uniformly. The tab key may be used to create indents, but tab stops may vary. We prefer three spaces per level of indent.
  • 27. What We Covered Today 1. Displaying data on the screen. 2. In particular, you learned to use the output stream object cout to build simple display programs. Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 28. What We’ll Be Covering Next Time 1. We’ll explain how variables are stored in and retrieved from memory. 2. You’ll also learn how to use arithmetic operators to perform calculations. 3. We discuss the order in which C++ applies operators (i.e., the rules of operator precedence), as well as the associativity of the operators. 4. You will learn how C++’s if statement allows a program to make decisions. 5. Finally, we’ll introduced the equality and relational operators, which you use to form conditions in if statements. Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/
  • 29. An Introduction To Software Development Using C++ Class #3: Use Cases
  • 30. An Example C++ Job Description RESPONSIBILITIES: • The position requires management of the design, layout, and production of client- server and web-based applications • Performs a developer role in building enterprise software solutions encompassing: services and service layer, service integration to UI and data, UI components • The candidate must work well in a team-like atmosphere in the development information technology solutions for a wide-variety of public-sector clients • REQUIREMENTS: • Bachelor's degree in Programming, Computer Science or related field plus a minimum of 3 years of related experience • Experienced in C, C++ coding methods and practices (2 - 5 years) • Working knowledge of Red Hat Linux operating system
  • 31. What Is UML? • The Unified Modeling Language (UML) is a general-purpose modeling language in the field of software engineering, which is designed to provide a standard way to visualize the design of a system. • It was created and developed by Grady Booch, Ivar Jacobson and James Rumbaugh at Rational Software during 1994–95, with further development led by them through 1996. • In 1997 it was adopted as a standard by the Object Management Group (OMG), and has been managed by this organization ever since. In 2005 the Unified Modeling Language was also published by the International Organization for Standardization (ISO) as an approved ISO standard. Since then it has been periodically revised to cover the latest revision of UML. • Though well-known and widely used in education and academic papers, as of 2013 UML is little-used in industry, and most such use is informal and ad hoc. Image Credit: en.wikipedia.org
  • 32. UML Diagrams • There are three classifications of UML diagrams: – Behavior diagrams. A type of diagram that depicts behavioral features of a system or business process. This includes activity, state machine, and use case diagrams as well as the four interaction diagrams. – Interaction diagrams. A subset of behavior diagrams which emphasize object interactions. This includes communication, interaction overview, sequence, and timing diagrams. – Structure diagrams. A type of diagram that depicts the elements of a specification that are irrespective of time. This includes class, composite structure, component, deployment, object, and package diagrams. Image Credit: code.google.com
  • 34. A Use Case • What is a Use Case? – It’s a list of steps that a system needs to follow in order to meet a goal. • You have to define what is required and how those requirements are going to be met • Do NOT try to write code in a Use Case Diagram • Consists of Shall vs. Should requirements – A Use Case generally includes interactions with an “Actor” (this is a human or an external system). Image Credit: www.en.pms.ifi.lmu.de
  • 35. Use Case Description • Description – The bank customer enters their card into the machine and then types in their PIN. Bank security then verifies the card. The user selects the account to use (e.g checking or savings). They then select an amount to withdrawal. Security verifies if the amount is available. The system makes a decision as to if it is going to provide the money. The user selects how they want their money: in $10s or $20s. Security provides the funds if possible. Security provides a receipt and returns the card to the user. Image Credit: madamenoire.com
  • 36. Use Case Description • Trigger – User places bank card in machine • Actors (outside of system boundary lines) – Customer – Bank security Image Credit: game-icons.net, www.zecatalist.com
  • 37. Use Case Description • Preconditions – Secure connection to the bank – Bank has cash • Goals (Successful Conclusions) – Secure client accounts – Provide customer with funds Image Credit: www.telegraph.co.uk
  • 38. Use Case Description Failed Conclusion 1. Invalid card 2. Invalid PIN 3. Customer insufficient funds 4. ATM insufficient funds 5. Over daily limit 6. Stolen card Extensions (Alternatives) 1. If invalid PIN entered 3 times – eat card. 2. If card is identified as being stolen – eat card. Image Credit: powershiftmagazine.com, www.principledinnovation.com
  • 39. Use Case Description • Steps of execution (Requirements) 1. Customer inserts card 1. Card is invalid 2. Eject Card 2. Card is validated 3. Customer enters PIN 1. PIN is invalid 2. PIN is invalid 3 times 3. Card marked as stolen 4. PIN is validated 5. Account is selected 6. Amount is selected 1. Over daily maximum 2. Over account funds available 3. Over funds in machine 4. Ask for new amount 7. Select desired $10s or $20s. 8. Provide funds 9. Provide receipt 10. Eject card Image Credit: www.jeffbullas.com
  • 40. Sample Use Case Diagram Actor Actor Actor Name Note Communication line Use Case System Boundary Line (separates system from actors) Include (Means 2 or more use elements |will be using another use case) Extend (Used when a use case is optional, functionality is NOT required) General Use Case More Specific Use Case
  • 41. What We Covered Today 1. What is a Use Case 2. Use Case description 3. What a Use Case Diagram looks like Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 42. What’s In Your C++ Toolbox? cout / cin #include
  • 43. What’s In Your C++Toolbox? I/O
  • 44. What We’ll Be Covering Next Time 1. Calculating the biggest and the smallest from a group of numbers. 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

  • #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.
  • #30: 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.