You are on page 1of 32

CS115C - COMPUTER

PROGRAMMING
ALGORITHM DESIGN
AND REPRESENTATION

• An Algorithm is a clear and unambiguous


specification of the steps needed to solve a
problem.
• It may be expressed in either Human language
(English, Tagalog), through a graphical
representation like a flowchart or through a
pseudocode, which is a cross between human
language and a programming language.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 2


ALGORITHM DESIGN AND
REPRESENTATION

COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 08/07/2023 3


COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY

ALGORITHM
DESIGN AND
REPRESENTA
TION

08/07/2023

4
ALGORITHM DESIGN AND
REPRESENTATION

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 5


COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY

FLOWCHARTING
SYMBOLS AND
THEIR MEANINGS

• A flowchart is a design tool used


to graphically represent the logic
in a solution.
• Flowcharts typically do not display
programming language
commands.

08/07/2023

6
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 7
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 8
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 9
GETTING THE AVERAGE OF
THREE NUMBERS
Start
• Input three (3) numbers
• Validate if numbers are valid
• Add three numbers Enter three
numbers
• Get the average
NO YES Add three numbers
Valid? and get the Average

End Output
Average

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 10


BASIC PROGRAM
STRUCTURE OF
CSHARP
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 11
BASIC STRUCTURE OF CSHARP

Class <Name>{
public static void Main(string[] args)
{
//statement
}
}
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 12
13
08/07/2023
BASIC STRUCTURE OF CSHARP
COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY
Syntax, Keywords, and
Identifiers

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 14


SYNTAX, KEYWORDS, AND IDENTIFIERS

• Keywords are words that are reserved for particular purposes.


• String, void, int, public, double, float, etc.
• Identifiers are names that programmers give to classes, methods, and
variables.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 15


Note that C# is a case-sensitive
language. Uppercase and lowercase
control the work of the computer on all

letters are not considered the same.


levels

• For example, Console is different


from console.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 16


COMMENTS
1. Single Line Comments – preface your comment within two
(2) forward slasher //

control the work of the computer on all


levels

2. Block Comments - enclose the comment in forwarding


slashes and asterisks, like this: “/* insert comment here */”

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 17


STATEMENTS AND BLOCKS
A statement is one or more lines of
code terminated by a semicolon. An
example of a singlecontrol
statement
the workis,
of the computer on all
levels

A block is one or more


statements bounded by an
opening and closing curly braces
that groups the statements as
one unit.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 18


C# LITERALS
The fixed values are called as Literal. Literal is a value that is
used by the variables.
control the work of the computer on all
levels

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 19


METHODS
1.WriteLine() and Write() – these are methods used to
print messages onto the screen.
• It has a pair of parentheses ()
control the work of the computer on all
levels

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 20


ESCAPE SEQUENCES

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 21


CHALLENGE 1: ESCAPE SEQUENCES
Write a program that output the following:

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 22


NAMING RULES AND
STYLES

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 23


NAMING RULES AND STYLES
• An identifier cannot be a C# reserve word.
• An identifier must begin with an alphabetic letter, underscore (_).
• Whitespace cannot be used in a valid identifier.
• An identifier must not be longer than 65,535 characters.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 24


NAMING RULES AND STYLES
• Use lowercase letter for the first character of variables
• Use uppercase letter for the first character of class and Method
names
• Use meaningful names
• Compound words or short phrases are fine but use uppercase letter
for the first character of the words after the first.
• Use verbs for methods’ names.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 25


EXAMPLE OF NAMING RULES AND
STYLES GATHERING

• Variables: height, speed, filename, tempInCelcius, incomingMsg,


textToShow
• Constant: SOUND_SPEED, PI, KM_PER_MILE
• Class names: Account, Person, Student
• Method names: Sum(), AddEvenNumber(),
InsertPersonalInformation()

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 26


STATEMENTS AND
EXPRESSIONS

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 27


EXPRESSION
Is a value, a variable, a method, or one of their combinations
that can be evaluated to a value.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 28


STATEMENT
Is any complete sentence that causes some action to occur

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 29


08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 30
ARITHMETIC
• Draw a flowchart diagram that will calculate the sum and product of
ten numbers. Find the difference of the first and last number. After
that, calculate the its average.

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 31


ANSWER
Start

Enter ten
numbers

Add 10 Nos
Subtract the 1st and Last No
Calculate the average

Sum
End Product
Average

08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 32

You might also like