[C#] Data Type and Sequence - IPO Charts
Categories: CS
Tags: IPO Charts C#
📋 This is my note-taking from what I learned in the class “Programming 1 - COMP 100-002”
Objectives
- Learn about programming
- Learn about algorithms
- Identify the output, input, and processing items from a problem specification
- Explore programming concepts
Definition of Computer Programming
What is Computer Programming?
Computer programming is not only about language syntax or using an IDE, it is more about solving problems.
Problem Solving Process
Step 1. Analyze the problem
- Problem
Justin Trudeau has been working with Quality Cleaners for six years. Last year, he received a promotion with an increase of 3.5%, which brought his current weekly pay to $300. Justin is scheduled to receive another increase of 3% next week. He wants you to write a program that will display the amount of his new weekly pay.
- Start to analyze by using IPO(Input Processing Output) Chart
- Input: What is given
- Processing: Stores intermediate values
- Output: What is required
-
IPO Chart of the problem above
Input Processing Output Current weekly pay Processing items: New weekly pay Raise rate Algorithm:
-
Ignore the information that is not important in this problem
Justin Trudeau has been working with Quality Cleaners for six years. Last year, he received a promotion with an increase of 3.5%, which broughthis current weekly pay to $300. Justin is scheduled to receive another increase of 3% next week. He wants you to write a program that will display the amount of his new weekly pay. -
Another examples of problem
Example 1 of Problem
Doug Ford also works at Quality Cleaners, he earns $14 per hour. Last week, Doug worked 35 hours. He wants you to write a program that will display the amount of his net weekly pay.
→ This problem specification does not contain enough information to be solvedExample 2 of Problem
Andrea Horwath, who works at Quality Cleaners, needs a program that will display the cost of painting a room.
→ The input in this problem specification is not explicitly stated
Step 2. Planning the Algorithm
- The definition of Algorithm: A finite series of steps to complete a task that may be specified by means of:
- English instructions
- Pseudocode
- Flowchart
- Steps of algorithm must be precise and short → ex) Food recipe
-
How we can expand on the previous IPO Chart of the problem above
Input Processing Output currentWeeklyPay Processing Items: payIncrease newWeeklyPay rateIncrease Algorithm: 1. Prompt for currentWeeklyPay 2. Accept currentlWeeklyPay 3. Prompt for rateIncrease 4. Accept rateIncrease 5. Calculate the payIncrease by multiplying currentWeeklyPay by rateIncrease 6. Calculate the newWeeklyPay by adding payIncrease and currentWeeklyPay 7. Display newWeeklyPay
Step 3. Desk-checking the Algorithm
-
To check if our algorithm is working properly, Use a desk-check table
Desk-checking tableWeekly pay (Input) Raise rate (Input) Pay increase (Processing) New weekly pay (processing) $300.00 0.03 $9.00 $309.00
Step 4. Code the Algorithm in a Program
- Transform the IPO chart information into a computer program
Algorithm conversion (Here, our algorithm into c# statements)
- Input:
- currentWeeklyPay
- rateIncrease
double currentWeeklyPay; double rateIncrease;
- Output:
- newWeeklyPay
double newWeeklyPay;
- newWeeklyPay
- Processing:
- payIncrease
double payIncrease;
- payIncrease
- Algorithm
- Enter the current weekly pay
- Accept the current weekly pay
- Enter the rate increase
- Accept the rate increase
Console.WriteLine("Enter the current pay: "); currentlWeeklyPay = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Enter the rate increase "); rateIncrease = Convert.ToDouble(Console.ReadLine());
- Calculate the payIncrease by multiplying currentWeeklyPay by rateIncrease
payIncrease = currentWeeklyPay * rateIncrease;
- Calculate the newWeeklyPay by adding payIncrease and currentWeeklyPay
newWeeklyPay = payIncrease + currentWeeklyPay;
- Display newWeeklyPay
Console.WriteLine("New pay: $" + newWeeklyPay);
Step 5. Desk-checking Program
-
To check if our program is working properly, Use a desk-check table
Desk-checking tableWeekly pay (Input) Raise rate (Input) New weekly pay (Output) $300.00 0.03 $309.00
Step 6. Evaluate and Modify
Evaluation and Modification might need for the following situations:
- Enhancements request from users
- The problem specifications might change because of the following:
- Company policies
- Government laws
3 Column IPO Chart & 2 Column IPO Chart
Guidelines for getting the C# statements
-
Comments have three formats:
- Single line: //
- Multiple line: /**/
- Documentation: ///
-
Declaration statement must start with a data type followed by the variable and terminated with a semi colon
-
Screen output is done via:
- Console.Write and Console.WriteLine
-
Keyboard input is done via:
- Console.ReadLine
-
To obtain other type, use the Convert class
- Convert.ToInt32, Convert.ToDouble, Convert.ToChar, Convert.ToBoolean
-
All statements must be terminated by a semi colon
Additional Information
C# Data Types - int OR double?
- C# Data Types
- Should I Use “int” or “double”?
- C# Decimal vs Double and Other Tips About Number Types
- Statements (C# Programming Guide)
- C# - Data Types
Leave a comment