SlideShare una empresa de Scribd logo
1 de 44
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/

Más contenido relacionado

La actualidad más candente

Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
Abha Damani
 
Application package
Application packageApplication package
Application package
JAYAARC
 

La actualidad más candente (20)

Basics1
Basics1Basics1
Basics1
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Csharp
CsharpCsharp
Csharp
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Application package
Application packageApplication package
Application package
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Book management system
Book management systemBook management system
Book management system
 
Savitch ch 11
Savitch ch 11Savitch ch 11
Savitch ch 11
 
Lect '1'
Lect '1'Lect '1'
Lect '1'
 
Savitch Ch 11
Savitch Ch 11Savitch Ch 11
Savitch Ch 11
 
Deep C
Deep CDeep C
Deep C
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notes
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREC & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
 
C++ Tutorial
C++ TutorialC++ Tutorial
C++ Tutorial
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C programming
C programmingC programming
C programming
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 

Destacado

Destacado (19)

Intro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, RecursionIntro To C++ - Class #20: Functions, Recursion
Intro To C++ - Class #20: Functions, Recursion
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsIntro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
 
Intro To C++ - Class 08 - Separate Files & Set Functions
Intro To C++ - Class 08 - Separate Files & Set Functions Intro To C++ - Class 08 - Separate Files & Set Functions
Intro To C++ - Class 08 - Separate Files & Set Functions
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & Arrays
 
Intro To C++ - Class #19: Functions
Intro To C++ - Class #19: FunctionsIntro To C++ - Class #19: Functions
Intro To C++ - Class #19: Functions
 
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & PrototypesIntro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
 
Intro To C++ - Class #21: Files
Intro To C++ - Class #21: FilesIntro To C++ - Class #21: Files
Intro To C++ - Class #21: Files
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++
 
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To  Classes, Objects, & StringsIntro To C++ - Class 05 - Introduction To  Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
 
Intro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm ReviewIntro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm Review
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … While
 
Intro To C++ - Class #22: Inheritance, Part 1
Intro To C++ - Class #22: Inheritance, Part 1Intro To C++ - Class #22: Inheritance, Part 1
Intro To C++ - Class #22: Inheritance, Part 1
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIIntro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...
 
Intro To C++ - Class #23: Inheritance, Part 2
Intro To C++ - Class #23: Inheritance, Part 2Intro To C++ - Class #23: Inheritance, Part 2
Intro To C++ - Class #23: Inheritance, Part 2
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 

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

Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
Deepak Singh
 

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

Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
1.1 programming fundamentals
1.1 programming fundamentals1.1 programming fundamentals
1.1 programming fundamentals
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
lecture1 pf.pptx
lecture1 pf.pptxlecture1 pf.pptx
lecture1 pf.pptx
 
Ch2 C Fundamentals
Ch2 C FundamentalsCh2 C Fundamentals
Ch2 C Fundamentals
 
General structure of c++
General structure of c++General structure of c++
General structure of c++
 
C++ Chapter 3
C++ Chapter 3C++ Chapter 3
C++ Chapter 3
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

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/

Notas del editor

  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.