Docsity

Procedural Programming Assignment for BTEC Level 5 HND Diploma in Computing - Prof. Thùy, Assignments of C programming

Toggle sidebar
bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: Procedural Programming
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Nguyen Anh Huy
Student ID
GCS210741
Class
GCS1007
Assessor name
Huynh Thi My Trang
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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Procedural Programming Assignment for BTEC Level 5 HND Diploma in Computing - Prof. Thùy and more Assignments C programming in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog 102 : Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyen Anh Huy Student ID GCS Class GCS1007 Assessor name Huynh Thi My Trang 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 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

STUDENT MANAGER SYSTEM

I - INTRODUCTION

1. Overview

C programing language is a general-purpose computer programming language. Dennis Ritchie created it in the 1970s, and it is still very popular and influential. Operating systems, device drivers, and protocol stacks have continued to use it, though application software has used it less frequently. The smallest microcontrollers and embedded systems to the largest supercomputers all use the programming language C. Procedural programming (PP) is a programming paradigm, derived from imperative programming, based on the concept of the procedure call. The procedures divide a large program into blocks of functions that are small enough contains a series of calculation steps to be performed. Each function has a start and an end point, and has its own data and logic. In the program, the functions work independently. Data is converted back and forth through function call parameters. Dividing a program into functions allows multiple people to participate in the program's construction. Each person constructs one or more functions independently of the other. In a procedural program, we only need to know which function can do specific tasks. It doesn't matter how it's done, as long as the function is reliable, you can use it without knowing how well it performs its function. This is called functional abstraction (aka specialization) and is the foundation of procedural programming. The characteristics of PP are:

  1. Focus on process or doing things rather than data.
  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.
  3. Global data is often shared by all functions.
  4. Data moves openly from function to function. The disadvantages of PP are:
  5. Bad code-ruse. Not like class and objects that resemble the real-world model, functions in PP are task-oriented and cannot be reused when meeting a different one. Except for some commonly used library functions, we need to write many repetitive codes for similar problems.
  6. Hard to expand the application. The entire process in PP is coded directly into the application, very-task related. For example, an application in PP for registering the user will not be used for logging on and off. Difficult to create new data types.
  7. Hard to maintain. It will be a timing consuming solution to make changes. If one function accidentally changes value of the global data, all the functions who access to this global data must change their values.
  8. No information hiding. Data is exposed to the whole program, so no security for data.
  1. Hard to design. For example, in designing graphical user interface, we'd better mainly concentrate on how to design a menu, a button etc. since people will see them at first sight, not actions behind. The advantages of PP
  2. Simple. No need to think about code reusing for later use, just think about how to finish this task.
  3. Ease of implementation of compilers and interpreters.
  4. Easy to keep track of workflow.
  5. Needs less memory. There is no data abstraction leading to a large code size that consumes lots of memory.
  6. A kind of modular programming that helps to learn OOP later.

2. Problem statement

Scenario: A teacher wants to manage grades of a class. He asks I to help him to write a small application to do that. He needs to enter student IDs, name, gender, birthday, grades (Math, Physical, Chemical, English, Computer Science), average score. Firstly, he needs to print all student IDs, name, gender, birthday, together with their grades. Secondly, he needs to delete student by No. in list. Thirdly, he needs to sort student list (by name/student ID) ascending/descending. Fourthly, he needs to find student by name/student ID, highest average grade and lowest average grade. Finally, he needs show student list. My 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.

b. Switch statements Switch statement acts as a substitute for a long if-else-if ladder that is used to test a list of cases. A switch statement contains one or more case labels that are tested against the switch expression. When the expression match to a case then the associated statements with that case would be executed. We have seen the way of using conditional statements such as if, if-else. if-else ladder, but the need for an additional way of dealing with conditional statements may seem unnecessary but based on the certain usage, switch case was defined to check for the single condition, and based on the multiple cases, code can be executed.

  • Syntax: switch (expression) { case /* constant-expression /: / code */ break; default: break; }
  • Flowchart:

3. Loop statements needed in the problem

a. While loop This loop executes a statement or a block of statements until the specified boolean expression evaluates to false.

  • Syntax: while (/* condition /) { / code */ }
  • Flowchart: b. For loop This loop has three sections - index declaration, condition (boolean expression) and updation section. In each for loop iteration, the index is updated (incremented/decremented) by updating section and checked with the condition. If the condition is matched, it continues execution until the specified boolean expression evaluates to false.
  • Syntax: for (/* index declaration /; / condition /; / updation section /) { / code */ }

4. Functions

a. Split function Add student information Enter student information including name, student id, gender, birthday, subject scores. Delete student information Print out the current list and delete by No. Sorted student Sort student list by name/student ID Find student The function allows to search for students in 4 ways: student ID, name, lowest average score, highest average score Show student list Print student information including name, student id, gender, birthday, subject scores, average score.

b. Hierarchy diagram Hierarchy diagram

b. Flowchart ❖ Menu option Flowchart 1 : Menu option

Explain flowchart: Step 1: Start Step 2: Declare variable int key, bool mOption Step 3: Check the condition “mOption = true”

  • If true, go to step 3
  • If false, go to step 6 Step 4 : Read variable key Step 5 : Compare key:
  • If key = 1: Add student information and go back step 3
  • If key = 2: Delete student information and go back step 3
  • If key = 3: Sort student by name/ student ID and go back step 3
  • If key = 4: Find student by name/ student ID/ lowest average score/ highest average score and go back step 3
  • If key = 5: Show student list and go back step 3
  • If key = 0: mOption = false and go back step 3 Step 6 : End

Explain flowchart: Step 1: Start Step 2: Parameter numOfStud, n and arrSt[] Step 3: Declare variable i Step 4 : Set variable i = numOfStud Step 5 : Check the condition “i < n”:

  • If true, input student information: name, student id, gender, birthday, subject scores
  • If false, go to step 7 Step 6 : Increment i by 1 then repeat step 5 Step 7 : Compute numOfStud = numOfStud + n Step 8 : End

❖ Delete student Flowchart 3 : Delete student

❖ Function sort student

  • Sort by name Flowchart 4 : Sort student by name

Explain flowchart: Step 1: Start Step 2: Parametter arrSort[], n Step 3: Declare variable I, j Step 4 : Set i = 0 Step 5 : Check the condition “i < n - 1”:

  • If true, go to step 6
  • If false, go to step 9 Step 6 : Set int j = i + 1 Step 7 : Check the condition “ j < n”
  • If true, go to step 8
  • If false, increment i by 1 then repeat step 5 Step 8 : Check the condition “strcmp(strupr(arrSort[i].name), strupr(arrSort[j].name)) > 0”
  • If true, swap arrSort[i] and arrSort[j] and increment j by 1 then repeat step 7
  • If false, increment j by 1 then repeat step 7 Step 9 : End