ASM1
ASM1
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 P3 M1 M2 D1
1
2
2
3
Issue Date
Submission Date
IV Name & Date
3
4
Table of Contents
1. INTRODUCTION………………………………………………………………………..5
2. ANALYSIS………………………………………………………………………………..7
2.1. List data types, data structures needed in the problem
.…………………………………………………………………………………………….8
2.2. Conditional Statements………………………………………………………………9
2.2.1 If statement………………………………………………………………………...9
2.2.2 If else statement……………………………………………………………………10
2.3. Loop statements……………………………………………………………………....10
2.3.1 While loop…………………………………………………………………………11
2.3.2 For loop……………………………………………………………………………12
3. DESIGN…………………………………………………………………………………...13
3.1. WBS………………………………………………………………………………….13
3.3. Flowchart…………………………………………………………………………….16
4
5
ASSIGNMENT 1 ANSWERS
1. Introduction
1.1
Procedural programming is derived from imperative programming. Its concept is based on
procedure calls. Procedures are nothing but a series of computational steps to be carried out. In
Procedural programming, the execution of the instructions takes place step by step. When you
use Procedural language, you give instructions directly to your computer and tell it how to
reach its goal through processes.
Top-down design: Problems are broken down into smaller, more manageable
subproblems, and each subproblem is solved using a separate procedure. This approach is
often described as "divide and conquer." (Brooks, 1995)
Sequential execution: Procedures are called and executed in a specific order, one after the other.
This makes it easier to understand the flow of control within a program.
Data and procedures as separate entities: Data is stored in variables, and procedures
operate on this data. This separation promotes modularity and makes code easier to maintain.
Global data: While not always ideal, procedural languages often allow data to be declared globally,
accessible by any procedure within the program. (Sebesta, 2012)
Emphasis on functions and procedures: The program's logic is encapsulated within these
reusable units, promoting code reusability and maintainability.
5
6
Predefined control structures: Procedural languages provide standard control structures like loops
(for, while) and conditionals (if-else) to govern the flow of execution.
This structured approach to code organization makes procedural programming a suitable choice for
solving problems that can be broken down into a series of well-defined steps. However, as problems
become more complex, the global data and sequential nature of procedural programming can lead to
challenges in managing code dependencies and maintaining large codebases
6
7
The student information and grade management problem is well-suited to procedural programming for the
following reasons:
1. Clear Sequential Nature: The problem requires sequential steps, from variable declaration,
grade input, to searching and displaying the highest/lowest scores. Procedural programming,
with its functions and sequential statements, aligns well with this requirement.
2. Focus on Data Processing: The core of the problem is manipulating grade data. Procedural
programming, with its use of variables and arrays for data storage and processing, is a natural
fit.
3. Simplicity and Efficiency: For a problem that isn't overly complex, procedural
programming leads to code that is easy to read, maintain, and efficient.
4. Iteration: The problem requires the ability to iterate over multiple students to input their grades.
Procedural programming's for or while loops handle this requirement directly.
5. No Need for High Abstraction: The problem doesn't necessitate the level of abstraction and
data encapsulation found in object-oriented programming. Procedural programming is
sufficient to solve the problem simply and effectively.
7
8
2. ANALYSIS
Int: An integer is a numeric literal (associated with numbers) without any fractional or
exponential part
Float: A floating-point literal is a numeric literal that has either a fractional form or an
exponent form.
Char: A character literal is created by enclosing a single character inside single quotation marks.
Array:
Linear data structures in C, such as arrays, store elements in adjacent memory locations, allowing for
quick access using an index. These structures are designed to hold elements of the same data type, and you
can declare them with the syntax "Datatype varname [size];". You can also declare and initialize an array
at the same time.
8
9
2.2.1 If statement
If statements are logical blocks used within programming. They’re conditional statements that tell a
computer what to do with certain information. In other words, they let a program make ‘decisions’
whileit’s running.
9
10
The if-else statement is valuable because it introduces decision-making into our code. It lets our
programs adapt and respond differently based on varying circumstances or user input. For example,
we could use it to:
10
11
11
12
variable which allows the body of the loop to know the exact sequencing of each iteration
12
13
3. Design
3.1 WBS
Explain:
Step 1: Enter ID & grades: This task involves inputting the student IDs and their corresponding grades into
the program.
Step 2: Find highest grades: This task identifies the students with the highest grades among all the entered
data.
Step 3:Find lowest grades: This task identifies the students with the lowest grades among all the entered data.
Step 4 Print all ID & grades: This task displays a list of all the student IDs and their corresponding grades.
Step 5 End: This final task indicates the termination of the program.
13
14
14
15
Explain
Step 1:Select options in the menu: The teacher can choose from a variety of options in the system's menu.
Step 2:Input student information: The teacher can enter information about students, such as their names, IDs, and
grades.
Step 3:Print ID, Grade: The system can print out a list of students, including their IDs and grades.
Step 4: Print highest grade: The system can identify and print the highest grade among all students.
Step 5: Print lowest grade: The system can identify and print the lowest grade among all students.
Step 6:Quit program: The teacher can exit the program.
15
16
3.3 Flowchart
correctly, the program will show all the information and run the for loop, but if you enter the
wrong Id, it will not show all information and will return to the original selection.
16
17
correctly, the program will show all the information and run the for loop, but if you enter the
wrong Id, it will not show all information and will return to the original selection.
17
18
18
19
This flowchart will use max to find the student's highest score, use float to assign the score if
max is less than student's score then that score will become max and the program will run
19
20
This flowchart will use min to find the student's lowest score, use float to assign the score if min is
greater than student's score then that score will become min and the program will run.
20
21
4 EVALUATION
Quite simply, having your code run will be a prerequisite. If you write code that often suffers from
basic errors such as: compilation errors, memory overflow, over- accessing the index of the array
... then of course your code is "fake". As a software developer, I need to know exactly what you
want, what the data storage structures are and how the logic code handles the data, etc.
Once you understand what you want to do, it's time to write code in a programming language. I
will then use a programming language to express what I want, ranging from organizing data to
processing logic. “Clean code” is a must, in addition, I also need to understand and control the
interaction between your code and other components in the system (from language, platform,
architecture, ...).
-Second: The code must solve the problem the user asked for. we are the ones who know how to
analyze and clarify them.
-Third: New code must be compatible with existing ones and easily extensible
Assuming I need to add a new feature to the product, I integrate additional source code into what is
already there, I need to make sure that it does not affect what is already running properly in the
program. Don't make your code-based mess, lose consistency and hard to control. Pay attention to
design and programming principles, such as SOLID.
Besides, pay attention to the possibility of reusing source code or extending new features later.
Don't let when implementing a similar feature in the future, I have to clone the source code
somewhere else and edit just a few small places. Designing modules and applying the principle of
“loose coupling” can help in these situations.
Fourth: Not only writing code for computers, code is also for humans.
Remember, software development doesn't just stop with writing the initial code, it also needs to be
maintained and continued to develop later. Many other people are involved in this cycle, not just
you. Leave lines of code that people who come after you can easily understand. Like any other
thing or phenomenon, it is very difficult to properly and fully appreciate it. However, with the
motto of finding "easy to quantify" ways, the above criteria will more or less help you visualize
and evaluate the code you do, at least help you know what you will have to do.
#Difficulties
It's not too difficult to use, but you need to learn carefully before writing to avoid mistake and have to fix
21
22
Think fast code is better than nice and readable. Write code
without a plan.
exception handling.
22
23
Citations:
References: GeeksforGeeks. “Decision Making in C (if , if..else, Nested if, if-else- if ),” May
19, 2017. https://www.geeksforgeeks.org/decision-making-c-cpp. (Access: 22/06/2024)
GeeksforGeeks. “While Loop in C,” September 25, 2022. https://www.geeksforgeeks.org/c-while-
loop/. (Access: 22/06/2024)
EDUCBA. “If Else Statement in C++ | How If Else Statement Works in C++? (Examples),” January
18, 2020. https://www.educba.com/if-else-statement-in-c-plus- plus/. (Access: 22/06/2024)
“What Is Procedural Programming - Naukri Code 360.” Accessed June 21, 2024.
https://www.naukri.com/code360/library/procedural-programming-everything-you- need-to-know.
(Access: 22/06/2024)
23
24
24
25
25
26
26
27
27