ModuleS 1-5 CE Computer Fundamentals Programming
ModuleS 1-5 CE Computer Fundamentals Programming
Computer Fundamentals
Programming
2nd Semester, SY 2018-2019
• Definition of Programming
• Purpose of Making Programs
• Programming Language
• Types of Programming Language
• Generations of Programming Language
• Examples of Programming Language
• Compiler
• Interpreter
• Choosing a programming Language
• How to make programs
Continuation…
4
• Flowchart
• Algorithm
• The C# programming Language
• What is C#?
• C# Operators
- (Mathematical, Assignment, Relational, Boolean)
• Looping
- (While, Do, For)
• Arrays
- (Single, Multi-dimensional Arrays)
• Textfiles
Course Requirements
5
• Quizzes
• Attendance
• Recitation
• Seatwork
• Written/Laboratory Midterm and Final
Examinations
• Laboratory Exercises
• Create a simple system using C# Programming
Language (Final Project)
Grading System:
Midterm & Final Exam – 50% Grade – 100%
Other components – 50%
6
Module 1: Introduction to
Computer Programming
What is a Program?
7
• Generic
• General
• does not necessarily always mean "program" or
"application" (e.g. a software "library" or "framework" is
not a "program" or "application", but are used to
facilitate the functional requirements of "programs" or
"applications").
Without programs, computers are useless!
Computer software, or simply
software, is a collection of data
or computer instructions that tell
the computer how to work. This
is in contrast to physical
hardware, from which the system
is built and actually performs the
work. Wikipedia
Why do programmers make computer
programs?
11
• To simplify task
• Web languages
• Software languages
• The different generations of languages
• Procedure oriented programming
• Object oriented programming
Types of Programming Language
17
Web Languages
• HTML
• XML
• JAVASCRIPT
• VBSCRIPT
• PHP
• ASP
• JAVA
Types of Programming Language
18
Software Languages
• C
• C++
• Visual Basic
• JAVA
• C#
Types of Programming Language
19
End of Module 1
Note: prepare for a quiz next meeting
29
30
n
31
Computer Fundamentals
Programming
Module 2 - Designing and Creating a
Program
• Cookbook
• Recipe Booklet
• Choreography
Example
of
Flowchart
Notations Used in Flowchart
46
Notation Meaning
: comparison
& logical and
Y yes
N no
EOF End of File
Relational Test Operators
47
Notation Meaning
> is greater than
< is less than
<= or =< is less than or equal to
>= or => is greater than or equal to
<> or >< is not equal to
= is equal to
Arithmetic Operators
48
Notations Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
() Grouping
** or ^ Exponentiation
Precedence of the Operators
49
1. Grouping ()
2. Exponentiation
3. Multiplication or division
4. Addition or subtraction
When operators are all of equal priority, the
computer evaluate the expression from left
to right.
50
When operators are of different priorities, the
computer performs those operations with higher
priorities first
51
Operations enclosed in parentheses will take place
before other operations. Note (if there are multiple
parentheses, the innermost parenthesis will be
52
evaluated first).
Write clearly the computation desired
53
Example #2.3
2L / 3G
Answer?
( 2 * L ) / (3 * G )
Problem 6 and 7
54
59
Problem 9 and 10
60
Age Charge
<16 7
>=16 and <65 10
>=65 5
Problem 12 and 13
62
End of Module 2
Note: prepare for a quiz next meeting; Submit all answer to Problems
provided, use the worksheet template provided.
65
Computer Fundamentals
Programming
Module 3 – The C# Programming
Language
• Namespace declaration
• A class
• Class methods
• Class attributes
• A Main method
• Statements & Expressions
• Comments
The C# Code
69
using System;
class HelloWorld
{
static void Main(string[]
args)
{
/* my first program in C#
*/
Console.WriteLine("Hello
World");
Console.ReadKey();
}
}
Line #1: using System;
70
72
/*
This program demonstrates
The basic syntax of C# programming
Language
*/
74
WriteLine is a
method of the
Console class
defined in the
System
namespace. This
statement causes
the message
"Hello, World!" to
be displayed on
the screen.
Line #8: Console.ReadKey();
75
• C# is case sensitive.
• Namespace declaration
• A class
• Class methods
• Class attributes
• A Main method
• Statements & Expressions
• Comments
Identifier
78
RULE #1:
NEVER EVER
USE THEM AS IDENTIFIERS!
C# Keywords
abstract as base bool break byte case
80 catch char checked class const continue decimal
default delegate do double else enum event
explicit extern false finally fixed float for
foreach goto if implicit in in (generic) int
interface internal is lock long namespace new
null object operator out out(generic) override params
private protected public randomly ref return sbyte
sealed short sizeof stackalloc static String struct
switch this throw true try typeof uint
ulong unchecked unsafe ushort using virtual void
volatile while
Contextual keywords
add alias ascending descending dynamic from get
global group Into join let order by partial (type)
partial (method) remove select set
Concept of Variables
81
Computer’s Memory
sAge
num1 fname
deptName mTime
Abc
abc123
bahaykubokahitmunti
student_name
sum
average
Valid or Invalid?
85
Number String
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
Arithmetic Operators
89
== Checks if the values of two operands are equal or not, (A == B) is not true.
if yes then condition becomes true.
!= Checks if the values of two operands are equal or not, (A != B) is true.
if values are not equal then condition becomes true.
> Checks if the value of left operand is greater than the (A > B) is not true.
value of right operand, if yes then condition becomes
true.
< Checks if the value of left operand is less than the (A < B) is true.
value of right operand, if yes then condition becomes
true.
>= Checks if the value of left operand is greater than or (A >= B) is not true.
equal to the value of right operand, if yes then
condition becomes true.
<= Checks if the value of left operand is less than or equal (A <= B) is true.
to the value of right operand, if yes then condition
becomes true.
Logical Operators
91
Operator Description Example
Console.WriteLine("The sum of " + Num1 + " and " + Num2 + " is: " +
Sum);
Console.ReadKey();
}
}
Sample Problem #17
Create a C# program that would get and display the quotient of two numbers given
94
by the user.
using System;
class my_app
{
static void Main(string[] args)
{
string Num1 = "";
string Num2 = "";
double Quotient = 0;
Console.WriteLine("The quotient of " + Num1 + " and " + Num2 + " is: " +
Quotient.ToString ("N2"));
Console.ReadKey();
}
}
95
End of Module 3
Note: prepare for a quiz next meeting; Submit all answer to Problems
provided, use the worksheet template provided.
96
Computer Fundamentals
Programming
Module 4 – Conditional Statements
• if statement
• if…else statement
• else if statement
• switch statement
if statement
99
Syntax:
if(boolean_expression)
{
/* statement(s) will
execute if the boolean
expression is true */
}
Sample Problem #1
using System;
class my_app
{
static void Main(string[] args)
{
string Age = "";
Syntax:
if(boolean_expression)
{
/* statement(s) will
execute if the boolean
expression is true */
}
else
{
/* statement(s) will
execute if the boolean
expression is false */
}
Sample Problem #2
Create a C# program that would display
“UNDER-AGE” if the age entered is below 18,
otherwise “OVER-AGE” if age above 18.
Solution to Problem #2
102
using System;
class my_app
{
static void Main(string[] args)
{
string Age = "";
Console.ReadKey();
}
}
nested if……
103
Sample Problem #3
Computer Fundamentals
Programming
Module 5 – C# Loops
• A loop statement
allows us to execute a
statement or a group
of statements
multiple times and
following is the
general form of a loop
statement in most of
the programming
languages
Loop Types and Description
108
A for loop is a
repetition control
structure that allows
you to efficiently
write a loop that
needs to execute a
specific number of
times.
C# - For Loop
111
• The init step is executed first, and only once. This step allows you
to declare and initialize any loop control variables. You are not
required to put a statement here, as long as a semicolon appears.
• After the body of the for loop executes, the flow of control jumps
back up to the increment statement. This statement allows you
to update any loop control variables. This statement can be left
blank, as long as a semicolon appears after the condition.