Programming Logic & OOP
Programming Logic & OOP
• The cycle of activities performed by a computer is referred to as the Input-Process-Output cycle or the I-P-O
cycle
• Each component participates in either one of the input, process, or output phases
Symbol Activity
Input
Processing
Output
Decision
Subroutine
Symbol Activity
Flow lines
Terminator
On page connector
Annotation
Tea is Prepared
Stop
Get a Number
Stop
Start
Stop
• Draw a flowchart to input any number, multiply it by 2, and display the result.
• Example:
▪ Flowchart to display the sum of two numbers
Start
Accept the
First Number
Accept the
Second Number
Stop
• A computer needs to identify the memory locations to be able to retrieve values from or store values in
them.
• The value of a variable changes each time the set of instructions is executed.
Constants
10 15 25
Variables
Start
Accept nNum1
Accept nNum2
Display nSum
Stop
• Draw a flowchart to accept item name, price, and quantity. You need to calculate the value as the product of
price and quantity, and display the calculated value and the item name using variables.
Start
character cltemName
numeric nPrice, nQuantity, nValue
Accept cItemName
Accept nPrice
Accept nQuantity
Stop
• All decisions may or may not state an action to be taken if the condition is false.
• Following is a flowchart segment to compare two numbers and check for equality.
Is nNum1 = No
nNum2 ?
Yes
Start
numeric nNum1,
nNum2
Accept nNum1
Accept nNum2
No
Is Yes
nNum1>nNum2? Display nNum1
No
Display nNum2
Stop
Start
numeric nX
Accept nX
Is
No
nX>10 AND
nX%2=0?
Yes
Display nX
Stop
Is Yes
nNum>10? Display “ GOOD”
No
Is Yes
nNum>5? Display “OK”
No
Display “REJECT”
Stop
Declare Variables
Is
nAverage>= 80 AND No Display “ Rejection
nTest1 > 75 AND letter to be sent”
nTest2 > 75 AND
nTest3 > 75 ?
Yes
Display “Interview
call letter to be sent”
Stop
nCounter = 1
Is No
nCounter<=25?
Yes Stop
Accept cName
Accept cAddress
Accept cTelno
Display cName,
cAddress, cTelno
nCounter=nCounter+1
▪ Flowchart to calculate the total number of call letters and rejection letters sent
Start
Variable Declaration
Accept Values
Is
nAverage >=80 AND No
nTest1 > 75 AND nTotReject=nTotReject+1
nTest2 > 75 AND
nTest3 > 75 ?
Yes
nTotSelect=nTotSelect+1
Process
A B
▪ Flowchart to calculate the total number of call letters and rejection letters sent (Contd.)
A
B
Accept cChoice
Is No
cChoice = “Y”?
Stop
©Larsen & Toubro Infotech Ltd. Privileged and Confidential 30
Modular Programming
• Long, continuous programs can be broken up into a series of individual modules that are related to each
other in a specified manner.
Main
Program
• Example:
• Flowchart to show modular programming
Start
nSum=nNum1 + nNum2
Accept nNum1, + nNum3
nNum2, nNum3
Return
Add
Display nSum
Stop
Accept cStudentName
Accept Average
Accept nTest1
nAverage=(nTest1+nTest2
Accept nTest2 +nTest3) / 3
Average
No
Display “Test score cannot Retur
be less than zero” n
Accept
Is No
Accept nSalary Summation
cChoice = “Y” ?
Yes
nTotSalary=nTotSalary+nSalary
Is Yes
Accept nSalary >=500 ?
Return Return
No
• Draw a flowchart to accept 50 numbers and also display the total number of odd and even numbers.
• Objects are entities that serve as the basic building blocks of an object-oriented application
• Because different people have different perceptions of the same object, what an object is depends upon the
point of view of the observer.
• That is, we describe an object on the basis of the features and behaviors that are important or relevant to us.
getName
getAge()
name
setBirthdate getAge Message
address
birthdate
Client or
sender
getAddress setAddress
Person
©Larsen & Toubro Infotech Ltd. Privileged and Confidential 45
Collaborating Objects
• Collaborating objects work together to complete a task and form the basis of an application system.
• All methods are defined within a class and are not defined globally as in traditional languages.
• All objects are created from classes and contain all the attributes and methods of that class.
• Objects must associate with each other to collaborate on common tasks.
• Associated objects communicate by sending messages.
Account Pen
Load passengers