Prog102 - Assignment 1 frontsheet 2 (3)
Prog102 - Assignment 1 frontsheet 2 (3)
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
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 ..........................................10
2.2.1 If statement..........................................11
2.2.2 If else statement..........................................12
2.3. Loop statements..........................................12
2.3.1 While loop..........................................13
2.3.2 For loop..........................................13
3. DESIGN ..........................................14
4. EVALUATION..........................................20
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.
Global data: While not always ideal, procedural languages often allow data to be
declared globally, accessible by any procedure within the program. (Sebesta, 2012)
5
6
Citations:
6
7
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
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
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 used to perform two operations for a single condition. The if-else
statement is an extension to the if statement using which, we can perform two different
operations, i.e., one is for the correctness of that condition, and the other is for the
incorrectness of the condition. Here, we must notice that if and else block cannot be
executed simiulteneously. Using if-else statement is always preferable since it always
invokes an otherwise case with every if condition.
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
• Control program flow: Decide which parts of the code to execute based on
conditions.
• Error handling: Take different actions in case of errors.
• Make choices in games: Determine the outcome of actions based on game rules.
The do while loop is a post tested loop. Using the do-while loop, we can repeat the
execution of several parts of the statements. The do-while loop is mainly used in the case
where we need to execute the loop at least once. The do-while loop is mostly used in
menu-driven programs where the termination condition depends upon the end user
11
12
The for loop is distinguished from other looping statements through an explicit loop
counter or loop
variable which allows the body of the loop to know the exact sequencing of each iteration
12
13
3. Design
3.1 WBS
13
14
14
15
15
16
3.3 Flowchart
First flowchart to enter the student id, still follow the initial steps, but if you enter the Id
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
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
18
19
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.
19
20
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.
implementing and writing those lines of code. It's easy to say, but this can be an
extremely difficult task.
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 bugs many times
No exception handling.
21
22
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)
22