SlideShare a Scribd company logo
Object Oriented Programming:12
Programming Steps in C++ and
Example Program
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2
Programming Example:
Convert Length
• Write a program that takes as input a given length
expressed in feet and inches
– Convert and output the length in centimeters
• Input: length in feet and inches
• Output: equivalent length in centimeters
• Lengths are given in feet and inches
• Program computes the equivalent length in
centimeters
• One inch is equal to 2.54 centimeters
3
Programming Example: Convert Length
(continued)
• Convert the length in feet and inches to all
inches:
– Multiply the number of feet by 12
– Add given inches
• Use the conversion formula (1 inch = 2.54
centimeters) to find the equivalent length in
centimeters
4
Programming Example: Convert Length
(continued)
• The algorithm is as follows:
– Get the length in feet and inches
– Convert the length into total inches
– Convert total inches into centimeters
– Output centimeters
5
Programming Example: Variables and
Constants
• Variables
int feet; //variable to hold given feet
int inches; //variable to hold given inches
int totalInches; //variable to hold total inches
double centimeters; //variable to hold length in
//centimeters
• Named Constant
const double CENTIMETERS_PER_INCH = 2.54;
const int INCHES_PER_FOOT = 12;
6
Programming Example: Main
Algorithm
• Prompt user for input
• Get data
• Echo the input (output the input)
• Find length in inches
• Output length in inches
• Convert length to centimeters
• Output length in centimeters
7
Programming Example: Putting It
Together
• Program begins with comments
• System resources will be used for I/O
• Use input statements to get data and output
statements to print results
• Data comes from keyboard and the output will
display on the screen
• The first statement of the program, after
comments, is preprocessor directive to include
header file iostream
8
Programming Example: Putting It
Together (continued)
• Two types of memory locations for data
manipulation:
– Named constants
• Usually put before main
– Variables
• This program has only one function (main),
which will contain all the code
• The program needs variables to manipulate
data, which are declared in main
9
Programming Example: Body of the
Function
• The body of the function main has the
following form:
int main ()
{
declare variables
statements
return 0;
}
10
Programming Example: Writing a
Complete Program
• Begin the program with comments for
documentation
• Include header files
• Declare named constants, if any
• Write the definition of the function main
11
12
Programming Example: Sample Run
Enter two integers, one for feet, one for inches: 15 7
The numbers you entered are 15 for feet and 7 for inches.
The total number of inches = 187
The number of centimeters = 474.98
13
Summary
• C++ program: collection of functions where
each program has a function called main
• Identifier consists of letters, digits, and
underscores, and begins with letter or
underscore
• The arithmetic operators in C++ are addition
(+), subtraction (-),multiplication (*), division
(/), and modulus (%)
• Arithmetic expressions are evaluated using
the precedence associativity rules
14
Summary (continued)
• All operands in an integral expression are
integers and all operands in a floating-point
expression are decimal numbers
• Mixed expression: contains both integers and
decimal numbers
• Use the cast operator to explicitly convert values
from one data type to another
• A named constant is initialized when declared
• All variables must be declared before used
15
Summary (continued)
• Use cin and stream extraction operator >>
to input from the standard input device
• Use cout and stream insertion operator <<
to output to the standard output device
• Preprocessor commands are processed before
the program goes through the compiler
• A file containing a C++ program usually ends
with the extension .cpp
Assignment
• Describe in detail the programming steps for
converting length in Feet and inches to
centimeters
• Explain the importance of “program planning
and design documentation” before
implementing the code / actual program

More Related Content

PPTX
Arithmetic and Arithmetic assignment operators
PDF
Lesson 5 .1 selection structure
PDF
Lecture 7
PPTX
halstead software science measures
PPT
test(3)arithmetic in c
PPT
Introduction to design and analysis of algorithm
PPTX
Process of algorithm evaluation
PPTX
Object oriented programming 11 preprocessor directives and program structure
Arithmetic and Arithmetic assignment operators
Lesson 5 .1 selection structure
Lecture 7
halstead software science measures
test(3)arithmetic in c
Introduction to design and analysis of algorithm
Process of algorithm evaluation
Object oriented programming 11 preprocessor directives and program structure

What's hot (18)

PPTX
Ninth session
PDF
P3
PDF
Cse115 lecture02overviewofprogramming
PPT
C++ programming program design including data structures
PDF
Cse115 lecture03problemsolving
PDF
Cse115 lecture04introtoc programming
PPTX
Functions in c++,
PDF
Fundamental
PPTX
Debugging Python with Pdb!
PDF
Cse115 lecture08repetitionstructures part02
PPTX
Pa1 loops
PPT
Parallel adder
PPT
4 bit add sub
PPT
parellel computing
Ninth session
P3
Cse115 lecture02overviewofprogramming
C++ programming program design including data structures
Cse115 lecture03problemsolving
Cse115 lecture04introtoc programming
Functions in c++,
Fundamental
Debugging Python with Pdb!
Cse115 lecture08repetitionstructures part02
Pa1 loops
Parallel adder
4 bit add sub
parellel computing
Ad

Similar to Object oriented programming 12 programming steps in cpp and example (20)

PPT
Elementary_Of_C++_Programming_Language.ppt
PPTX
Presentation c++
PPTX
Intro in understanding to C programming .pptx
PPT
programming week 2.ppt
PPTX
C++ basics
PDF
Object Oriented Programming (OOP) using C++ - Lecture 2
PPTX
#Code2 create c++ for beginners
DOCX
LAB 1 Report.docx
PDF
PROGRAMMING FUNDAMENTALS BASICS LECTURE 2
PPT
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
PDF
Cp week _2.
PPTX
Programming using c++ tool
PDF
Prog1-L1.pdf
PPT
Apclass (2)
PPT
Pengaturcaraan asas
DOCX
C++ Tutorial.docx
PDF
4.languagebasics
PPTX
Introduction to C ++.pptx
PPT
01 c++ Intro.ppt
PPTX
Esc3.Intro to C++ and computer program.pptx
Elementary_Of_C++_Programming_Language.ppt
Presentation c++
Intro in understanding to C programming .pptx
programming week 2.ppt
C++ basics
Object Oriented Programming (OOP) using C++ - Lecture 2
#Code2 create c++ for beginners
LAB 1 Report.docx
PROGRAMMING FUNDAMENTALS BASICS LECTURE 2
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
Cp week _2.
Programming using c++ tool
Prog1-L1.pdf
Apclass (2)
Pengaturcaraan asas
C++ Tutorial.docx
4.languagebasics
Introduction to C ++.pptx
01 c++ Intro.ppt
Esc3.Intro to C++ and computer program.pptx
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
PPTX
Information and network security 46 digital signature algorithm
PPTX
Information and network security 45 digital signature standard
PPTX
Information and network security 44 direct digital signatures
PPTX
Information and network security 43 digital signatures
PPTX
Information and network security 42 security of message authentication code
PPTX
Information and network security 41 message authentication code
PPTX
Information and network security 40 sha3 secure hash algorithm
PPTX
Information and network security 39 secure hash algorithm
PPTX
Information and network security 38 birthday attacks and security of hash fun...
PPTX
Information and network security 37 hash functions and message authentication
PPTX
Information and network security 35 the chinese remainder theorem
PPTX
Information and network security 34 primality
PPTX
Information and network security 33 rsa algorithm
PPTX
Information and network security 32 principles of public key cryptosystems
PPTX
Information and network security 31 public key cryptography
PPTX
Information and network security 30 random numbers
PPTX
Information and network security 29 international data encryption algorithm
PPTX
Information and network security 28 blowfish
PPTX
Information and network security 27 triple des
Information and network security 47 authentication applications
Information and network security 46 digital signature algorithm
Information and network security 45 digital signature standard
Information and network security 44 direct digital signatures
Information and network security 43 digital signatures
Information and network security 42 security of message authentication code
Information and network security 41 message authentication code
Information and network security 40 sha3 secure hash algorithm
Information and network security 39 secure hash algorithm
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 37 hash functions and message authentication
Information and network security 35 the chinese remainder theorem
Information and network security 34 primality
Information and network security 33 rsa algorithm
Information and network security 32 principles of public key cryptosystems
Information and network security 31 public key cryptography
Information and network security 30 random numbers
Information and network security 29 international data encryption algorithm
Information and network security 28 blowfish
Information and network security 27 triple des

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPT
Introduction Database Management System for Course Database
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
medical staffing services at VALiNTRY
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administraation Chapter 3
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administration Chapter 2
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PTS Company Brochure 2025 (1).pdf.......
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Introduction Database Management System for Course Database
Introduction to Artificial Intelligence
Design an Analysis of Algorithms I-SECS-1021-03
wealthsignaloriginal-com-DS-text-... (1).pdf
Understanding Forklifts - TECH EHS Solution
Odoo Companies in India – Driving Business Transformation.pdf
medical staffing services at VALiNTRY
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administraation Chapter 3
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administration Chapter 2

Object oriented programming 12 programming steps in cpp and example

  • 1. Object Oriented Programming:12 Programming Steps in C++ and Example Program Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 2 Programming Example: Convert Length • Write a program that takes as input a given length expressed in feet and inches – Convert and output the length in centimeters • Input: length in feet and inches • Output: equivalent length in centimeters • Lengths are given in feet and inches • Program computes the equivalent length in centimeters • One inch is equal to 2.54 centimeters
  • 3. 3 Programming Example: Convert Length (continued) • Convert the length in feet and inches to all inches: – Multiply the number of feet by 12 – Add given inches • Use the conversion formula (1 inch = 2.54 centimeters) to find the equivalent length in centimeters
  • 4. 4 Programming Example: Convert Length (continued) • The algorithm is as follows: – Get the length in feet and inches – Convert the length into total inches – Convert total inches into centimeters – Output centimeters
  • 5. 5 Programming Example: Variables and Constants • Variables int feet; //variable to hold given feet int inches; //variable to hold given inches int totalInches; //variable to hold total inches double centimeters; //variable to hold length in //centimeters • Named Constant const double CENTIMETERS_PER_INCH = 2.54; const int INCHES_PER_FOOT = 12;
  • 6. 6 Programming Example: Main Algorithm • Prompt user for input • Get data • Echo the input (output the input) • Find length in inches • Output length in inches • Convert length to centimeters • Output length in centimeters
  • 7. 7 Programming Example: Putting It Together • Program begins with comments • System resources will be used for I/O • Use input statements to get data and output statements to print results • Data comes from keyboard and the output will display on the screen • The first statement of the program, after comments, is preprocessor directive to include header file iostream
  • 8. 8 Programming Example: Putting It Together (continued) • Two types of memory locations for data manipulation: – Named constants • Usually put before main – Variables • This program has only one function (main), which will contain all the code • The program needs variables to manipulate data, which are declared in main
  • 9. 9 Programming Example: Body of the Function • The body of the function main has the following form: int main () { declare variables statements return 0; }
  • 10. 10 Programming Example: Writing a Complete Program • Begin the program with comments for documentation • Include header files • Declare named constants, if any • Write the definition of the function main
  • 11. 11
  • 12. 12 Programming Example: Sample Run Enter two integers, one for feet, one for inches: 15 7 The numbers you entered are 15 for feet and 7 for inches. The total number of inches = 187 The number of centimeters = 474.98
  • 13. 13 Summary • C++ program: collection of functions where each program has a function called main • Identifier consists of letters, digits, and underscores, and begins with letter or underscore • The arithmetic operators in C++ are addition (+), subtraction (-),multiplication (*), division (/), and modulus (%) • Arithmetic expressions are evaluated using the precedence associativity rules
  • 14. 14 Summary (continued) • All operands in an integral expression are integers and all operands in a floating-point expression are decimal numbers • Mixed expression: contains both integers and decimal numbers • Use the cast operator to explicitly convert values from one data type to another • A named constant is initialized when declared • All variables must be declared before used
  • 15. 15 Summary (continued) • Use cin and stream extraction operator >> to input from the standard input device • Use cout and stream insertion operator << to output to the standard output device • Preprocessor commands are processed before the program goes through the compiler • A file containing a C++ program usually ends with the extension .cpp
  • 16. Assignment • Describe in detail the programming steps for converting length in Feet and inches to centimeters • Explain the importance of “program planning and design documentation” before implementing the code / actual program