SlideShare a Scribd company logo
1 of 38
ASTU
CSE 1102 Fundamentals of Programming
Lecture #1
Spring 2019
Computer Science & Engineering Program
The School of EE & Computing
Adama Science & Technology University
ASTU
Problem Solving and Computer Programming
– Problem solving life cycle
– Basics of programming language
Case study: Heat Transfer
Guess a Number Game
Reading assignment
– Chapter 1 of the textbook
– Read about
 Computer Storage
 How a computer runs programs?
 Pseudo Code and Flowchart
-Heat Transfer Notes
http://www.freestudy.co.uk/heat%20transfer/
2
ASTU
Outline
• Problem Solving Life Cycle
– Phase 1: Development
– Phase 2: Documentation
– Phase 3: Maintenance
• Basics of Programming Language
– Programming Languages
• Low level and High level languages
• Compiled vs. Interpreted
• Procedural and Object Oriented
– Compilation in C++
– General Notes on C++
3
ASTU
Software Development
• Computer Program
– Self-contained set of instructions used to
instruct a computer to produce specific result
• Problem Solving Life Cycle
– Also called Software Development Procedure
– Helps developers understand the problem
to be solved and create an effective,
appropriate software solution
4
ASTU
Problem Solving Life Cycle
• Requirement
• Phase 1: Development
– Analysis
– Design
– Coding
– Testing
• Phase 2: Documentation
• Phase 3: Maintenance
5
ASTU
Requirement
• Request for a program or statement of a
problem
• After a program requirement is received,
phase 1 begins.
• In the real world, it is a complex task of
extracting and documenting user
requirements
6
ASTU
Phase 1: Development
• Step 1: Analyze the Problem
– Determine and understand the output items
the program must produce
– Determine the input items
7
ASTU
Phase 1: Development
8
• Step 2: Develop a Solution
– Select the exact set of steps, called
an “algorithm”, to solve the problem
– Refine the algorithm
• Start with initial solution in the analysis step until
you have an acceptable and complete solution
– Check solution
• ***Read about Pseudo Code & Flowchart
ASTU
Phase 1: Development
9
• Step 3: Code the Solution
– Consists of actually writing a C++ program
that corresponds to the solution developed
in Step 2
– Program should contain well-defined
patterns or structures of the following types:
• Sequence
• Selection
• Iteration
• Invocation
ASTU
Phase 1: Development
10
• Step 3: Code the Solution
– Sequence: Defines the order in which
instructions are executed
– Selection: Allows a choice between different
operations, based on some condition
– Iteration: Allows the same operation to be
repeated based on some condition
• Also called looping or repetition
– Invocation: Involves invoking a set of
statements when needed
ASTU
Phase 1: Development
11
• Step 4: Test and Correct the Program
– Testing: Method to verify correctness and
that requirements are met
– Bug : A program error
– Debugging : The process of locating an
error, and correcting and verifying
the correction
– Testing may reveal errors, but does not
guarantee the absence of errors
ASTU
Phase II: Documentation
• Five main documents are needed:
– Program description
– Algorithm development and changes
– Well-commented program listing
– Sample test runs
– Users' manual
12
ASTU
Phase III: Maintenance
• Ongoing correction of newly discovered
bugs
• Revisions to meet changing user needs
• Addition of new features
• Usually the longest phase
• Good documentation vital for effective
maintenance
13
ASTU
Computer Hardware
• Computer hardware: Components that
support the capabilities of the computer
Input Devices
Output Devices
Secondary Memory
Main Memory
CPU
ALU CU
ASTU
Computer Software
• Application software: Programs written
to perform particular tasks for users
• System software: Collection of programs
to operate the computer system
15
ASTU
Computer Software
• Operating system: The set of system
programs used to operate and control a
computer
• Tasks performed by the OS include:
– Memory management
– Allocation of CPU time
– Control of input and output
– Management of secondary storage devices
16
ASTU
A Layered View of the Computer
17
Computer Hardware
System Software
Compilers, Interpreters, Preprocessors
Operating System, Device Drivers
Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs
ASTU
Programming Languages
• Programming: Process of writing a
program, or software
• Programming language
– Set of instructions used to construct a
program
– Comes in a variety of forms and types
18
ASTU
Low and High Level Languages
• Low-level languages: Languages that
use instructions tied directly to one type
of computer
– machine language, assembly language
• High-level languages: Instructions
resemble written languages, such as
English
– Can be run on a variety of computer types
– Visual Basic, C, C++, Java
19
ASTU
Low and High Level Languages
20
ASTU
Machine Language
• Machine language programs : only
programs that can actually be used to
operate a computer
– Also referred to as object codes
– Consists of a sequence of instructions
composed of binary numbers
• Contains two parts: an instruction and an
address
21
Operation Address
0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
ASTU
Assembly Language
• Assembly language programs:
Substitute word-like symbols, such as
ADD, SUB, and MUL, for binary opcodes
– Use decimal numbers and labels for
memory addresses
– One-to-one correspondence
• Usually, each line of assembly code produces
one machine instruction
– Example: ADD 1, 2
• Assemblers: Translate programs into
machine language
22
ASTU
High Level Language
• One-to-many correspondence
– Each statement corresponds to several
machine language instructions
• Much easier to program than in
assembly language.
• Data are referenced using descriptive
names
• Operations can be described using
familiar symbols
• Example:
cost = price + tax
23
ASTU
Compiled vs. Interpreted
• Interpreted: Each statement is translated
individually and executed immediately
after translation
• Compiled: All statements are translated
and stored as an executable program, or
object program; execution occurs later
• C++ is predominantly a compiled language
24
ASTU
Source Code
• The programs written in a high or
low-level language
• It is written by the programmer.
• Can be compiled automatically into
object code or machine code or
executed by an interpreter.
• C++ source programs have extension
‘.cpp’ or ‘.h’
25
ASTU
Compiler
• Translates high-level language to
machine language.
• Input to a compiler is the source code
• Output from the compiler is
the object code (.obj).
26
Compiler
while (num != -1) {
sum += num;
count++;
cin >> num;
}
Source File
.cpp
00001111
00110011
11111111
00000000
11100111
Object File
.obj
ASTU
Linker
• Combines your object code with
pre-compiled object libraries for
input/output etc.
• Input are the object files (.obj).
• Output is the executable file (.exe) in
Windows.
27
Linker
00001111
00110011
11111111
00000000
11100111
Library Files
.obj
00001111
00110011
11111111
00000000
11100111
Object File
.obj
Executable File
.exe
ASTU
Compilation Process in C++
• C++ actually adds an extra step to the
compilation process
– the code is run through a preprocessor,
which applies some modifications to the
source code, before being fed to the
compiler.
Eg. Removing comment
28
ASTU
Program in Memory
• The purpose of most application
programs is to process data to produce
specific results
29
ASTU
General Notes on C++
• C++ is immensely popular
– particularly for applications that require
speed and/or access to some low-level
features.
• It was created in 1979 by
Bjarne Stroustrup
– at first as a set of extensions
– to the C programming language.
30
ASTU
General Notes on C++
• You can write graphical programs in
C++
– it is much harder and less portable than text
based(console)programs.
– We will be sticking to console programs in
this course.
• Everything in C++ is case sensitive:
– someName is not the same as SomeName.
31
ASTU
Case Study: Heat Transfer
• The following formula is used to
determine the heat transferred through a
flat substance, such as a wall, with its
two sides maintained at different
temperatures:
q = −𝑘
𝑇2 − 𝑇1
𝑑
32
ASTU
Case Study: Heat Transfer
– q is the heat transfer.
– k is the thermal conductivity of the
substance in watts/m°C.
– T2 is the higher temperature on one side of
the substance in °C.
– T1 is the lower temperature on the other
side of the wall in °C.
– d is the thickness of the substance in
meters.
33
ASTU
Case Study: Heat Transfer
• Determine the units of q
– by calculating the units resulting from the
right side of the formula.
• A glass window
• thickness of 0.5 centimeters,
• thermal conductivity of 0.77 watts/m°C, and
• outside and inside temperatures of 36.6°C &
22.2°,
• Determine the value of q.
34
ASTU
Case Study: Heat Transfer
• If you were asked to write a computer
program to determine the heat transfer
through a substance, what inputs,
outputs, and algorithm would your
program require?
35
ASTU
Case Study: Guess a Number Game
Step 1: Analyze the Problem
– The objective is to randomly generate an
integer greater than or equal to 0 and less
than 100. Then prompt the player (user) to
guess the number.
– Input: Guessed Number
– Output: Guess is Correct or Guess is Higher,
or Guess is Lower
36
ASTU
Case Study: Guess a Number Game
Step 2: Develop a Solution
1. Accept guessed number from user
2. If the player guesses the number correctly,
output an appropriate message.
3. If the guessed number is less than the
random number generated
display ‘‘guess is lower than the number. Guess again!’’;
4. Otherwise
display ‘‘guess is higher than the number. Guess again!’’;
37
ASTU
Case Study: Guess a Number Game
Step 3: Then prompt the player to enter
another number.
Step 4: The player is prompted to guess
the random number until the player
enters the correct number and stop after
fixed no of trials .
38

More Related Content

Similar to CPP Lecture 1.pptx

Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThAram Mohammed
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Mohamed El Desouki
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsSasidharaRaoMarrapu
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++Seble Nigussie
 
Computer and programing basics.pptx
Computer and programing basics.pptxComputer and programing basics.pptx
Computer and programing basics.pptxgaafergoda
 
l1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxl1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxssuser6f38e5
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cppManzoor ALam
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdfDinashMaliya3
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptxchouguleamruta24
 
ch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesLiemLe21
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 

Similar to CPP Lecture 1.pptx (20)

Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++
 
Chapter1.ppt
Chapter1.pptChapter1.ppt
Chapter1.ppt
 
Pj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentalsPj01 1-computer and programming fundamentals
Pj01 1-computer and programming fundamentals
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
Mini Project- USB Temperature Logging
Mini Project- USB Temperature LoggingMini Project- USB Temperature Logging
Mini Project- USB Temperature Logging
 
Computer and programing basics.pptx
Computer and programing basics.pptxComputer and programing basics.pptx
Computer and programing basics.pptx
 
l1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptxl1-introduction_to_computers_and_c_programming.pptx
l1-introduction_to_computers_and_c_programming.pptx
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cpp
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 
CSC204PPTNOTES
CSC204PPTNOTESCSC204PPTNOTES
CSC204PPTNOTES
 
ch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesch01_an overview of computers and programming languages
ch01_an overview of computers and programming languages
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Chapter 01.PPT
Chapter 01.PPTChapter 01.PPT
Chapter 01.PPT
 

Recently uploaded

High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 

Recently uploaded (20)

High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 

CPP Lecture 1.pptx

  • 1. ASTU CSE 1102 Fundamentals of Programming Lecture #1 Spring 2019 Computer Science & Engineering Program The School of EE & Computing Adama Science & Technology University
  • 2. ASTU Problem Solving and Computer Programming – Problem solving life cycle – Basics of programming language Case study: Heat Transfer Guess a Number Game Reading assignment – Chapter 1 of the textbook – Read about  Computer Storage  How a computer runs programs?  Pseudo Code and Flowchart -Heat Transfer Notes http://www.freestudy.co.uk/heat%20transfer/ 2
  • 3. ASTU Outline • Problem Solving Life Cycle – Phase 1: Development – Phase 2: Documentation – Phase 3: Maintenance • Basics of Programming Language – Programming Languages • Low level and High level languages • Compiled vs. Interpreted • Procedural and Object Oriented – Compilation in C++ – General Notes on C++ 3
  • 4. ASTU Software Development • Computer Program – Self-contained set of instructions used to instruct a computer to produce specific result • Problem Solving Life Cycle – Also called Software Development Procedure – Helps developers understand the problem to be solved and create an effective, appropriate software solution 4
  • 5. ASTU Problem Solving Life Cycle • Requirement • Phase 1: Development – Analysis – Design – Coding – Testing • Phase 2: Documentation • Phase 3: Maintenance 5
  • 6. ASTU Requirement • Request for a program or statement of a problem • After a program requirement is received, phase 1 begins. • In the real world, it is a complex task of extracting and documenting user requirements 6
  • 7. ASTU Phase 1: Development • Step 1: Analyze the Problem – Determine and understand the output items the program must produce – Determine the input items 7
  • 8. ASTU Phase 1: Development 8 • Step 2: Develop a Solution – Select the exact set of steps, called an “algorithm”, to solve the problem – Refine the algorithm • Start with initial solution in the analysis step until you have an acceptable and complete solution – Check solution • ***Read about Pseudo Code & Flowchart
  • 9. ASTU Phase 1: Development 9 • Step 3: Code the Solution – Consists of actually writing a C++ program that corresponds to the solution developed in Step 2 – Program should contain well-defined patterns or structures of the following types: • Sequence • Selection • Iteration • Invocation
  • 10. ASTU Phase 1: Development 10 • Step 3: Code the Solution – Sequence: Defines the order in which instructions are executed – Selection: Allows a choice between different operations, based on some condition – Iteration: Allows the same operation to be repeated based on some condition • Also called looping or repetition – Invocation: Involves invoking a set of statements when needed
  • 11. ASTU Phase 1: Development 11 • Step 4: Test and Correct the Program – Testing: Method to verify correctness and that requirements are met – Bug : A program error – Debugging : The process of locating an error, and correcting and verifying the correction – Testing may reveal errors, but does not guarantee the absence of errors
  • 12. ASTU Phase II: Documentation • Five main documents are needed: – Program description – Algorithm development and changes – Well-commented program listing – Sample test runs – Users' manual 12
  • 13. ASTU Phase III: Maintenance • Ongoing correction of newly discovered bugs • Revisions to meet changing user needs • Addition of new features • Usually the longest phase • Good documentation vital for effective maintenance 13
  • 14. ASTU Computer Hardware • Computer hardware: Components that support the capabilities of the computer Input Devices Output Devices Secondary Memory Main Memory CPU ALU CU
  • 15. ASTU Computer Software • Application software: Programs written to perform particular tasks for users • System software: Collection of programs to operate the computer system 15
  • 16. ASTU Computer Software • Operating system: The set of system programs used to operate and control a computer • Tasks performed by the OS include: – Memory management – Allocation of CPU time – Control of input and output – Management of secondary storage devices 16
  • 17. ASTU A Layered View of the Computer 17 Computer Hardware System Software Compilers, Interpreters, Preprocessors Operating System, Device Drivers Application Programs Word-Processors, Spreadsheets, Database Software, IDEs
  • 18. ASTU Programming Languages • Programming: Process of writing a program, or software • Programming language – Set of instructions used to construct a program – Comes in a variety of forms and types 18
  • 19. ASTU Low and High Level Languages • Low-level languages: Languages that use instructions tied directly to one type of computer – machine language, assembly language • High-level languages: Instructions resemble written languages, such as English – Can be run on a variety of computer types – Visual Basic, C, C++, Java 19
  • 20. ASTU Low and High Level Languages 20
  • 21. ASTU Machine Language • Machine language programs : only programs that can actually be used to operate a computer – Also referred to as object codes – Consists of a sequence of instructions composed of binary numbers • Contains two parts: an instruction and an address 21 Operation Address 0010 0000 0000 0100 0100 0000 0000 0101 0011 0000 0000 0110
  • 22. ASTU Assembly Language • Assembly language programs: Substitute word-like symbols, such as ADD, SUB, and MUL, for binary opcodes – Use decimal numbers and labels for memory addresses – One-to-one correspondence • Usually, each line of assembly code produces one machine instruction – Example: ADD 1, 2 • Assemblers: Translate programs into machine language 22
  • 23. ASTU High Level Language • One-to-many correspondence – Each statement corresponds to several machine language instructions • Much easier to program than in assembly language. • Data are referenced using descriptive names • Operations can be described using familiar symbols • Example: cost = price + tax 23
  • 24. ASTU Compiled vs. Interpreted • Interpreted: Each statement is translated individually and executed immediately after translation • Compiled: All statements are translated and stored as an executable program, or object program; execution occurs later • C++ is predominantly a compiled language 24
  • 25. ASTU Source Code • The programs written in a high or low-level language • It is written by the programmer. • Can be compiled automatically into object code or machine code or executed by an interpreter. • C++ source programs have extension ‘.cpp’ or ‘.h’ 25
  • 26. ASTU Compiler • Translates high-level language to machine language. • Input to a compiler is the source code • Output from the compiler is the object code (.obj). 26 Compiler while (num != -1) { sum += num; count++; cin >> num; } Source File .cpp 00001111 00110011 11111111 00000000 11100111 Object File .obj
  • 27. ASTU Linker • Combines your object code with pre-compiled object libraries for input/output etc. • Input are the object files (.obj). • Output is the executable file (.exe) in Windows. 27 Linker 00001111 00110011 11111111 00000000 11100111 Library Files .obj 00001111 00110011 11111111 00000000 11100111 Object File .obj Executable File .exe
  • 28. ASTU Compilation Process in C++ • C++ actually adds an extra step to the compilation process – the code is run through a preprocessor, which applies some modifications to the source code, before being fed to the compiler. Eg. Removing comment 28
  • 29. ASTU Program in Memory • The purpose of most application programs is to process data to produce specific results 29
  • 30. ASTU General Notes on C++ • C++ is immensely popular – particularly for applications that require speed and/or access to some low-level features. • It was created in 1979 by Bjarne Stroustrup – at first as a set of extensions – to the C programming language. 30
  • 31. ASTU General Notes on C++ • You can write graphical programs in C++ – it is much harder and less portable than text based(console)programs. – We will be sticking to console programs in this course. • Everything in C++ is case sensitive: – someName is not the same as SomeName. 31
  • 32. ASTU Case Study: Heat Transfer • The following formula is used to determine the heat transferred through a flat substance, such as a wall, with its two sides maintained at different temperatures: q = −𝑘 𝑇2 − 𝑇1 𝑑 32
  • 33. ASTU Case Study: Heat Transfer – q is the heat transfer. – k is the thermal conductivity of the substance in watts/m°C. – T2 is the higher temperature on one side of the substance in °C. – T1 is the lower temperature on the other side of the wall in °C. – d is the thickness of the substance in meters. 33
  • 34. ASTU Case Study: Heat Transfer • Determine the units of q – by calculating the units resulting from the right side of the formula. • A glass window • thickness of 0.5 centimeters, • thermal conductivity of 0.77 watts/m°C, and • outside and inside temperatures of 36.6°C & 22.2°, • Determine the value of q. 34
  • 35. ASTU Case Study: Heat Transfer • If you were asked to write a computer program to determine the heat transfer through a substance, what inputs, outputs, and algorithm would your program require? 35
  • 36. ASTU Case Study: Guess a Number Game Step 1: Analyze the Problem – The objective is to randomly generate an integer greater than or equal to 0 and less than 100. Then prompt the player (user) to guess the number. – Input: Guessed Number – Output: Guess is Correct or Guess is Higher, or Guess is Lower 36
  • 37. ASTU Case Study: Guess a Number Game Step 2: Develop a Solution 1. Accept guessed number from user 2. If the player guesses the number correctly, output an appropriate message. 3. If the guessed number is less than the random number generated display ‘‘guess is lower than the number. Guess again!’’; 4. Otherwise display ‘‘guess is higher than the number. Guess again!’’; 37
  • 38. ASTU Case Study: Guess a Number Game Step 3: Then prompt the player to enter another number. Step 4: The player is prompted to guess the random number until the player enters the correct number and stop after fixed no of trials . 38