ASM 1 Programing
ASM 1 Programing
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of
plagiarism. I understand that making a false declaration is a form of malpractice.
Grading grid
P1 P2 M1 D1
1
❒ Summative Feedback: ❒ Resubmission Feedback:
Lecturer Signature:
2
Table of Contents
Introduction.........................................................................................................................................5
I. Content.....................................................................................................................................5
1. Define basic algorithms to carry out an operation and outline the process of programming an
application.........................................................................................................................................5
a. Problem Definition................................................................................................................7
b. Design....................................................................................................................................7
c. Coding...................................................................................................................................7
d. Debugging:............................................................................................................................8
e. Testing:.......................................................................................................................................8
f. Documentation:.....................................................................................................................8
g. Maintenance:.........................................................................................................................8
a. Tasks in defining a problem:..................................................................................................8
c. Specifying the processing requirements:................................................................................9
II. Determine the steps taken from writing code to execution.................................................10
1. Pseudo code concept:...............................................................................................................10
a. Running flow (execution sequence) of the pseudocode:......................................................10
b. Some common keywords when representing pseudocode:..................................................11
2. Creating a new app:.................................................................................................................11
3. The source code:......................................................................................................................12
4. Using Directive:.......................................................................................................................12
5. Namespace:..............................................................................................................................12
6. Class declaration:.....................................................................................................................13
7. C# Method and Statements:.....................................................................................................13
8. Statements/comments:.............................................................................................................13
9. Multiple Line Statement:.........................................................................................................13
10. Formatting Text:..................................................................................................................14
11. Displaying Output:...............................................................................................................14
12. User Input:...........................................................................................................................15
13. User Input:...........................................................................................................................15
14. Read the input:.....................................................................................................................16
III. Inconclusion...........................................................................................................................16
IV. Reference List........................................................................................................................17
3
Introduction
A computer program consists of code that is executed on a computer to perform particular
tasks. This code is written by programmers. Programming is the process of giving
machines a set of instructions that describe how a program should be carried out.
Programmers will spend their whole careers learning a variety of programming languages
and tools so they can effectively build computer programs. Programmers will start by
using a code editor or IDE to write what is called source code. This is a collection of code
written in a programming language that other programmers can read. Source code needs
to be converted into machine language so machines can understand the instructions and
execute the program. This process of converting source code into machine language is
known as compiling. Examples of compiled programming languages would be C and C+
+. There are other languages that do not use compilers. Instead, these languages will use
an interpreter that will read and execute the code. Examples of interpreted programming
languages would be JavaScript and PHP. Once the code is executed, then the computer
program can run. The different types of computer programs include Word processors,
Database systems, video games, and websites. These computer programs allow us to
interactive with different software devices and services like phones, websites, and the
computers themselves.
I. Content
1. Define basic algorithms to carry out an operation and outline the process of
programming an application
2. Algorithm:
An algorithm is the step-by-step unambiguous instructions to solve a given problem.
In the traditional study of algorithms, there are two main criteria for judging the merits of
algorithms: correctness (does the algorithm give solution to the problem in a finite
number of steps?) and efficiency (how much resources (in terms of memory and time)
does it take to execute.
Example of an algorithm:
4
3. Computers and Algorithms:
To make a computer do anything, we have to write a computer
program.
To write a computer program, we have to tell the computer, step by
step, what we want it to do.
The computer then "executes" the program, following each step
mechanically, to accomplish the desired goal.
Data structure + algorithms = program.
When we are telling the computer what to do, we also get to choosehow it's going to do it.
That's where computer Algorithms come in to picture.
The algorithm is the basic technique used to get the job/work done.
When we say that algorithms are ubiquitous, we mean... Algorithms are found
everywhere. Algorithms can be used to solve many different types of problems.
Algorithms are a daily occurrence.
4. Algorithms Characteristics:
Finiteness: An algorithm must always terminate after a finite number of steps.
Definiteness: Each step of an algorithm must be precisely defined; the actions to be
carried out must be rigorously and unambiguously specified for each case.
Input: An algorithm has zero or more inputs
Output: An algorithm has one or more outputs
Effectiveness: the algorithms is based on the available resources. It should be effective,
exact and suitable for programs.
5
Language Independent: The Algorithm designed must be language-independent. It has to
be general resources. We can apply to all programming languages.
5. Steps in Program Development
a. Problem Definition
The first step in the process of program development is the thorough understanding and
identification of the problem for which is the program or software is to be developed.
In this step the problem has to be defined formally.
All the factors like Input/output, processing requirement, memory requirements, error
handling, interfacing with other programs have to be taken into consideration in this
stage.
b. Design
The next stage is the program design. The software developer makes use of tools like
algorithms and flowcharts to develop the design of the program.
Algorithm
Flowchart
c. Coding
Once the design process is complete, the actual computer program is written, i.e. the
instructions are written in a computer language.
Coding is generally a very small part of the entire program development process and also
a less time consuming activity in reality.
In this process all the syntax errors i.e. errors related to spelling, missing commas,
undefined labels etc. are eliminated.
For effective coding some of the guide lines which are applied are :
o Use of meaningful names and labels of variables,
o Simple and clear expressions,
o Modularity with emphasis on making modules generalized,
o Making use of comments and indenting the code properly,
o Avoiding jumps in the program to transfer control.
6
d. Debugging:
At this stage the errors in the programs are detected and corrected.
This stage of program development is an important process. Debugging is also known as
program validation.
Some common errors which might occur in the programs include:
o Un initialization of variables.
o Reversing of order of operands.
o Confusion of numbers and characters.
o Inverting of conditions eg jumping on zero instead of on not zero.:
e. Testing:
7
Figure 3:
b. Specifying the input requirements:
The input specification is obtained by answering following questions
What specific values will be provided as input to the program?
What format will the values be?
For each input item, what is the valid range of values that it may assume?
What restrictions are placed on the use of these values?
8
adherence to best practices. Seek feedback from others to gain insights and make
necessary adjustments.
Document and deploy: Document the code, including comments, explanations, and
instructions for future reference or collaboration. Prepare the application for deployment
by packaging it appropriately for the target platform or environment.
Maintain and update: Regularly maintain and update the application based on user
feedback, bug reports, or changing requirements. Continuously monitor for performance
issues, security vulnerabilities, or compatibility problems.
9
Similar to END/STOP/KETTHUC, and this pair of keywords often comes together
because in programming, where there is a beginning, there must be an end.
b. Some common keywords when representing pseudocode:
BEGIN/START => Start the program
END/STOP => End the program
INPUT => Requires user input and saves to memory (interacts with keyboard)
DISPLAY/WRITE => Print to screen
IF/ELSE => If/then used to branch the flow (sequentially execute the program based on
a calculated condition)
BEGIN LOOP/END LOOP => start and end of the loop (a concept in programming that
will be mentioned later in the article)
Basic example of pseudocode with a problem of calculating the sum of two numbers
entered by the user:
BEGIN
INPUT A
INPUT B
C=A+B
DISPLAY C
END
The above pseudocode asks the computer to execute the following tasks sequentially:
10
Figure 4:
Figure 5:
4. Using Directive:
From line 1 to 5, we have a few statements that start with the word using. These
statements are known as directives. They tell the compiler that our program uses a
certain namespace
For instance, the first line
using System;
tells the compiler that our program uses the System namespace.
5. Namespace:
11
A namespace is simply a grouping of related code elements. These elements include
classes, interfaces, enums and structs etc
C# comes with a large amount of pre-written code that are organised into different
namespaces.
The System namespace contains code for methods that allow us to interact with our
users. We use two of these methods in our program
- the WriteLine() and Read() methods.
6. Class declaration:
Every app consists of at least one class declaration that defined by the programmer
• user-defined class
• E.g., public class Welcome1
Class Name convention (upper camel casing)
• Begin with a capital letter
• Capitalize the first letter of each word included
• Contains letters, digits, and underscore
• Doesn’t start with digit, doesn’t contain spaces
C# is case sensitive
• So be careful because Myname is different from MyName.
7. C# Method and Statements:
Main method
• public static void Main(string[] args)
• It’s the starting point of every app
Statements
• Statements end with a semicolon (;)
8. Statements/comments:
Statement is instruction that programmer tells computer to do
• Every C# statement is terminated with semicolon ‘;’
Comment is explanation / guide that programmer explain to reader some block of
code and comments will not be executed
• Comment a single line with //
• Comment a block with /*..........*/
12
Figure 6:
13
Figure 7:
11. Displaying Output:
Most applications require some input from the user and give output as a result. To
display text to the console window you use the Console. Write or Console.WriteLine
methods.
The difference between these two is that Console.WriteLine is followed by a line
terminator, which moves the cursor to the next line after the text output.
The program below will display Hello World! to the console window:
You can also prompt the user to enter data and then use the Console.ReadLine method
to assign the input to a string variable. The following example asks the user for a
name and then displays a message that includes the input:
Figure 8:
14
14. Read the input:
For standard input we use Console.ReadLine()
• String s = Console.ReadLine();
• int n = Convert.ToInt32(Console.ReadLine());
Possible erroneous input
• User can input a string which is not an integer
• In this case an Exception is raised
• We will learn about handling exception later.
III. Inconclusion
15
IV. Reference List
Karumanchi, N. (2011). Data Structures and Algorithms Made Easy: Data Structure and
Algorithmic Puzzles.
Nagel, C. (2018). Professional C# 7 and . NET Core 2. 0. Wiley & Sons, Incorporated, John.
Stages of program development process (no date) Stages of program development process
(Program development steps) || CseWorld Online. Available at:
https://www.cseworldonline.com/articles/stages-of-program-development-process.php
(Accessed: 06 October 2023).
16
Flowchart
17
Console.Write("Tên khách hàng: ");
string tenKhachHang = Console.ReadLine();
Console.WriteLine("Nhập loại khách hàng: ");
string loaiKhachHang = Console.ReadLine();
Console.WriteLine("Nhập số người: ");
int soNguoi = int.Parse(Console.ReadLine());
Console.WriteLine("Nhập số mét khối: ");
int soMetKhoi = int.Parse(Console.ReadLine());
Console.Write("Chỉ số đồng hồ nước tháng trước: ");
int chiSoTruoc = int.Parse(Console.ReadLine());
Console.Write("Chỉ số đồng hồ nước tháng này: ");
int chiSoNay = int.Parse(Console.ReadLine());
int luongTieuThu = chiSoNay - chiSoTruoc;
Console.WriteLine("\nThông tin khách hàng:");
Console.WriteLine("Tên khách hàng: " + tenKhachHang);
Console.WriteLine("Chỉ số đồng hồ nước tháng trước: " + chiSoTruoc);
Console.WriteLine("Chỉ số đồng hồ nước tháng này: " + chiSoNay);
Console.WriteLine("Lượng tiêu thụ: " + luongTieuThu);
18