You are on page 1of 9

HIGH SCHOOL DEPARTMENT

Technology and Livelihood Education Area


MODULES # 1-8 in ICT 9

" No portion of this module may be copied or reproduced in books,


pamphlets, outlines, or notes- whether printed, mimeographed, typewritten,
photocopied, or in any form-for distribution or sale, without the written
permission of Colegio San Agustin-Makati. The infringer shall be
prosecuted in compliance with copyright, trademark patent, and other
pertinent laws."

TITLE Payroll Program

LEARNING COMPETENCIES:
1. Differentiate variable from data type; and
2. Apply variable and data type in creating program.
3. Apply arithmetic operators
4. Apply comparison operators
5. Apply the conditional statements

LEARNING TARGET:

 I can apply the use of variables, data types, and arithmetic operators in creating programs.

MATERIALS:
 internet
 email

INSTRUCTIONS:
1. Study the information below:

Relational operators are used to check the relationship between two operands. If the relationship is true the

result will be true, otherwise it will result in false.

Relational operators are used in decision making and loops.


C# Relational Operators

Operato
Operator Name Example
r

== Equal to 6 == 4 evaluates to false

> Greater than 3 > -1 evaluates to true

< Less than 5 < 3 evaluates to false

>= Greater than or equal to 4 >= 4 evaluates to true

<= Less than or equal to 5 <= 3 evaluates to false

!= Not equal to 10 != 2 evaluates to true

Conditional Statement – it performs different actions for different decisions.

C# has the following conditional statements:

 Use if to specify a block of code to be executed, if a specified condition is true


 Use else to specify a block of code to be executed, if the same condition is false
 Use else if to specify a new condition to test, if the first condition is false
 Use switch to specify many alternative blocks of code to be executed

The if Statement
Use the if statement to specify a block of C# code to be executed if a condition is True.
Syntax
if (condition)
{
// block of code to be executed if the condition is True
}

Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error.
In the example below, we test two values to find out if 20 is greater than 18. If the condition is True, print
some text:
Example
if (20 > 18)
{
Console.WriteLine("20 is greater than 18");
}
We can also test variables:
Example
int x = 20;
int y = 18;
if (x > y)
{
Console.WriteLine("x is greater than y");
}

Example explained
In the example above we use two variables, x and y, to test whether x is greater than y (using the > operator).
As x is 20, and y is 18, and we know that 20 is greater than 18, we print to the screen that "x is greater than y".

The else Statement


Use the else statement to specify a block of code to be executed if the condition is False.
Syntax
if (condition)
{
// block of code to be executed if the condition is True
}
else
{
// block of code to be executed if the condition is False
}

Example
int time = 20;
if (time < 18)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
}
// Outputs "Good evening."

Example explained
In the example above, time (20) is greater than 18, so the condition is False. Because of this, we move on to
the else condition and print to the screen "Good evening". If the time was less than 18, the program would
print "Good day".

The else if Statement


Use the else if statement to specify a new condition if the first condition is False.
Syntax
if (condition1)
{
// block of code to be executed if condition1 is True
}
else if (condition2)
{
// block of code to be executed if the condition1 is false and condition2 is True
}
else
{
// block of code to be executed if the condition1 is false and condition2 is False
}
Example
int time = 22;
if (time < 10)
{
Console.WriteLine("Good morning.");
}
else if (time < 20)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
}
// Outputs "Good evening."

2. Open any browser and type this address https://dotnetfiddle.net/. Press enter to load the page.
TRY THIS:
Create a program that checks the qualification of the age below:
Age Condition Remark
19 and above You are legally qualified to vote!
18 You are exactly 18. You are qualified to vote!
0 to 17 I'm sorry, you are below 18. You cannot vote yet.
Less than 0 Invalid Age

Guide Sample 1:

SYNTAX CODE:

using System;

namespace act_2_age_azarcon
{
class Program
{
public static void Main(string[] args)
{
double age;
Console.WriteLine("Programmed by: Adina D. Azarcon, 9G");
Console.WriteLine("");

Console.WriteLine("Please enter your age: ");


age=Convert.ToDouble(Console.ReadLine());

if(age >= 19){


Console.WriteLine("You are legally qualified to vote!");
}

else if(age==18){
Console.WriteLine("You are exactly 18. You are qualified to vote!");
}

else if(age>=17){
Console.WriteLine("I'm sorry, you are below 18. You cannot vote yet.");
}

else if(age<=0){
Console.WriteLine("This age is INVALID!");
}

Console.ReadKey(true);
}
}
}

OUTPUT
Guide Example 2:
CONDITIONS

using System;

namespace Act3_AgeGroup_LeeH
{
class Program
{
public static void Main(string[] args)
{

double age;
Console.WriteLine("Programmed by: Name and Section");
Console.WriteLine("");

Console.WriteLine("Enter your age");


age=Convert.ToDouble(Console.ReadLine());

if(age>=80) {
Console.WriteLine("Your generation is pre depression");
Console.WriteLine("Your date of birth is before 1930");
}

else if(age>=64) {
Console.WriteLine("Your generation is depression");
Console.WriteLine("Your born between 1930-1945");
}

else if(age>=45) {
Console.WriteLine("Your generation is baby boom");
Console.WriteLine("Your born between 1946-1964");
}

else if(age>=33) {
Console.WriteLine("Your generation is generation x");
Console.WriteLine("Your born between 1965-1976");
}

else if(age>=15) {
Console.WriteLine("Your generation is generation y");
Console.WriteLine("Your born between 1977-1994");
}

else if(age<15) {
Console.WriteLine("Your generation is generation z");
Console.WriteLine("Your born between after 1994");
}

Console.ReadKey(true);
}
}
}
OUTPUT:

DO THIS TASK NOW:


3. Read and do the GRASP below.
Instructions:
1. Create a c# file with a filename: TASK_Lastname and save inside a folder.
2. Use double data types for variables. (See sample output)
3. Prompt a question selecting the room type.
4. Prompt a question for number of days for stay.
5. Display customer’s information.
6. Create a condition for room type with corresponding amount
7. Prompt amount of payment.
8. Create a condition for sufficient and insufficient amount.
9. Save the changes you have made on your work.

Competencies:
Apply all the c# concepts in creating program.
Instructions:
See the sample output saved in the folder.
1. Create a new project with the filename: CN_LASTNAME.
Save the project inside the a folder.
2. Apply the necessary variables and data types declaration
and initialization.
double ______, ______;
Console.WriteLine("Programmed by: Name and Section");
Console.WriteLine("");

Console.WriteLine("___________");
_____=Convert.ToDouble(Console.ReadLine());

Console.WriteLine("___________");
_____=Convert.ToDouble(Console.ReadLine());

//start typing your conditional statements codes here.


3. Apply the arithmetic operators, comparison operators and
conditional statements based from sample output. Prompt a question selecting the room type. Prompt a question for
number of days for stay. Compute for the amount to pay.
4. Test your work.
5. SAVE the changes you have made on your file.
6. Check the rubrics saved in the folder.
===========Welcome to Manhattan Hotel============
Please choose your room type:
[5] : This room can accommodate 5 or more persons. It costs P10,000 per day
[4] : This room can accommodate 4 persons. It costs P5,000 per day
[3] : This room can accommodate 3 persons. It costs P4,000 per day
[2] : This room can accommodate 2 persons. It costs P2,000 per day
[1] : This room can accommodate 1 person. It costs P1,000 per day

Which room type would you like to choose?


5
How many days would you like to stay?
2
Your total price is: 20000
Sample Output:

Rubrics:
Category 10 9 8 7
Specifications The program works and meets The program works and The program produces The program is
all of the specifications. produces the correct correct results but does producing incorrect
results and displays not display them results.
them correctly. It also correctly.
meets most of the other
specifications.
Efficiency The code is extremely efficient The code is fairly The code is brute force The code is huge and
without sacrificing readability efficient without and unnecessarily long. appears to be patched
and understanding. sacrificing readability together.
and understanding.
Delivery The program was 80-99% of the program 60-79% of the program 59% and below was
delivered100% on time was delivered within a was delivered within a delivered within a given
given time given time time
4 3 2 1
Information Information is creatively written Information is well Information could be Information is poorly
and cleverly presented. written and interesting to better written and too written, inaccurate, or
read and is presented in much information is incomplete.
short sections. given in each section.
Creativity Was extremely clever and Was well done and Was clever at times; Minimal effort. Poor
presented with originality. interesting to the incorporated most of the layout/design. Did not
Excellent layout/design work audience; added a few attributes; used a limited incorporate required
incorporating all required original touches to variety of appropriate attributes, graphics, did
attributes, great variety of enhance the project; graphics. not resize pictures,
appropriate graphics that used a good variety of
enhanced the pages. appropriate graphics.
Work Ethics You worked very hard on your You worked hard on You worked on your You did not seriously
project and were always on your project but project but were off task work on your project,
task.  sometimes got off task  and needed to be you frequently were off
redirected by the task, and did not
teacher  refocus when
redirected by the
teacher 
Time Allotment Used time well during each Focused on getting the Needed numerous Did not use class time
class period. Focused on project done, but was reminders to get back to to focus on the project.
getting the project done. Did occasionally distracted work.
not distract others. Helped or distracted others.
others.
Following Able to follow all the Able to follow majority of
Instructions instructions correctly the instructions
Total: 50 points

You might also like