SlideShare a Scribd company logo
CHAPTER 1
AN OVERVIEW OF COMPUTERS
AND PROGRAMMING
LANGUAGES
In this chapter, you will:
 Learn about different types of computers
 Explore the hardware and software components of a computer
system
 Learn about the language of a computer
 Learn about the evolution of programming languages
 Examine high-level programming languages
 Discover what a compiler is and what it does
 Examine how a high-level language program is processed
 Learn what an algorithm is and explore problem-solving
techniques
 Become aware of structured design and object-oriented design
programming methodologies
 Become aware of Standard C++ and ANSI/ISO Standard C++
A BRIEF OVERVIEW OF THE HISTORY OF
COMPUTERS
Computers that are in use can be classified in the following categories:
• Main frame computers.
• Mid size computers.
• Micro computers (also called personal computers).
ELEMENTS OF A COMPUTER SYSTEM
Hardware
CPU-The CPU has several components in it.
 CU - It has three main functions.
 Fetch and decode the instruction.
 Control the flow of information (instruction or data) in
and out of MM.
 Control the operation of the internal components of
CPU.
• PC-program counter points to the next instruction to be
executed.
• IR-instruction register holds the instruction that is currently
being executed.
• ALU-arithmetic logic unit. This component is responsible for
carrying out all arithmetic and logical operations.
• ACC-accumulator. Once ALU performs the operation the
results are placed in ACC.
01CHAP_1.PPT
Main Memory
 Directly connected to the CPU.
 All programs must be loaded into MM before they can be
executed.
 All data must be brought into MM before it can be manipulated.
 When the power of the computer is turned off every thing in the
main memory is lost for good.
01CHAP_1.PPT
Secondary storage
 Everything in main memory is lost when the computer is
turned off.
 Information stored in main memory must be transferred to
some other device for permanent storage.
 The device that stores information permanently is called
secondary storage.
 Examples of secondary storage are hard disks, floppy
disks, Zip disks,CD-ROMs, and tapes.
Input/Output devices
 For a computer to perform a useful task, it must be able to
take in data and programs and display the results of
calculations.
 The devices that feed data and programs into computers
are called input devices.
 The keyboard, mouse, and secondary storage are
examples of input devices.
 The devices that the computer uses to display results are
called output devices.
 A monitor, printer, and secondary storage are examples of
output devices.
Software
 Software are programs written to perform specific tasks.
 Two types of programs
 System programs - programs that take control of the
computer.
 Application programs - programs that perform a specific
task. (Word processors, spreadsheets, and games are
examples of application programs.)
THE LANGUAGE OF A COMPUTER
• Two types of electrical signal - analog and digital. Since inside
the computer digital signals are processed, the language of a
computer is a sequence of 0s and 1s.
• The language of a computer is called the machine language.
• The digit 0 or 1 is called a binary digit or in short form a bit.
• A sequence of 0s and 1s is also referred as a binary code.
Bit: A bit is a binary digit 0 or 1.
• A sequence of 8 bits is called a byte.
• Coding Scheme
• ASCII (American Standard Code for Information Interchange).
• 128 characters
•A is encoded as 1000001 (66th character)
•3 is encoded as 0110011.
• EBCDIC (used by IBM)-256 characters
• Unicode - 65536 characters. Two bytes are needed to store a
character.
THE EVOLUTION OF PROGRAMMING
LANGUAGES
 Early computers were programmed in machine language.
Suppose we want to represent the equation
wages = rate · hours
to calculate the weekly wages in machine language.
If 100100 stands for load, 100110 stands for multiplication and
100010 stands for store, then the following sequence of instructions
might be needed to calculate the weekly wages.
100100 0000 010001
100110 0000 010010
100010 0000 010011
Assembly languages - an instruction in assembly language is an easy-
to-remember form called a mnemonic.
Using the assembly language instructions, the equation to calculate the
weekly wages can be written as follows:
LOAD rate
MULT hour
STOR wages
Assembler: An assembler is a program that translates a program written in
assembly language into an equivalent program in machine language.
High level languages- Basic, FORTRAN, COBOL, Pascal,
C++, C
In order to calculate the weekly wages, the equation
wages = rate · hours
in C++, can be written as follows:
wages = rate * hours;
Compiler: A compiler is a program that translates a program written
in a high level language to an equivalent machine language.
PROCESSING A HIGH-LEVEL LANGUAGE
PROGRAM
The following steps are necessary to execute a program written in a
high level language, say, C++:
1. Use an editor to create a program (that is type) in C++. This program
is called the source program.
Source program: A program written in a high-level language.
2. Check that the program obeys the rules of the programming
language and translate the program in to an equivalent machine
language. All this is accomplished by the compiler. The equivalent
machine language program is called an object program.
Object program: The machine language version of the high-
level language program.
3. The programs that you write in a high-level language are
developed using a software development kit (SDK), which
contains many programs that are useful in creating your
program. This prewritten code resides in a place called the
library.
Linker: A program that combines the object program with other
programs provided by the SDK and used in the program to
create the executable code.
4. The next step is to load the executable program into the main
memory for execution and a program called loader
accomplishes this.
Loader: A program that loads an executable program into main
memory.
5. The final step is to execute the program.
01CHAP_1.PPT
PROGRAMMING WITH THE PROBLEM ANALYSIS–
CODING–EXECUTION CYCLE
• Programming is a process of problem solving.
• Problem solving techniques
 Analyze the problem
 Outline the problem requirements
 Design steps, called an algorithm, to solve the problem
Algorithm: A step-by-step problem-solving process in
which a solution is arrived at in a finite amount of time.
Problem solving process
1. (a) Analyze the problem.
(b) Outline the problem and its solution requirements.
(c) Design steps (algorithm) to solve the problem.
2. (a) Implement the algorithm in a programming language,
such as C++.
(b) Verify that the algorithm works.
3. Maintenance: Maintenance requires using and modifying the
program if the problem domain changes.
Problem Analysis-Coding-Execution Cycle
Analysis of the problem is the first and the most important step. This
phase requires us to:
1. Thoroughly understand what the problem is about.
2. Understand the problem requirements. Some of the
requirements could be:
a. Does the program require interaction with the user?
b. Does the program manipulate data? If the program manipulates
data, the programmer must know what the data are and how the
data are represented, that is, look at sample data.
c. Is there any output of the program? If yes, the programmer should
know how the results should be generated.
3. If the problem is complex, divide the problem into sub-
problems. Analyze each sub-problem as above.
• Dividing a problem into smaller subproblems is called
structured design.
• The structured design approach is also known as top-down
design, stepwise refinement, and modular programming.
• In structured design, the problem is divided into smaller
problems.
• Each subproblem is then analyzed, and a solution is obtained
to solve the subproblem.
• The solutions of all subproblems are then combined to solve
the overall problem.
• This process of implementing a structured design is called
structured programming.
• The next step is to design an algorithm to solve the problem.
• If the problem was broken into subproblems, design algorithms for
each subproblem.
• Once the necessary steps have been designed, check the correctness of
the algorithm.
• Sometimes algorithm’s correctness can be tested using sample data.
• At times some mathematical analysis might be required to test the
correctness of the algorithm.
• Once the algorithm is designed and correctness verified, the next step
is to write the equivalent code into the high level language.
• Then using an editor enter the program into the computer.
• The next step is to ensure that the program follows the constructs of
the language.
• Run the code through the compiler.
• If the compiler generates error, we must go back, look at the code,
remove the errors, and run the code again through the compiler.
• If there are no syntax errors, the compiler generates the equivalent
machine code, the linker links the machine code with the systems
resources, and the loader can then place the program into the main
memory so that it can be executed.
• The final step is to execute the program.
• The compiler only guarantees that the program follows the rules of the
language. It does not guarantee that the program will run correctly.
Example 1-1
Design an algorithm to find the perimeter and area of a
rectangle.
The perimeter and area of the rectangle are given by the
following formulas:
perimeter = 2 · (length + width)
area = length · width
The algorithm to find the perimeter and area of the rectangle
is, therefore:
1. Get the length of the rectangle.
2. Get the width of the rectangle.
3. Find the perimeter using the following equation:
perimeter = 2 · (length + width)
4. Find the area using the following equation:
area = length · width
Example 1-2
Design an algorithm that calculates the monthly paycheck of a sales-
person at a local department store.
Every salesperson has a base salary. The salesperson also receives a
bonus at the end of each month based on the following criteria: If the
salesperson has been with the store for five or less years, the bonus is
$10 for each year that he or she has worked there. If the salesperson has
been with the store for more than five years, the bonus is $20 for each
year that he or she has worked there. The salesperson can earn an
additional bonus as follows: If the total sale made by the salesperson for
the month is more than $5000 but less than $10000, he or she receives a
3% commission on the sale. If the total sale made by the salesperson for
the month is at least $10000, he or she receives a 6% commission on the
sale.
The algorithm to calculate a salesperson’s monthly paycheck.
1. Get baseSalary.
2. Get noOfServiceYears.
3. Calculate bonus using the following formula:
if(noOfServiceYears is less than or equal to
five)
bonus = 10 · noOfServiceYears
otherwise
bonus = 20 · noOfServiceYears
4. Get totalSale.
5. Calculate additionalBonus using the following formula.
if (totalSale is less than 5000)
additionalBonus = 0
otherwise
if(totalSale is greater than or equal to
5000 and totalSale is less than 10000)
additionalBonus = totalSale · (0.03)
otherwise
additionalBonus = totalSale · (0.06)
6. Calculate payCheck using the equation
payCheck = baseSalary + bonus + additionalBonus
OBJECT-ORIENTED PROGRAMMING
• In OOD, the first step in the problem-solving process is to identify
components called objects, which form the basis of the solution, and
determine how these objects interact with one another.
• After identifying the objects, the next step is to specify for each object
the relevant data and possible operations to be performed on that data.
• Each object consists of data and operations on that data.
• An object combines data and operations on the data into a single unit.
• A programming language that implements OOD is called an object-
oriented programming (OOP) language.
• Because an object consists of data and operations on that data, you
need to learn how to represent data in computer memory, how to
manipulate data, and how to implement operations.
• To create operations, you write algorithms and implement them in a
programming language.
• To work with objects, you need to know how to combine data and
operations on the data into a single unit.
• C++ was designed especially to implement OOD. Furthermore, OOD
works well and is used in conjunction with structured design.

More Related Content

PPTX
Computer Programming By Prof.(Dr.) Anand K. Tripathi ,Mrs Monika Tripathi
PPT
CHAPTER-1.ppt
PPTX
chapter _3.pptx Programming Language in DSS
PPTX
Lecture1.Introduction to Computer programming.pptx
PPTX
Introduction to Computer, Programming languages , Networks and Internet.pptx
PPTX
01-PROGRAMMING introA of the class name. Pptx
PPTX
programming for problem solving-1 unit -1 ppt.pptx
PPTX
Programming for Problem Solving
Computer Programming By Prof.(Dr.) Anand K. Tripathi ,Mrs Monika Tripathi
CHAPTER-1.ppt
chapter _3.pptx Programming Language in DSS
Lecture1.Introduction to Computer programming.pptx
Introduction to Computer, Programming languages , Networks and Internet.pptx
01-PROGRAMMING introA of the class name. Pptx
programming for problem solving-1 unit -1 ppt.pptx
Programming for Problem Solving

Similar to 01CHAP_1.PPT (20)

PDF
C progrmming
PDF
6272 cnote
PPTX
Introduction_to_Programming.pptx
PPTX
c programming 1-1.pptx
PDF
PPS Unit-1.pdf
DOCX
Interaction With Computers FIT
PPT
C programming for Computing Techniques
PPT
programming language(C++) chapter-one contd.ppt
PPTX
lecture Slides - Week 1.programming fundamentals
PPTX
Computer Programming In C.pptx
PPTX
Computer and programing basics.pptx
PPTX
CSC204PPTNOTES
PPTX
Program Logic and Design
PDF
Namdeo Kapale Sanjivani College of Engineering KopaCFP_UNIT1_24-25.pdf
PPTX
Introductions to Design Logic.pptx IT level
PPTX
Lecture 1 Introduction.pptx hfjsh huwhf uwej wiuehfi w
PDF
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy1.pdf
PPTX
Introduction to computer programming
PPTX
introductiontocomputerprogramming.pptx
PPT
An overview of computers and programming languages
C progrmming
6272 cnote
Introduction_to_Programming.pptx
c programming 1-1.pptx
PPS Unit-1.pdf
Interaction With Computers FIT
C programming for Computing Techniques
programming language(C++) chapter-one contd.ppt
lecture Slides - Week 1.programming fundamentals
Computer Programming In C.pptx
Computer and programing basics.pptx
CSC204PPTNOTES
Program Logic and Design
Namdeo Kapale Sanjivani College of Engineering KopaCFP_UNIT1_24-25.pdf
Introductions to Design Logic.pptx IT level
Lecture 1 Introduction.pptx hfjsh huwhf uwej wiuehfi w
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy1.pdf
Introduction to computer programming
introductiontocomputerprogramming.pptx
An overview of computers and programming languages
Ad

More from ManoRanjani30 (12)

PPTX
Java_Programming_Concepts_Full_P22_P60.pptx
PPT
Number_Systems _binary_octal_hex_dec.ppt
PPTX
Next_Gen_Learning_AI_Collaboration_PPT.pptx
PPTX
Next-Gen Learning AI + Collaboration in Classrooms.pptx
PPTX
introduction to visual basic unit 1.pptx
PPT
operating system Scheduling process unit 3.ppt
PPTX
os memory management unit iii memory.pptx
PPTX
operating system_processes_ unit II.pptx
PPTX
Consumers-Oriented Applicaations 1 .pptx
PPT
Network model.ppt
PPT
E-r Model.ppt
PPT
dijkstraC.ppt
Java_Programming_Concepts_Full_P22_P60.pptx
Number_Systems _binary_octal_hex_dec.ppt
Next_Gen_Learning_AI_Collaboration_PPT.pptx
Next-Gen Learning AI + Collaboration in Classrooms.pptx
introduction to visual basic unit 1.pptx
operating system Scheduling process unit 3.ppt
os memory management unit iii memory.pptx
operating system_processes_ unit II.pptx
Consumers-Oriented Applicaations 1 .pptx
Network model.ppt
E-r Model.ppt
dijkstraC.ppt
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Business Ethics Teaching Materials for college
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Complications of Minimal Access Surgery at WLH
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
master seminar digital applications in india
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
TR - Agricultural Crops Production NC III.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pharma ospi slides which help in ospi learning
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
Business Ethics Teaching Materials for college
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Complications of Minimal Access Surgery at WLH
2.FourierTransform-ShortQuestionswithAnswers.pdf
Renaissance Architecture: A Journey from Faith to Humanism
master seminar digital applications in india
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
TR - Agricultural Crops Production NC III.pdf

01CHAP_1.PPT

  • 1. CHAPTER 1 AN OVERVIEW OF COMPUTERS AND PROGRAMMING LANGUAGES
  • 2. In this chapter, you will:  Learn about different types of computers  Explore the hardware and software components of a computer system  Learn about the language of a computer  Learn about the evolution of programming languages  Examine high-level programming languages  Discover what a compiler is and what it does  Examine how a high-level language program is processed  Learn what an algorithm is and explore problem-solving techniques  Become aware of structured design and object-oriented design programming methodologies  Become aware of Standard C++ and ANSI/ISO Standard C++
  • 3. A BRIEF OVERVIEW OF THE HISTORY OF COMPUTERS Computers that are in use can be classified in the following categories: • Main frame computers. • Mid size computers. • Micro computers (also called personal computers).
  • 4. ELEMENTS OF A COMPUTER SYSTEM Hardware CPU-The CPU has several components in it.  CU - It has three main functions.  Fetch and decode the instruction.  Control the flow of information (instruction or data) in and out of MM.  Control the operation of the internal components of CPU. • PC-program counter points to the next instruction to be executed. • IR-instruction register holds the instruction that is currently being executed. • ALU-arithmetic logic unit. This component is responsible for carrying out all arithmetic and logical operations. • ACC-accumulator. Once ALU performs the operation the results are placed in ACC.
  • 6. Main Memory  Directly connected to the CPU.  All programs must be loaded into MM before they can be executed.  All data must be brought into MM before it can be manipulated.  When the power of the computer is turned off every thing in the main memory is lost for good.
  • 8. Secondary storage  Everything in main memory is lost when the computer is turned off.  Information stored in main memory must be transferred to some other device for permanent storage.  The device that stores information permanently is called secondary storage.  Examples of secondary storage are hard disks, floppy disks, Zip disks,CD-ROMs, and tapes.
  • 9. Input/Output devices  For a computer to perform a useful task, it must be able to take in data and programs and display the results of calculations.  The devices that feed data and programs into computers are called input devices.  The keyboard, mouse, and secondary storage are examples of input devices.  The devices that the computer uses to display results are called output devices.  A monitor, printer, and secondary storage are examples of output devices.
  • 10. Software  Software are programs written to perform specific tasks.  Two types of programs  System programs - programs that take control of the computer.  Application programs - programs that perform a specific task. (Word processors, spreadsheets, and games are examples of application programs.)
  • 11. THE LANGUAGE OF A COMPUTER • Two types of electrical signal - analog and digital. Since inside the computer digital signals are processed, the language of a computer is a sequence of 0s and 1s. • The language of a computer is called the machine language. • The digit 0 or 1 is called a binary digit or in short form a bit. • A sequence of 0s and 1s is also referred as a binary code.
  • 12. Bit: A bit is a binary digit 0 or 1. • A sequence of 8 bits is called a byte. • Coding Scheme • ASCII (American Standard Code for Information Interchange). • 128 characters •A is encoded as 1000001 (66th character) •3 is encoded as 0110011. • EBCDIC (used by IBM)-256 characters • Unicode - 65536 characters. Two bytes are needed to store a character.
  • 13. THE EVOLUTION OF PROGRAMMING LANGUAGES  Early computers were programmed in machine language. Suppose we want to represent the equation wages = rate · hours to calculate the weekly wages in machine language. If 100100 stands for load, 100110 stands for multiplication and 100010 stands for store, then the following sequence of instructions might be needed to calculate the weekly wages. 100100 0000 010001 100110 0000 010010 100010 0000 010011
  • 14. Assembly languages - an instruction in assembly language is an easy- to-remember form called a mnemonic. Using the assembly language instructions, the equation to calculate the weekly wages can be written as follows: LOAD rate MULT hour STOR wages Assembler: An assembler is a program that translates a program written in assembly language into an equivalent program in machine language.
  • 15. High level languages- Basic, FORTRAN, COBOL, Pascal, C++, C In order to calculate the weekly wages, the equation wages = rate · hours in C++, can be written as follows: wages = rate * hours; Compiler: A compiler is a program that translates a program written in a high level language to an equivalent machine language.
  • 16. PROCESSING A HIGH-LEVEL LANGUAGE PROGRAM The following steps are necessary to execute a program written in a high level language, say, C++: 1. Use an editor to create a program (that is type) in C++. This program is called the source program. Source program: A program written in a high-level language. 2. Check that the program obeys the rules of the programming language and translate the program in to an equivalent machine language. All this is accomplished by the compiler. The equivalent machine language program is called an object program. Object program: The machine language version of the high- level language program.
  • 17. 3. The programs that you write in a high-level language are developed using a software development kit (SDK), which contains many programs that are useful in creating your program. This prewritten code resides in a place called the library. Linker: A program that combines the object program with other programs provided by the SDK and used in the program to create the executable code. 4. The next step is to load the executable program into the main memory for execution and a program called loader accomplishes this. Loader: A program that loads an executable program into main memory. 5. The final step is to execute the program.
  • 19. PROGRAMMING WITH THE PROBLEM ANALYSIS– CODING–EXECUTION CYCLE • Programming is a process of problem solving. • Problem solving techniques  Analyze the problem  Outline the problem requirements  Design steps, called an algorithm, to solve the problem Algorithm: A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time.
  • 20. Problem solving process 1. (a) Analyze the problem. (b) Outline the problem and its solution requirements. (c) Design steps (algorithm) to solve the problem. 2. (a) Implement the algorithm in a programming language, such as C++. (b) Verify that the algorithm works. 3. Maintenance: Maintenance requires using and modifying the program if the problem domain changes.
  • 22. Analysis of the problem is the first and the most important step. This phase requires us to: 1. Thoroughly understand what the problem is about. 2. Understand the problem requirements. Some of the requirements could be: a. Does the program require interaction with the user? b. Does the program manipulate data? If the program manipulates data, the programmer must know what the data are and how the data are represented, that is, look at sample data. c. Is there any output of the program? If yes, the programmer should know how the results should be generated. 3. If the problem is complex, divide the problem into sub- problems. Analyze each sub-problem as above.
  • 23. • Dividing a problem into smaller subproblems is called structured design. • The structured design approach is also known as top-down design, stepwise refinement, and modular programming. • In structured design, the problem is divided into smaller problems. • Each subproblem is then analyzed, and a solution is obtained to solve the subproblem. • The solutions of all subproblems are then combined to solve the overall problem. • This process of implementing a structured design is called structured programming.
  • 24. • The next step is to design an algorithm to solve the problem. • If the problem was broken into subproblems, design algorithms for each subproblem. • Once the necessary steps have been designed, check the correctness of the algorithm. • Sometimes algorithm’s correctness can be tested using sample data. • At times some mathematical analysis might be required to test the correctness of the algorithm. • Once the algorithm is designed and correctness verified, the next step is to write the equivalent code into the high level language. • Then using an editor enter the program into the computer.
  • 25. • The next step is to ensure that the program follows the constructs of the language. • Run the code through the compiler. • If the compiler generates error, we must go back, look at the code, remove the errors, and run the code again through the compiler. • If there are no syntax errors, the compiler generates the equivalent machine code, the linker links the machine code with the systems resources, and the loader can then place the program into the main memory so that it can be executed. • The final step is to execute the program. • The compiler only guarantees that the program follows the rules of the language. It does not guarantee that the program will run correctly.
  • 26. Example 1-1 Design an algorithm to find the perimeter and area of a rectangle. The perimeter and area of the rectangle are given by the following formulas: perimeter = 2 · (length + width) area = length · width
  • 27. The algorithm to find the perimeter and area of the rectangle is, therefore: 1. Get the length of the rectangle. 2. Get the width of the rectangle. 3. Find the perimeter using the following equation: perimeter = 2 · (length + width) 4. Find the area using the following equation: area = length · width
  • 28. Example 1-2 Design an algorithm that calculates the monthly paycheck of a sales- person at a local department store. Every salesperson has a base salary. The salesperson also receives a bonus at the end of each month based on the following criteria: If the salesperson has been with the store for five or less years, the bonus is $10 for each year that he or she has worked there. If the salesperson has been with the store for more than five years, the bonus is $20 for each year that he or she has worked there. The salesperson can earn an additional bonus as follows: If the total sale made by the salesperson for the month is more than $5000 but less than $10000, he or she receives a 3% commission on the sale. If the total sale made by the salesperson for the month is at least $10000, he or she receives a 6% commission on the sale.
  • 29. The algorithm to calculate a salesperson’s monthly paycheck. 1. Get baseSalary. 2. Get noOfServiceYears. 3. Calculate bonus using the following formula: if(noOfServiceYears is less than or equal to five) bonus = 10 · noOfServiceYears otherwise bonus = 20 · noOfServiceYears 4. Get totalSale.
  • 30. 5. Calculate additionalBonus using the following formula. if (totalSale is less than 5000) additionalBonus = 0 otherwise if(totalSale is greater than or equal to 5000 and totalSale is less than 10000) additionalBonus = totalSale · (0.03) otherwise additionalBonus = totalSale · (0.06) 6. Calculate payCheck using the equation payCheck = baseSalary + bonus + additionalBonus
  • 31. OBJECT-ORIENTED PROGRAMMING • In OOD, the first step in the problem-solving process is to identify components called objects, which form the basis of the solution, and determine how these objects interact with one another. • After identifying the objects, the next step is to specify for each object the relevant data and possible operations to be performed on that data. • Each object consists of data and operations on that data. • An object combines data and operations on the data into a single unit. • A programming language that implements OOD is called an object- oriented programming (OOP) language. • Because an object consists of data and operations on that data, you need to learn how to represent data in computer memory, how to manipulate data, and how to implement operations. • To create operations, you write algorithms and implement them in a programming language. • To work with objects, you need to know how to combine data and operations on the data into a single unit. • C++ was designed especially to implement OOD. Furthermore, OOD works well and is used in conjunction with structured design.