Professional Documents
Culture Documents
PROG102 - GCS200708 - NguyenXuanNam - Assignment 1
PROG102 - GCS200708 - NguyenXuanNam - Assignment 1
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.
Student’s signature
Grading grid
P1 P2 P3 M1 M2 D1
❒ Summative Feedback: ❒ Resubmission Feedback:
Assignment Brief
Scenario:
A math teacher wants to manage grades of a class. He asks you to help him to write a small application to do
that. He needs to enter student IDs, student’s grades and store these information into 2 separate arrays
(integer array for IDs and float array for grades). Then he needs to print all student IDs together with their
grades. Finally, he needs to know which student has highest grade and lowest grade. Your program should be
menu based with the options above. When an option is done, the program should go back to the main menu so
he can choose another option. There should be an option to quit program.
Task 1
To prove your programming ability to be appointed to this small project, please prepare an illustrated guide on
programming in general and a particular emphasis on procedural programming. Here you will need to include
introduction to computer programming languages and discuss key features of procedural programming.
Task 2
Your next task is to do the analysis for the scenario mentioned above by doing the following subtasks
Identify the variables and data types required in the program.
Identify and describe 2 different selection structures, including the condition(s) to check; state why
they are needed and where they can be used in the context of the scenario.
Identify and describe any iteration constructs.
Split the program into functions (sub-functions) and draw a hierarchy diagram to illustrate the
structure of your program.
Task 3
You need to use a drawing tool to draw design diagram for your program, includes:
A use case diagram for actions required
Flow chart diagrams for: menu operation, printing IDs and grades, finding max grade and finding min
grade.
Review / evaluate your design, state clearly pros vs cons and which needs to improve, using
characteristics of procedural programming as bases to discuss.
Write a report for 3 tasks above and submit the report to CMS in PDF format.
Submission Format
The submission is in the form of an individual written report. This should be written in a concise, formal
business style using single spacing and font size 12. You are required to make use of headings, paragraphs and
subsections as appropriate, and all work must be supported with research and referenced using the Harvard
referencing system. Please also provide a bibliography using the Harvard referencing system.
Table of Contents
P1. Provide introduction to procedural programming..................................1
1. Introduction to computer programming lauguage................................................1
1.1 Low lever language........................................................................................................1
1.2 High lever language.......................................................................................................2
P2. Identify the program units and data and file structures required
implement a given design...........................................................................4
1. The variables and data types required..................................................................5
1.1 The variables.................................................................................................................. 5
1.2 Data types required.......................................................................................................6
1.2.1 Basic Types............................................................................................................6
1.2.2 Enumcrated types.................................................................................................6
1.2.3 The type void........................................................................................................7
1.2.4 Derived types........................................................................................................7
3. Selection structures..............................................................................................9
3.1 If..................................................................................................................................... 9
3.2 If else............................................................................................................................ 11
3.3 Swtich-case................................................................................................................... 12
4. Interation constructs............................................................................................14
4.1 For................................................................................................................................. 14
4.2 While............................................................................................................................. 15
4.3 Do-While....................................................................................................................... 16
3. Pseudo code.........................................................................................................28
3.1 Select menu functions..................................................................................................28
3.2 Input student informantions.........................................................................................28
3.3 Print all student informations.......................................................................................29
3.4 Print highest grade........................................................................................................29
3.5 Print lowest grade.........................................................................................................30
Page |1
language. Because of the low (hence the word) abstraction between the language and machine
language, low-level languages are sometimes described as being “close to the hardware”.
Programs written in low-level languages tend to be relatively non-portable, due to being
optimized for a certain type of system architecture. Low-level languages can convert to machine
code without a compiler of interpreter-second-generation programming languages use a simple
processor called an assembler – and the resulting code runs directly on the processor. A program
written in a low-level language can be made to run very quickly with a small memory footprint. An
quivalent program in a high-level language can be less efficient and use more memory. Low-level
languages are simple but considered doffocult to use, due to numerous technical details that the
programmer must remerber. By comparison, a high-level programming language isolates
execution semantics of a computer architecture from the specification of the program which
simplifies development.
Page |2
and Fortran. The first high-level programming language designed for computer was Plankalkul,
created by Konrad Zuse. However, it was not implemented in his time and his original
contributions were largely isolated from other developments due to World War II, aside from the
language’s influence on the “Superplan” language by Heinz Rutishauser and also to some degree
Algol. The first significantly widespread high-level language was Fortran, a machine-independent
development of IBM’s earlier Autocode systems. Algol, defined in 1958 and 1960 by committees
of European and American computer scientists, intro duced recursion as well as nested functions
under lexical scope. It was also the first language with a clear distinction between value and name-
parameters and their corresponding sematics. Algol also introduced seral structured programming
concopts, such as the while-do and if-then-else constructs and its syntax was the first to be
described in formal notation – “Backus-Naur form” (BNF). During roughly the same period, Cobol
introduced records and Lisp introduced a fully general lambda abstraction in a programming
language for the first time.
Page |3
programming paradigm that a new developer will learn. Fundamentally, the procedural code is
the one that directly instructs a device on how to finish a task in logical steps. This paradigm user a
linear top- down approach and treats data and procedures as two different entities. Based on the
conpt of a procedure call, Procedural Programming divides the program into procedures, which
are also known as routines or functions, simply containing a series of steps to be carried out.
Simply put, Procedural Programming involves writing down a list of instructions to tell the
computer whtat it should do step-by-step to finish the task at hand.
The right selection of programming language yields solutions that are concise, easy to debug,
easy to extend, eay to document and easy to fix. The support and community. It is very important
to consider the platform on which the program will run. Say you have two languages, Java and C. If
a program is written in C and needs to be run on Windows and Linux platforms, it would require
platform compilers and two different executables. On the other hand, with Java development, the
program can run on any machine provided a Java Machine(JVM) is installed. The same goes for
web pages. They should all look and work the same across all browsers. However, using CSS3 tags
and HTML 5 without checking browser compatibility will cause the site to look and behave
diffenrently across different browsers.
P2.Identify the program units and data and file structures required to
implement a given design
Page |4
1.The variables and data types required
1.1.The variables
A variable is nothing but a name given to a storage area that our programs can manipulate. Each
variable in C has a specific type, which determines the size and layout of the variable’s memory;
the range of values that can be stored within that memory and the set of operations that can be
applied to the variable. The name of a variable can be composed of letters, digits and the
underscore character. It must begin with either a letter or an underscore. Upper and lowercase
letters are distinct because C is case-sensitive. C programming language also allows to define
various other types of variables, which we will cover in subsequent chapters like Enumeration,
Poionter, Array, Structure, Union, etc. For this chapter, let us study only basicvariable types. Based
on the basic types explained in the previous chapter, there will be the following basic variable
types
Page |5
1.2.Data types required
Data types in C refer to an extensive system used for declaring variables or functions of different
types. The type of a variable determines how much space it occupies in storage and how the bit
pattern stored is interpreted. The array types and structure types are referred collectively as the
aggregare types. The type of a fuction specifies the type of the fuction’s return value. We will see
the basic types in the following section, where as other types will be covered in the upcoming
chapters. The types in C can be classified as follows
1.2.1.Basic Types
They are arithmetic types and are further classified into: (a) integer types and (b) bloating-point
types.
1.2.2.Enumerated types
Page |6
They are again arithmetic types and they are used to define variables that can only assign
certain discrete integer values throughout the program.
1.2.4.Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and €
Function types
2.1.Int
Integers are a commonly used data type in computer programming. For example, whenever a
Page |7
number is being incremented, such as within a “for loop” or “while loop”, and integer is used.
Integer are also used to determine an item’s location within an array.
2.2.Float
2.3.Character
The character is also used as a reserved keyword in a programming language where it may be
represented in code languages as chr or char. It plays a critical role in computer programming that
is a data type that holds one character (letter, number, etc.) of data.
Declaration: char c;
2.4.Double
The double is a fundamental data type buildt into the compiler and used to define numeric
variables holding numbers with decimal points. C, C#, C++ and many other programming
languages recognize the double as a type. A double type can represent fractional as well as whole
values.
3.Selection structures
3.1.If
The ability to control the flow of your program, letting it make decisions on what code to
execute is valuable to the programmer. The if statement allows you to control if a program enters
a section of code or not based on whether a given condition is true or false. One of the important
fuctions of the if statement is that it allows the program to select an action based upon the user’s
input. For example, by using an if statement to check a user entered password, your program can
decide whether a user is allowed access to the pro
Page |9
3.2.If else
P a g e | 10
If-else is a conditional statement in C++. The C++ of statement runs a block of code if a condition
is met. An if-else statement fuctions the same way but runs a second block of code if the condition
is not met. If and if-else statements can be nested.
3.3.Swtich-case
P a g e | 11
Switch case statements are a substitute for long if statements that compare a variable to several
integral values. The switch statement is a multiway is a multiway branch statement. It provides an
easy way to dispatch execution parts of code based on the value of the expression. Switch is a
control statement that allows a value to change control of execution.
P a g e | 12
4.Interation constructs
4.1.For
A “For” Loop is used to repeat a specific block of code (statements) a known number of times.
The for-loop statement is a very specialized while loop, which increases the readability of
program. Here is the syntax of the of for loop.
P a g e | 13
4.2.While
While loop is also known as pre-tested loop. In general, a while loop allows a part of the code to
be executed multiple times depending upon a given boolean condition. It can be viewed as a
repeating if statement. The while loop is mostly used in the case where the number of iterations is
P a g e | 14
not known in advance.
4.3.Do-While
In the previous tutorial we learned while loop in C. A do while loop is similar to while loop with
one exception that it executes the statements inside the body of do-while before checking the
condition. On the other hand in the while loop, first the condition is checked and then the
P a g e | 15
statements in while loop are executed. So you can say that if a condition is false at the first place
then the do while would ren once, however the while loop would not run at all.
P a g e | 16
5.External modules/functions required
5.1.Stdio.h
The header file stdio.h stands for Standard Input Output. It has the information related to
input/output functions.
5.2.String.h
The string.h header defines one variable type, one macro and various functions for manipulating
arrays of characters.
5.3.Printf
In C programming language, printf() function is used to print the (“character, string, float
integer, octal and hexadecimal values”) onto the output screen.
1.Use case
Identify requiments:
P a g e | 17
Input student informations
2.Flowchart
P a g e | 18
i: the repeated time
option: menu
P a g e | 19
option: menu
ID: student ID
P a g e | 20
Grade: student grade
P a g e | 21
P a g e | 22
i: the repeated time
option: menu
P a g e | 23
i: the repeated time
option: menu
P a g e | 24
input option: selection option
P a g e | 25
i: the repeated time
option: menu
P a g e | 26
input option: selection option
3.Pseudo code
P a g e | 27
3.3.Print all student informations
P a g e | 28
3.5.Print lowest grade
Unlike with the object-oriented programming which is data and model concentrated, procedural
P a g e | 29
programming (PP) focus on sequences of actions to be done. From the point of programming, data
is the reason for the existence of a program.
In procedural languages such as C, programs are composed of procedures or functions and each
procedure is a sequence of statements that has a specific defined purpose.
2. The whole program is implemented based on actions such as reading, calculating and
printing. Therefore, a bunch of functions are written to solve a program from top to down.
A local variable is a variable that is declared in the main structure of a method and is limited to
the local scope it is given. The local variable can only be used in the method it is defined in, and if
it were to be used outside the defined method, the code will cease to work.
A global variable is a variable which is declared outside every other function defined in the code.
Due to this, global variables can be used in all functions, unlike a local variable.
P a g e | 30
2.4. Modularity
Modularity is when two dissimilar systems have two different tasks at hand but are grouped
together to conclude a larger task first. Every group of systems then would have its own tasks
finished one after the other until all tasks are complete.
P a g e | 31
REFERENCES
Kernighan, B. and Ritchie, D. (1988). The C Programming Language. United States, Hoboken:
Prentice Hall.
P a g e | 32