SlideShare a Scribd company logo
1 of 64
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Chapter 1
Introduction to Computers and
C++ Programming
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Overview
1.1 Computer Systems
1.2 Programming and Problem Solving
1.3 Introduction to C++
1.4 Testing and Debugging
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
1.1
Computer Systems
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Computer Systems
 A computer program is…
 A set of instructions for a computer to follow
 Computer software is …
 The collection of programs used by a computer
 Includes:
 Editors
 Translators
 System Managers
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Hardware
 Three main classes of computers
 PCs (Personal Computer)
 Relatively small used by one person at a time
 Workstation
 Larger and more powerful than a PC
 Mainframe
 Still larger
 Requires support staff
 Shared by multiple users
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Networks
 A number of computers connected to
share resources
 Share printers and other devices
 Share information
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Computer Organization
 Five main components
 Input devices
 Allows communication to the computer
 Output devices
 Allows communication to the user
 Processor (CPU)
 Main memory
 Memory locations containing the running program
 Secondary memory
 Permanent record of data often on a disk Display 1.1
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.1 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Computer Memory
 Main Memory
 Long list of memory locations
 Each contains zeros and ones
 Can change during program execution
 Binary Digit or Bit
 A digit that can only be zero or one
 Byte
 Each memory location has eight bits
 Address
 Number that identifies a memory location
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Larger Data Items
 Some data is too large for a single byte
 Most integers and real numbers are too large
 Address refers to the first byte
 Next few consecutive bytes can store the
additional
bits for larger data
Display 1.2
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.2 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Data or Code?
 ‘A’ may look like 01000001
 65 may look like 01000001
 An instruction may look like 01000001
 How does the computer know the meaning
of 01000001?
 Interpretation depends on the current instruction
 Programmers rarely need to be concerned with
this problem.
 Reason as if memory locations contain letters and
numbers rather than zeroes and ones
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Secondary Memory
 Main memory stores instructions and
data while a program is running.
 Secondary memory
 Stores instructions and data between sessions
 A file stores data or instructions in
secondary memory
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Secondary Memory Media
 A computer might have any of these
types of secondary memory
 Hard disk
 Fast
 Fixed in the computer and not normally removed
 Floppy disk
 Slow
 Easily shared with other computers
 Compact disk
 Slower than hard disks
 Easily shared with other computers
 Can be read only or re-writable
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Memory Access
 Random Access
 Usually called RAM
 Computer can directly access any memory location
 Sequential Access
 Data is generally found by searching through
other items first
 More common in secondary memory
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
The Processor
 Typically called the CPU
 Central Processing Unit
 Follows program instructions
 Typical capabilities of CPU include:
add
subtract
multiply
divide
move data from location to location
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Computer Software
 The operating system
 Allows us to communicate with the computer
 Is a program
 Allocates the computer’s resources
 Responds to user requests to run other
programs
 Common operating systems include…
 UNIX Linux DOS
Windows Macintosh VMS
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Computer Input
 Computer input consists of
 A program
 Some data
Display 1.3
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.3 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
High-level Languages
 Common programming languages include …
C C++ Java Pascal Visual Basic FORTRAN Perl
PHP Lisp Scheme Ada C# Python
 These high – level languages
 Resemble human languages
 Are designed to be easy to read and write
 Use more complicated instructions than
the CPU can follow
 Must be translated to zeros and ones for the CPU
to execute a program
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Low-level Languages
 An assembly language command such as
ADD X Y Z
might mean add the values found at x and y
in memory, and store the result in location z.
 Assembly language must be translated to
machine language (zeros and ones)
0110 1001 1010 1011
 The CPU can follow machine language
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Compilers
 Translate high-level language to
machine language
 Source code
 The original program in a high level language
 Object code
 The translated version in machine language
Display 1.4
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Linkers
 Some programs we use are already compiled
 Their object code is available for us to use
 For example: Input and output routines
 A Linker combines
 The object code for the programs we write
and
 The object code for the pre-compiled routines
into
 The machine language program the CPU can
run
Display 1.5
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
1.2
Programming and Problem-
Solving
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Algorithms
 Algorithm
 A sequence of precise instructions that
leads to a solution
 Program
 An algorithm expressed in a language the
computer can understand
Display 1.6
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Program Design
 Programming is a creative process
 No complete set of rules for creating a program
 Program Design Process
 Problem Solving Phase
 Result is an algorithm that solves the problem
 Implementation Phase
 Result is the algorithm translated into a
programming
language
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Problem Solving Phase
 Be certain the task is completely specified
 What is the input?
 What information is in the output?
 How is the output organized?
 Develop the algorithm before implementation
 Experience shows this saves time in getting
your program to run.
 Test the algorithm for correctness
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Implementation Phase
 Translate the algorithm into a programming
language
 Easier as you gain experience with the language
 Compile the source code
 Locates errors in using the programming language
 Run the program on sample data
 Verify correctness of results
 Results may require modification of
the algorithm and program
Display 1.7
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Object Oriented Programming
 Abbreviated OOP
 Used for many modern programs
 Program is viewed as interacting objects
 Each object contains algorithms to describe
its behavior
 Program design phase involves designing
objects and their algorithms
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
OOP Characteristics
 Encapsulation
 Information hiding
 Objects contain their own data and algorithms
 Inheritance
 Writing reusable code
 Objects can inherit characteristics from other objects
 Polymorphism
 A single name can have multiple meanings depending
on its context
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Software Life Cycle
 Analysis and specification of the task
(problem definition)
 Design of the software
(object and algorithm design)
 Implementation (coding)
 Maintenance and evolution of the system
 Obsolescence
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Section 1.2 Conclusion
 Can you…
 Describe the first step to take when creating
a program?
 List the two main phases of the program
design process?
 Explain the importance of the problem-solving phase?
 List the steps in the software life cycle?
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
1.3
Introduction to C++
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Introduction to C++
 Where did C++ come from?
 Derived from the C language
 C was derived from the B language
 B was derived from the BCPL language
 Why the ‘++’?
 ++ is an operator in C++ and results in a cute pun
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
C++ History
 C developed by Dennis Ritchie at AT&T
Bell Labs in the 1970s.
 Used to maintain UNIX systems
 Many commercial applications written in c
 C++ developed by Bjarne Stroustrup at AT&T
Bell Labs in the 1980s.
 Overcame several shortcomings of C
 Incorporated object oriented programming
 C remains a subset of C++
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
A Sample C++ Program
 A simple C++ program begins this way
#include <iostream>
using namespace std;
int main()
{
 And ends this way
return 0;
}
Display 1.8
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Explanation of code (1/5)
 Variable declaration line
int numberOfPods, peasPerPod, totalPeas;
 Identifies names of three variables to name numbers
 int means that the variables represent integers
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Explanation of code (2/5)
 Program statement
cout << “Press return after entering a number.n”;
 cout (see-out) used for output to the monitor
 “<<“ inserts “Press…a number.n” in the data
bound for the monitor
 Think of cout as a name for the monitor
 “<<“ points to where the data is to end up
 ‘n’ causes a new line to be started on the monitor
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Explanation of code (3/5)
 Program statement
cin >> numberOfPods;
 cin (see-in) used for input from the keyboard
 “>>” extracts data from the keyboard
 Think of cin as a name for the keyboard
 “>>” points from the keyboard to a variable where the data
is stored
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Explanation of code (4/5)
 Program statement
totalPeas = numberOfPods * peasPerPod;
 Performs a computation
 ‘*’ is used for multiplication
 ‘=‘ causes totalPeas to get a new value based on
the calculation shown on the right of the equal sign
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Explanation of code (5/5)
 Program statement
cout << numberOfPods;
 Sends the value of variable numberOfPods to
the monitor
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Program Layout (1/3)
 Compiler accepts almost any pattern of line
breaks and indentation
 Programmers format programs so they
are easy to read
 Place opening brace ‘{‘ and closing brace ‘}’
on a line by themselves
 Indent statements
 Use only one statement per line
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Program Layout (2/3)
 Variables are declared before they are used
 Typically variables are declared at the beginning of
the program
 Statements (not always lines) end with a semi-colon
 Include Directives
#include <iostream>
 Tells compiler where to find information about items
used in the program
 iostream is a library containing definitions of cin and
cout
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Program Layout (3/3)
 using namespace std;
 Tells the compiler to use names in iostream in
a “standard” way
 To begin the main function of the program
int main()
{
 To end the main function
return 0;
}
 Main function ends with a return statement
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Running a C++ Program
 C++ source code is written with a text
editor
 The compiler on your system converts
source code to object code.
 The linker combines all the object code
into an executable program.
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
C++11
 C++11 (formerly known as C++0x) is the most recent
version of the standard of the C++ programming
language.
 Approved on August 12, 2011 by the International
Organization for Standardization.
 C++11 language features are not supported by older
compilers
 Check the documentation with your compiler to determine
if special steps are needed to compile C++11 programs
 e.g. with g++, use extra flags of –std=c++11
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Run a Program
 Obtain code in Display 1.10
 Compile the code
 Fix any errors the compiler indicates and
re-compile the code
 Run the program
 Now you know how to run a program on
your system
Display 1.10
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Section 1.3 Conclusion
 Can you…
 Describe the output of this line?
cout << “C++ is easy to understand.”;
 Explain what this line does?
cin >> peasPerPod;
 Explain this? #include <iostream>
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
1.4
Testing and Debugging
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Testing and Debugging
 Bug
 A mistake in a program
 Debugging
 Eliminating mistakes in programs
 Term used when a moth caused a failed relay
on the Harvard Mark 1 computer. Grace Hopper
and other programmers taped the moth in logbook
stating:
“First actual case of a bug being found.”
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Program Errors
 Syntax errors
 Violation of the grammar rules of the language
 Discovered by the compiler
 Error messages may not always show correct location of
errors
 Run-time errors
 Error conditions detected by the computer at run-time
 Logic errors
 Errors in the program’s algorithm
 Most difficult to diagnose
 Computer does not recognize an error
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Section 1-4 Conclusion
 Can you…
 Describe the three kinds of program errors?
 Tell what kind of errors the compiler catches?
 What kind of error is produced if you forget a
punctuation symbol such as a semi-colon?
 Tell what type of error is produced when a program
runs but produces incorrect results?
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Chapter 1 -- End
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.1 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.2 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.3 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.4 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.5 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.6 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.7 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.8
Next
Back
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.9 Back Next
Copyright © 2018 Pearson Addison-Wesley. All rights reserved.
Display 1.10 Next
Back

More Related Content

Similar to Chapter 1.ppt

C LECTURE NOTES FULL_1.pdf
C LECTURE NOTES FULL_1.pdfC LECTURE NOTES FULL_1.pdf
C LECTURE NOTES FULL_1.pdfPriyanka542143
 
Introduction to c_language
Introduction to c_languageIntroduction to c_language
Introduction to c_languageWay2itech
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eGina Bullock
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eGina Bullock
 
PPS UNIT 1- R18.docx
PPS UNIT 1- R18.docxPPS UNIT 1- R18.docx
PPS UNIT 1- R18.docxUzma1102
 
C PROGRAMING AND PC
C PROGRAMING AND PCC PROGRAMING AND PC
C PROGRAMING AND PC4044uday
 
programing fundamentals by dr. wheedh khan
programing fundamentals by dr. wheedh khanprograming fundamentals by dr. wheedh khan
programing fundamentals by dr. wheedh khanahmedmidhu2001
 
Introduction to computers and programing.pptx
Introduction to computers and programing.pptxIntroduction to computers and programing.pptx
Introduction to computers and programing.pptxahmedmidhu2001
 
Computer and programing basics.pptx
Computer and programing basics.pptxComputer and programing basics.pptx
Computer and programing basics.pptxgaafergoda
 
Chapter_1_Computer_Abstractions_and_Tech.ppt
Chapter_1_Computer_Abstractions_and_Tech.pptChapter_1_Computer_Abstractions_and_Tech.ppt
Chapter_1_Computer_Abstractions_and_Tech.pptnivine7
 
Safetty systems intro_embedded_c
Safetty systems intro_embedded_cSafetty systems intro_embedded_c
Safetty systems intro_embedded_cMaria Cida Rosa
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdfDinashMaliya3
 
Introduction to Computers and Programming
Introduction to Computers and ProgrammingIntroduction to Computers and Programming
Introduction to Computers and ProgrammingEdwin Flórez Gómez
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppmeharikiros2
 
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdf
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdfAERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdf
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdfssuserb3a23b
 
iw3htp4_01-FINAL.ppt
iw3htp4_01-FINAL.pptiw3htp4_01-FINAL.ppt
iw3htp4_01-FINAL.pptlucky sharma
 
Programming_Fundamentals_Chapter_1_INTRO.pdf
Programming_Fundamentals_Chapter_1_INTRO.pdfProgramming_Fundamentals_Chapter_1_INTRO.pdf
Programming_Fundamentals_Chapter_1_INTRO.pdfBernardVelasco1
 

Similar to Chapter 1.ppt (20)

C LECTURE NOTES FULL_1.pdf
C LECTURE NOTES FULL_1.pdfC LECTURE NOTES FULL_1.pdf
C LECTURE NOTES FULL_1.pdf
 
Introduction to c_language
Introduction to c_languageIntroduction to c_language
Introduction to c_language
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5e
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5e
 
C++ Problem solving
C++ Problem solvingC++ Problem solving
C++ Problem solving
 
C 1
C 1C 1
C 1
 
PPS UNIT 1- R18.docx
PPS UNIT 1- R18.docxPPS UNIT 1- R18.docx
PPS UNIT 1- R18.docx
 
C PROGRAMING AND PC
C PROGRAMING AND PCC PROGRAMING AND PC
C PROGRAMING AND PC
 
programing fundamentals by dr. wheedh khan
programing fundamentals by dr. wheedh khanprograming fundamentals by dr. wheedh khan
programing fundamentals by dr. wheedh khan
 
Introduction to computers and programing.pptx
Introduction to computers and programing.pptxIntroduction to computers and programing.pptx
Introduction to computers and programing.pptx
 
Computer and programing basics.pptx
Computer and programing basics.pptxComputer and programing basics.pptx
Computer and programing basics.pptx
 
Chapter_1_Computer_Abstractions_and_Tech.ppt
Chapter_1_Computer_Abstractions_and_Tech.pptChapter_1_Computer_Abstractions_and_Tech.ppt
Chapter_1_Computer_Abstractions_and_Tech.ppt
 
Safetty systems intro_embedded_c
Safetty systems intro_embedded_cSafetty systems intro_embedded_c
Safetty systems intro_embedded_c
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
 
Introduction to Computers and Programming
Introduction to Computers and ProgrammingIntroduction to Computers and Programming
Introduction to Computers and Programming
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cpp
 
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdf
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdfAERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdf
AERO_PROGRAMMING_FOR_PROBLEM_SOLVING_LECTURE_NOTES.pdf
 
iw3htp4_01-FINAL.ppt
iw3htp4_01-FINAL.pptiw3htp4_01-FINAL.ppt
iw3htp4_01-FINAL.ppt
 
Programming_Fundamentals_Chapter_1_INTRO.pdf
Programming_Fundamentals_Chapter_1_INTRO.pdfProgramming_Fundamentals_Chapter_1_INTRO.pdf
Programming_Fundamentals_Chapter_1_INTRO.pdf
 
C program full materials.pdf
C program  full materials.pdfC program  full materials.pdf
C program full materials.pdf
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Chapter 1.ppt

  • 1.
  • 2. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming
  • 3. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Overview 1.1 Computer Systems 1.2 Programming and Problem Solving 1.3 Introduction to C++ 1.4 Testing and Debugging
  • 4. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. 1.1 Computer Systems
  • 5. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Computer Systems  A computer program is…  A set of instructions for a computer to follow  Computer software is …  The collection of programs used by a computer  Includes:  Editors  Translators  System Managers
  • 6. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Hardware  Three main classes of computers  PCs (Personal Computer)  Relatively small used by one person at a time  Workstation  Larger and more powerful than a PC  Mainframe  Still larger  Requires support staff  Shared by multiple users
  • 7. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Networks  A number of computers connected to share resources  Share printers and other devices  Share information
  • 8. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Computer Organization  Five main components  Input devices  Allows communication to the computer  Output devices  Allows communication to the user  Processor (CPU)  Main memory  Memory locations containing the running program  Secondary memory  Permanent record of data often on a disk Display 1.1
  • 9. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.1 Back Next
  • 10. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Computer Memory  Main Memory  Long list of memory locations  Each contains zeros and ones  Can change during program execution  Binary Digit or Bit  A digit that can only be zero or one  Byte  Each memory location has eight bits  Address  Number that identifies a memory location
  • 11. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Larger Data Items  Some data is too large for a single byte  Most integers and real numbers are too large  Address refers to the first byte  Next few consecutive bytes can store the additional bits for larger data Display 1.2
  • 12. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.2 Back Next
  • 13. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Data or Code?  ‘A’ may look like 01000001  65 may look like 01000001  An instruction may look like 01000001  How does the computer know the meaning of 01000001?  Interpretation depends on the current instruction  Programmers rarely need to be concerned with this problem.  Reason as if memory locations contain letters and numbers rather than zeroes and ones
  • 14. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Secondary Memory  Main memory stores instructions and data while a program is running.  Secondary memory  Stores instructions and data between sessions  A file stores data or instructions in secondary memory
  • 15. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Secondary Memory Media  A computer might have any of these types of secondary memory  Hard disk  Fast  Fixed in the computer and not normally removed  Floppy disk  Slow  Easily shared with other computers  Compact disk  Slower than hard disks  Easily shared with other computers  Can be read only or re-writable
  • 16. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Memory Access  Random Access  Usually called RAM  Computer can directly access any memory location  Sequential Access  Data is generally found by searching through other items first  More common in secondary memory
  • 17. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. The Processor  Typically called the CPU  Central Processing Unit  Follows program instructions  Typical capabilities of CPU include: add subtract multiply divide move data from location to location
  • 18. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Computer Software  The operating system  Allows us to communicate with the computer  Is a program  Allocates the computer’s resources  Responds to user requests to run other programs  Common operating systems include…  UNIX Linux DOS Windows Macintosh VMS
  • 19. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Computer Input  Computer input consists of  A program  Some data Display 1.3
  • 20. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.3 Back Next
  • 21. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. High-level Languages  Common programming languages include … C C++ Java Pascal Visual Basic FORTRAN Perl PHP Lisp Scheme Ada C# Python  These high – level languages  Resemble human languages  Are designed to be easy to read and write  Use more complicated instructions than the CPU can follow  Must be translated to zeros and ones for the CPU to execute a program
  • 22. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Low-level Languages  An assembly language command such as ADD X Y Z might mean add the values found at x and y in memory, and store the result in location z.  Assembly language must be translated to machine language (zeros and ones) 0110 1001 1010 1011  The CPU can follow machine language
  • 23. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Compilers  Translate high-level language to machine language  Source code  The original program in a high level language  Object code  The translated version in machine language Display 1.4
  • 24. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Linkers  Some programs we use are already compiled  Their object code is available for us to use  For example: Input and output routines  A Linker combines  The object code for the programs we write and  The object code for the pre-compiled routines into  The machine language program the CPU can run Display 1.5
  • 25. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. 1.2 Programming and Problem- Solving
  • 26. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Algorithms  Algorithm  A sequence of precise instructions that leads to a solution  Program  An algorithm expressed in a language the computer can understand Display 1.6
  • 27. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Program Design  Programming is a creative process  No complete set of rules for creating a program  Program Design Process  Problem Solving Phase  Result is an algorithm that solves the problem  Implementation Phase  Result is the algorithm translated into a programming language
  • 28. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Problem Solving Phase  Be certain the task is completely specified  What is the input?  What information is in the output?  How is the output organized?  Develop the algorithm before implementation  Experience shows this saves time in getting your program to run.  Test the algorithm for correctness
  • 29. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Implementation Phase  Translate the algorithm into a programming language  Easier as you gain experience with the language  Compile the source code  Locates errors in using the programming language  Run the program on sample data  Verify correctness of results  Results may require modification of the algorithm and program Display 1.7
  • 30. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Object Oriented Programming  Abbreviated OOP  Used for many modern programs  Program is viewed as interacting objects  Each object contains algorithms to describe its behavior  Program design phase involves designing objects and their algorithms
  • 31. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. OOP Characteristics  Encapsulation  Information hiding  Objects contain their own data and algorithms  Inheritance  Writing reusable code  Objects can inherit characteristics from other objects  Polymorphism  A single name can have multiple meanings depending on its context
  • 32. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Software Life Cycle  Analysis and specification of the task (problem definition)  Design of the software (object and algorithm design)  Implementation (coding)  Maintenance and evolution of the system  Obsolescence
  • 33. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Section 1.2 Conclusion  Can you…  Describe the first step to take when creating a program?  List the two main phases of the program design process?  Explain the importance of the problem-solving phase?  List the steps in the software life cycle?
  • 34. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. 1.3 Introduction to C++
  • 35. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Introduction to C++  Where did C++ come from?  Derived from the C language  C was derived from the B language  B was derived from the BCPL language  Why the ‘++’?  ++ is an operator in C++ and results in a cute pun
  • 36. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. C++ History  C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s.  Used to maintain UNIX systems  Many commercial applications written in c  C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s.  Overcame several shortcomings of C  Incorporated object oriented programming  C remains a subset of C++
  • 37. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. A Sample C++ Program  A simple C++ program begins this way #include <iostream> using namespace std; int main() {  And ends this way return 0; } Display 1.8
  • 38. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Explanation of code (1/5)  Variable declaration line int numberOfPods, peasPerPod, totalPeas;  Identifies names of three variables to name numbers  int means that the variables represent integers
  • 39. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Explanation of code (2/5)  Program statement cout << “Press return after entering a number.n”;  cout (see-out) used for output to the monitor  “<<“ inserts “Press…a number.n” in the data bound for the monitor  Think of cout as a name for the monitor  “<<“ points to where the data is to end up  ‘n’ causes a new line to be started on the monitor
  • 40. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Explanation of code (3/5)  Program statement cin >> numberOfPods;  cin (see-in) used for input from the keyboard  “>>” extracts data from the keyboard  Think of cin as a name for the keyboard  “>>” points from the keyboard to a variable where the data is stored
  • 41. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Explanation of code (4/5)  Program statement totalPeas = numberOfPods * peasPerPod;  Performs a computation  ‘*’ is used for multiplication  ‘=‘ causes totalPeas to get a new value based on the calculation shown on the right of the equal sign
  • 42. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Explanation of code (5/5)  Program statement cout << numberOfPods;  Sends the value of variable numberOfPods to the monitor
  • 43. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Program Layout (1/3)  Compiler accepts almost any pattern of line breaks and indentation  Programmers format programs so they are easy to read  Place opening brace ‘{‘ and closing brace ‘}’ on a line by themselves  Indent statements  Use only one statement per line
  • 44. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Program Layout (2/3)  Variables are declared before they are used  Typically variables are declared at the beginning of the program  Statements (not always lines) end with a semi-colon  Include Directives #include <iostream>  Tells compiler where to find information about items used in the program  iostream is a library containing definitions of cin and cout
  • 45. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Program Layout (3/3)  using namespace std;  Tells the compiler to use names in iostream in a “standard” way  To begin the main function of the program int main() {  To end the main function return 0; }  Main function ends with a return statement
  • 46. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Running a C++ Program  C++ source code is written with a text editor  The compiler on your system converts source code to object code.  The linker combines all the object code into an executable program.
  • 47. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. C++11  C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ programming language.  Approved on August 12, 2011 by the International Organization for Standardization.  C++11 language features are not supported by older compilers  Check the documentation with your compiler to determine if special steps are needed to compile C++11 programs  e.g. with g++, use extra flags of –std=c++11
  • 48. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Run a Program  Obtain code in Display 1.10  Compile the code  Fix any errors the compiler indicates and re-compile the code  Run the program  Now you know how to run a program on your system Display 1.10
  • 49. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Section 1.3 Conclusion  Can you…  Describe the output of this line? cout << “C++ is easy to understand.”;  Explain what this line does? cin >> peasPerPod;  Explain this? #include <iostream>
  • 50. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. 1.4 Testing and Debugging
  • 51. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Testing and Debugging  Bug  A mistake in a program  Debugging  Eliminating mistakes in programs  Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.”
  • 52. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Program Errors  Syntax errors  Violation of the grammar rules of the language  Discovered by the compiler  Error messages may not always show correct location of errors  Run-time errors  Error conditions detected by the computer at run-time  Logic errors  Errors in the program’s algorithm  Most difficult to diagnose  Computer does not recognize an error
  • 53. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Section 1-4 Conclusion  Can you…  Describe the three kinds of program errors?  Tell what kind of errors the compiler catches?  What kind of error is produced if you forget a punctuation symbol such as a semi-colon?  Tell what type of error is produced when a program runs but produces incorrect results?
  • 54. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Chapter 1 -- End
  • 55. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.1 Back Next
  • 56. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.2 Back Next
  • 57. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.3 Back Next
  • 58. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.4 Back Next
  • 59. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.5 Back Next
  • 60. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.6 Back Next
  • 61. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.7 Back Next
  • 62. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.8 Next Back
  • 63. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.9 Back Next
  • 64. Copyright © 2018 Pearson Addison-Wesley. All rights reserved. Display 1.10 Next Back