C#/C SHARP
• C#(C-Sharp) is a programming language developed by Microsoft
that runs on the .NET Framework.
• C# has roots from the C family, and the language is close to other
popular languages like C++ and Java.
3.
Programming Languages
• 3levels
• High level language – English like language
• Translators – convert the programmer/source codes into machine codes
• Compiler
• Interpreter
• Example: python, java, C#, c++, html, visual basic
• Middle level Language – combination of English terms and binary codes
• Translator – Assembler
• Example: Assembly Language
• Low level language – binary codes – are a combination of the digits 0 and 1.
• 10001100
• Directly read by the computer
• Binary language – 0 – false, off
• 1 – true, on
4.
USES
• Mobile applications
•Desktop applications
• Web applications
• Web services
• Web sites
• Games
• VR
• Database applications
• And much, much more!
5.
Definition of aProgram
• Programming is the creation of an ordered set of instructions to solve a
problem with a computer. The instructions sometimes referred to as codes
make up a computer program.
• Computer Program is a collection of instructions that performs a specific
task when executed by a computer designed by a computer programmer.
Programming needs a language called Programming Language to
communicate with computers.
6.
Steps in theProgramming Process
• Problem definition
• You need to understand the problem before you can expect to
get a correct solution to the problem. What information
(inputs), is given to you to use to solve the problem? What will
the solution (outputs) of the problem, look like? What
calculations (processes), will be used to change the input
information into the desired output?
7.
• Example:
• Problem:Write a program to input 2 integers and display their sum.
• Input/s: 2 integers
• Process: add 2 integers
• Output/s: Print sum
8.
Steps…
Algorithm design
• Breakthe problem into the steps of what must be done to
solve the problem. List what tasks need to be done to solve the
problem. An English outline is a good tool for doing the job.
Expand the outline into a complete solution. It should list all
the steps that need to be done, in the correct order they need
to be done in.
9.
Steps…
• Desktop testing
•In this step, you pretend to be a computer and execute the
steps in the algorithm. Be careful to follow the algorithm
exactly! Don't add steps, or leave out any steps. Don't
rearrange the steps. If you don't get the right answer to the
problem, then you have an error in the algorithm. Fix it and
try again until you get the right answer.
10.
Steps…
• Coding
• Oncethe algorithm, or complete outline works correctly, you
need to translate the algorithm into a computer language that
your computer understands.
11.
Steps…
• Testing anddebugging
• Now, enter the program into the computer, enter some test data, and have the
computer execute the program. If you get the correct answer to the problem,
the program works! Otherwise, look for errors in the program and try again.
• 2 types of error
• Syntax error – error on how you write the program – ex. Missing quotes, wrong spelling, no semi colon
• No output displayed
• Logical error – error on the logic of the program.
• It displays incorrect output
12.
Steps…
• Documentation (optional)
•You may want to write a user’s manual in order for users of your
program will know how to use it properly and step by step. Once
the program works correctly, you want make sure the
documentation is up to date and be ready to maintain the program.
Good programs get better during the life-time as people think of
better way to do things and additional tasks the program might do.
13.
Program Logic Formulation
•Logical reasoning – the use of logical thinking in order
to find results or draw conclusions
14.
Algorithm
• An algorithmis a logical sequence of steps for solving a problem
that can be translated into a computer program.
• Two ways of implementing an algorithm:
1. Pseudocode
2. Flowchart
15.
Flowcharts and Pseudocodes
•A pseudocode is an artificial and informal language that helps
programmers develop algorithms. It is usually a combination of
English words and some keywords of a programming language.
• A flowchart is a diagram that represents the sequence of
operations in a process. It is a graphic representation of an
algorithm.
16.
Problem: create analgorithm to compute the sum of two integers
• Input/s: first number, second number
• Process: add the two numbers
• Output: sum
Pseudocode:
1. Enter first number and second number
2. Compute the sum, sum = first number + second number
3. Print sum
17.
Start
int A=0, B=0,sum = 0
Enter “First Number”, A
Enter “Second Number”, B
sum = A+B
Print sum
end
Start
int b = 0, h = 0, Area = 0
Enter “base”, b
Enter “height”, h
Area = b * h / 2
Print Area
end
18.
Problem#2: Create analgorithm to compute
the area of a triangle
• Input/s: base, height
• Process: A = b*h/2
• Output: Area of the triangle
• Pseudocode:
• 1. Enter base and height
• 2. Compute the Area, Area = base * height/2
• 3. Print Area
Flowcharting Symbols
Decision. Abranching point; lines
representing different decisions
emerge from different points of the
diamond
Diamond
AGE>=18?
Y
N
PRINT “Qualified to
Vote”
PRINT “Not Qualified
to Vote”
Notations commonly usedin Flowcharting
Notation Meaning
+
-
*
/
**
( )
=
>
<
< >
> =
< =
Y
N
Addition
Subtraction
Multiplication
Division
Exponentiation
Grouping
Equal to
Greater than
Less than
Not Equal to
Greater than or
Equal to
Less than or Equal to
Yes
No
2+3 = 5
3-2
2*3
4/2
2**2
(2+3) * 2
X=Y
5>2
5<6
5<>6
6>=6
5<=7
28.
Rules of Precedence
•In other words, the precedence is:
• Parentheses (simplify inside 'em)
• Exponents.
• Multiplication and Division (from left to right)
• Addition and Subtraction (from left to right)
Variable
• a storagelocation capable of containing a certain type of data that
can be modified during program execution.
• These variables will represent certain values
• Example: num1,sum,ave,total, name, address
• Num1 = 5, name=“Joey”, address = “Tuguegarao”
32.
Rules of DrawingFlowcharts for
Algorithms
• All boxes of flowcharts are connected with arrows to show the logical
connection between them,
• Flowcharts will flow from top to bottom,
• All flowcharts start with a Start Box and end with a Terminal Box,
33.
Examples of Flowchartsfor Algorithms
• Example 1: Calculate the sum of two integers and display the average.
• Algorithm:
• Step 1: Input num1,
• Step 2: Read num2,
• Step 3: Calcuate the sum, sum = num1 + num2
• Step 4: Calculate average, ave = sum/2
• Step 5: Print sum, ave
Determine and OutputWhether Number N is Even or Odd
• Algorithm:
• Step 1: Read number N,
• Step 2: Set remainder as N modulo 2,
• Step 3: If remainder is equal to 0 then number N is even, else number N is
odd,
• Step 4: Print output.
37.
Determine Whether aTemperature is Below or Above the
Freezing Point
• Algorithm:
• Step 1: Input temperature,
• Step 2: If it is less than 32, then print "below freezing point", otherwise print
"above freezing point"
39.
Determine Whether AStudent Passed the Exam or Not:
• Algorithm:
• Step 1: Input grades of 4 courses M1, M2, M3 and M4,
• Step 2: Calculate the average grade with formula
"Grade=(M1+M2+M3+M4)/4"
• Step 3: If the average grade is less than 60, print "FAIL", else print "PASS".
41.
Your Turn
• Determineif a Number is positive or negative.
• Create the algorithm
• Draw the flowchart