Professional Documents
Culture Documents
PROG102 GCS210942 VoDucTai Assignment1
PROG102 GCS210942 VoDucTai Assignment1
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
P age |1
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.
P age |2
Table of Contents
P age |4
3. Flowcharts ........................................................................................................................... 23
4. pseuso code ....................................................................................................................... 30
References ........................................................................................................... 33
P age |5
ASSIGNMENT 1 ANSWERS
P1. Provide an introduction to procedural programming
1. Introduction to computer programming languages.
1.1. Definition
-Computer programming languages allow us to give instructions to a computer in a language
the computer understands. Just as many human-based languages exist, there are an array of
computer programming languages that programmers can use to communicate with a
computer. The portion of the language that a computer can understand is called a “binary.”
Translating programming language into binary is known as “compiling.” Each language, from C
Language to Python, has its own distinct features, though many times there are commonalities
between programming languages.
- A programming language is a computer language programmers use to develop
software programs, scrips,or other sets of instructions for computers to execute.
- Although many languages share similarities, each has its own syntax. Once a
programmer learns the languages rules, syntax, and structure, they write the source code in
a text editor or IDE. Then, the programmer often compiles the code into machine
language that can be understood by the computer. Scripting languages, which do not require a
compiler, use an interpreter to execute the script
P age |6
particular type of computer. Such languages are considered high-level because they are closer
to human languages and further from machine languages.
In computer science, a high-level programming language is a programming language with
strong abstraction from the details of the computer. In contrast to low-level programming
languages, it may use natural language elements, be easier to use, or may automate (or even
hide entirely) significant areas of computing systems (e.g. memory management), making the
process of developing a program simpler and more understandable than when using a lower-
level language. The amount of abstraction provided defines how "high-level" a programming
language is.
- Examples: Python, Visual Basic, Delphi, Perl, PHP, ECMAScript, Ruby, C #, Java,
Pascal.
- A high-level programming language is a programming language with
strong abstraction from the details of the computer. In contrast to low-level programming
languages, it may use natural language elements, be easier to use, or may automate (or even
hide entirely) significant areas of computing systems (e.g. memory management), making the
process of developing a program simpler and more understandable than when using a lower-
level language
Low-level languages are considered to be closer to computers. In other words, their prime
function is to operate, manage and manipulate the computing hardware and components.
Programs and applications written in a low-level language are directly executable on the
computing hardware without any interpretation or translation.
P age |7
Machine language and assembly language are popular examples of low-level languages.
P age |8
2.2. Introduction to C Programming Language
- C is a mid-level structured oriented programming language that is extremely popular, simple,
and flexible to use. It is a structured programming language that is machine-independent and
extensively used to write various applications, Operating Systems like Windows, and many
other complex programs like Oracle database, Git, Python interpreter, and more.
- The base or father of programming languages is ‘ALGOL.’ It was first introduced
in 1960. ‘ALGOL’ was used on a large basis in European countries. ‘ALGOL’ introduced
the concept of structured programming to the developer community. In 1967, a new
computer programming language was announced called as ‘BCPL’ which stands for Basic
Combined Programming Language. BCPL was designed and developed by Martin
Richards, especially for writing system software. This was the era of programming
languages. Just after three years, in 1970 a new programming language called ‘B’ was
introduced by Ken Thompson that contained multiple features of ‘BCPL.’ This
programming language was created using UNIX operating system at AT&T and Bell
Laboratories. Both the ‘BCPL’ and ‘B’ were system programming languages.
- ‘C’ is a powerful programming language which is strongly associated with the
UNIX operating system. Even most of the UNIX operating system is coded in ‘C’. Initially
‘C’ programming was limited to the UNIX operating system, but as it started spreading
around the world, it became commercial, and many compilers were released for cross-
platform systems. Today ‘C’ runs under a variety of operating systems and hardware
platforms. As it started evolving many different versions of the language were released.
At times it became difficult for the developers to keep up with the latest version as the
systems were running under the older versions. To assure that ‘C’ language will remain
standard, American National Standards Institute (ANSI) defined a commercial standard
for ‘C’ language in 1989. Later, it was approved by the International Standards
Organization (ISO) in 1990. ‘C’ programming language is also called as ‘ANSI C’.
P age |9
3. Criteria to select a programming language to use
- we don't choose the language. We choose the field, which is accompanied by
one, two or three languages. They are already "chosen" for us. By whom? By the industry,
market, historical accident, after all.
It is characteristic for beginners to concentrate on the language. The syntax, the grammar... –
they seem so important, so unfamiliar that draw all our attention. But it turns out that this is
just the tip of the iceberg. What's beneath the water?
- The environment (and the way) of executing: The Compiler / The Virtual Machine.
P2. Identify the program units and data and file structures required to implement a given
design.
1. Variables
1.1. Definition:
Variable (computer science), a symbolic name associated with a value and whose
associated value may be changed
Variable (mathematics), a symbol that represents a quantity in a mathematical
expression, as used in many sciences
Variable (research), a logical set of attributes
- 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
P a g e | 10
because C is case-sensitive. Based on the basic types explained in the previous chapter, there
will be the following basic variable types.
- C programming language also allows to define various other types of variables,
which we will cover in subsequent chapters like Enumeration, Pointer, Array, Structure, Union,
etc. For this chapter, let us study only basic variable types.
1.2. Rules for naming a variable
* A variable name can only have letters(both uppercase and lowercase letters),
digits and underscore.
* The first letter of a variable should be either a letter or an underscore.
* There is no rule on how long a variable name(identify) can be. However, you may
run into problems in some compilers if the variable name is longer than 31
characters.
* Examples:
2. Data types
2.1. Definition
2.2. Types of data types in C
- A data type, in programming, is a classification that specifies which type of value a
variable has and what type of mathematical, relational or logical operations can be
applied to it without causing an error. A string, for example, is a data type that is used to
classify text and an integer is a data type used to classify whole numbers. - The data type
defines which operations can safely be performed to create, transform and use the
variable in another computation. When a program language requires a variable to only be
used in ways that respect its data type, that language is said to be strongly typed. This
prevents errors, because while it is logical to ask the computer to multiply a float by an
integer (1.5 x 5), it is illogical to ask the computer to multiply a float by a string (1.5 x
Alice). When a programming language allows a variable of one data type to be used as if it
were a value of another data type, the language is said to be weakly typed. - Technically,
the concept of a strongly typed or weakly typed programming language is a fallacy. In
every programming language, all values of a variable have a static type -- but the type
might be one whose values are classified into one or more classes. And while some classes
specify how the data type’s value will be compiled or interpreted, there are other classes
whose values are not marked with their class until run-time. The extent to which a
programming language discourages or prevents type error is known as type safety.
P a g e | 11
Sr.no. Type & Description
1 Char
Typically a single octet(one byte). It is an integer type.
2 Int
The most natural size of integer for the machine.
3 Float
A single-precision floating point value.
P a g e | 12
4 Double
A double-precision floating point value.
5 Void
Represents the absence of type.
P a g e | 13
3.2. If..else
3.2.1. Syntax
If(condition)
{
}
Else
{
}
3.2.2. Example
P a g e | 14
3.3. If..else if
3.3.1. Syntax
If(condition 1)
{
}
Else if(condition 2)
{
}
Else
{
}
P a g e | 15
3.3.2. Example
3.4. Switch..case
3.4.1. Syntax
switch(expression)
{
case constant1:
break;
case constant2:
P a g e | 16
break;
.
.
.
default:
break;
}
3.4.2. Example
P a g e | 17
4. Iteration structures
4.1. For statement
4.1.1. Syntax()
For(condition)
{
}
4.1.2. Example
P a g e | 18
4.2.2. Example
P a g e | 19
5. External modules
5.1. Stdio.h library
5.1.1. printf
5.1.2. scanf
P a g e | 20
5.2. String.h library
P a g e | 21
P3. Design a procedural programming solution for a given problem
1. Requirements of the given scenario
- A small program has a menu
- Input IDs and Grades
- Show IDs and Grades
- Print highest grade
- Print lowest grade
- Exit application
2. Use case diagram
P a g e | 22
3. Flowchart
3.1. Input IDs, Grades
. Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
P a g e | 23
- 2 Print all student impressions
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 1
- 5 if selection is 1 then start to print IDs, Grades
- Save ID and Grade into it to array
- if choice is 5, exit the program and return to the menu
- End
P a g e | 24
3.2. Show IDs and Grade
P a g e | 25
Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
- 2 Print all student impressions
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 2
- 5 if selection is 2 then start to show ID and Grade
- if choice is 5, exit the program and return to the menu
- End
P a g e | 26
3.3. Print highest grade
P a g e | 27
. Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
- 2 Print all student impressions
P a g e | 28
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 3
- 5 if selection is 3 then start to find the highest grade else check if the
selection is 5
- if choice is 5, exit the program and return to the menu for the user to re-
enter the program to select other options. If it is a choice other than1,2,3,4,5 the same
will force the user to re-enter the options included int the condition
P a g e | 29
4. Pseuso code
4.1. Input id and grade
Start
- S1: declare variables: id, grade, option
- S2: show menu
- S3: Input option from the menu
- S4:if(option==1)
Begin
-Input id and grade
-Save id and grade in the ID array and grade array
P a g e | 30
- Back to S2
End
- S5: if(option==5)exit application
Stop
P a g e | 32
Stop
REFERENCES
P a g e | 34
Instructions on how to write references:
https://www.computerscience.org/resources/computer-programming-languages/[ Accessed
April 5,6 2022 ]
P a g e | 35
8. mkdev.me,( 2022 ) How to choose a programming language [Definition],[online]. Available
at:
2022 ]
https://www.techtarget.com/searchapparchitecture/definition/data-type[ Accessed
November 2022 ]
P a g e | 36