Procedural Programming Standards and Code Implementation: A Case Study, Assignments of C programming

Procedural Programming assignment

Typology: Assignments

2020/2021

Uploaded on 06/16/2021

unkaeciique
unkaeciique 🇻🇳

4.7

(174)

29 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 | H o N g o c K h a n h
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 0: Procedural Programming
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Hồ Ngọc Khánh
Student ID
GCS200074
Class
Assessor name
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
P4
P5
M3
M4
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Procedural Programming Standards and Code Implementation: A Case Study and more Assignments C programming in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 0 : Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Hồ Ngọc Khánh Student ID GCS Class Assessor name 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 P4 P5 M3 M4 D

CONTENTS

  • PROGRAM IMPLEMENTATION
    • I. Introduction
    • II. Programming standards.............................................................................................................
        1. Procedural Programming Standards
        1. Structure Standards
    • III. Operating results
  • TESTING AND DEBUGGING
    • I. Test Plan
    • II. Test Cases.................................................................................................................................
    • III. Executing and Log results
    • IV. Analyzation
  • EVALUATION AND CONCLUSION
  • CODE LISTINGS
  • Figure 1: PROGRAM REVIEW FIGURES
  • Figure 2: FILE HEADER
  • Figure 3: EXAMPLES OF CODE COMMENTINGS IN MY WORK................................................................
  • Figure 4: LIST OF VARIABLES AND FUNCTIONS IN MY PROGRAM
  • Figure 5: EXAMPLE OF INDENTATION STANDARDS IN MY WORK
  • Figure 6: EXAMPLE OF WHITESPACE STANDARDS IN MY WORK............................................................
  • Figure 7: if-else STATEMENTS IN MY WORK
  • Figure 8: CORRECT FORM OF USING for STATEMENTS
  • Figure 9: for STATEMENTS IN MY WORK
  • Figure 10: CORRECT FORM OF USING while STATEMENTS
  • Figure 11: while STATEMENT IN MY WORK
  • Figure 12: CORRECT FORM OF USING do-while STATEMENTS
  • Figure 13: do-while STATEMENT IN MY WORK
  • Figure 14: CORRECT FORM OF USING switch
  • Figure 15: switch STATEMENT IN MY WORK (OPTIONAL)
  • Figure 16: SCREENSHOT NO.1
  • Figure 17: SCREENSHOT NO.2
  • Figure 18: SCREENSHOT NO.3
  • Figure 19: SCREENSHOT NO.4
  • Figure 20: SCREENSHOT NO.5
  • Figure 21: SCREENSHOT NO.6
  • Figure 22: SCREENSHOT NO.7
  • Figure 23: TEST RESULT NO.1................................................................................................................
  • Figure 24: TEST RESULT NO.2................................................................................................................
  • Figure 25: TEST RESULT NO.3................................................................................................................
  • Figure 26: TEST RESULT NO.4................................................................................................................
  • Figure 27: TEST RESULT NO.5................................................................................................................
  • Figure 28: TEST RESULT NO.6................................................................................................................
  • Figure 29: TEST RESULT NO.7................................................................................................................
  • Figure 30: TEST RESULT NO.8................................................................................................................
  • Figure 31: TEST RESULT NO.9................................................................................................................
  • Figure 32: TEST RESULT NO.10..............................................................................................................
  • Figure 33: TEST RESULT NO.11..............................................................................................................

PROGRAM IMPLEMENTATION

I. Introduction

According to the circumstance has been mentioned in Assignment 1, I have successfully compiled a program with C language base, which might help in solving that problem, with the assistance from Microsoft Visual Studio and MinGW-w64 environment compiler. This program exploits the researches about Procedural Programming and Basics of Programming languages. Below shows briefly the vision of my workspace: Figure 1 : PROGRAM REVIEW In this section, I will go across several sub-sections about my implementation for this particular problem:

  1. Programming standards: compare my work with Procedural Programming’s standards and evaluate on how many requirements my work meets.
  2. Screenshots of oprating results: demonstration of my program’s results to compare to my expectation.

II. Programming standards In this sub-section, I am going to present about the Procedural Programming structures and coding standards. Hence, this sub-section will be divided into two parts which are Procedural Programming Standards and Comparison of my work.

1. Procedural Programming Standards Definition: This are a set of procedures that can be specified for a specific programming language defining a programming style, techniques, and various procedures. These protocols can be written in the language for different parts of the programme. They can be considered to be the primary qualities of software creation. Coding standards guarantee that all developers working on the project meet certain defined guidelines. The key purpose of the coding process is to code from the design document prepared during the design phase into a high-level language and then to validate the code by the device. The importance of procedural programming standards:

  1. Security Concerns: Code becomes vulnerable to attacks if it is unreliable, includes logic errors and bugs. Any of the above issues occur due to the flawed programming code that may have arisen from bad coding practises.
  2. Performance Issues: Bad coding has a detrimental impact on site results. Performance problems cover a variety of topics, such as when the user connects with the web, server response issues, reusability & code flow and so on. In the future, if I want to apply for a professional software or cloud engineer, there are some strict standards or regulations I have to follow or else I won’t get the job:
  3. The code should be easy to read, by compiling the program these ways:
  • Try to describe the various parts of the code by segmenting the code blocks into a paragraph.
  • Using the indentation to denote the start and end of the control systems, along with a simple specification of where the code is within them.
  1. There should be continuity in the code in the naming convention of the variables. In addition, the data that is in the code should be represented.
  2. Name the tasks according to what they do.
  3. The code should be such that even after returning to it after a space gap, one should be able to understand it, without that person needing to look at every line of it.
  4. Follow a clear and identical way to comment on the job.
  5. It is important to avoid complex language functions or constructs which are difficult to understand.
  • Layout : should generally follow the GNU coding standard layout for C, extended it to C++. 1. Indentation: - Do not use tabs for indentation. - Indentation spacing is 2 spaces. - Lines should be within a reasonable range. Lines longer than 100 columns should generally be avoided. if (menu == 1 ) student_output(num); // not using tab as indentation and the indentation spaces is 2 spaces else if (menu == 2 ){ for (int i = 0 ; i <= num; i++) if (max_score(num) == sc[i]) printf("Student with ID %d has the highest score: %.2f\n",id[i],sc[i]); } // the longest line only has 82 columns Figure 5 : EXAMPLE OF INDENTATION STANDARDS IN MY WORK 2. Whitespace - Conventional operators ( if, for, while , and others) should be surrounded by a space character. - Commas should be followed by a white space. - Semicolons in for statements should be followed by a space character. void student_output(int n) { for (int i = 0 ; i <= n; i++) // conventional operator for is surrounded by space character // semicolons in statement are followed by space character printf("Student ID: %d --- Score: %.2f\n", id[i], sc[i]); // commas are followed space character } Figure 6 : EXAMPLE OF WHITESPACE STANDARDS IN MY WORK 3. if-else condition statements The keywords have to stay in the same column, which will be demonstrated below: if (menu == 1 ) student_output(num); else if (menu == 2 ) { for (int i = 0 ; i <= num; i++) if (max_score(num) == sc[i]) printf("Student with ID %d has the highest score: %.2f\n", id[i], sc[i]); }

else if (menu == 3 ) { … // keywords of statements are in the same column with the inner statements Figure 7 : if-else STATEMENTS IN MY WORK

4. for iteration statements The for iteration statements should be in this form: Figure 8 : CORRECT FORM OF USING for STATEMENTS for (int i = 0 ; i <= n; i++) { printf("Student %d's ID: ",i+ 1 ); scanf("%d", &id[i], "\n"); printf("Student %d's score: ",i+ 1 ); scanf("%f", &sc[i], "\n"); } … for (int i = 0 ; i <= num; i++) if (min_score(num) == sc[i]) printf("Student with ID %d has the lowest score: %.2f\n", id[i], sc[i]); Figure 9 : for STATEMENTS IN MY WORK 5. while iteration statements The while iteration statements should be in this form: Figure 10 : CORRECT FORM OF USING while STATEMENTS while (sc[i] < 0 || sc[i] > 10 ) { printf("Grade's invalid. Please retype!\n"); printf("Student %d's score: ", i+ 1 ); scanf("%f", &sc[i], "\n"); } Figure 11 : while STATEMENT IN MY WORK 6. do-while iteration statements

switch (menu) { case 1 : student_output(num); break; case 2 : for (int i = 0 ; i <= num; i++) if (max_score(num) == sc[i]) printf("Student with ID %d has the highest score: %.2f\n", id[i], sc[i]); break; case 3 : for (int i = 0 ; i <= num; i++) if (min_score(num) == sc[i]) printf("Student with ID %d has the lowest score: %.2f\n", id[i], sc[i]); break; case 4 : break; default: printf("Please try again!\n"); break; } Figure 15 : switch STATEMENT IN MY WORK (OPTIONAL) III. Operating results

  • When run the code, it immediately appears with the notification of asking how many students to input. Right after that is the appearance of the student_input Figure 16 : SCREENSHOT NO.
  • After typing the IDs and the grades, the menu operation will be shown up as well. I also have to mention the strong point in this sub-function which does the job of checking the grades’ validation typed in, if the grade is invalid, a notification of “Grade’s invalid. Please retype!” to inform the user to retype. This small function will be on repeat until the grade typed in valid so it can transfer to another student

Figure 17 : SCREENSHOT NO.

  • Your request: 1. This is when the program display the students’ IDs and grades Figure 18 : SCREENSHOT NO.
  • Your request: 2. The menu operation will be appeared again, the program will take the request number 2 and this is when it shows the highest grade along with the individual who owns it Figure 19 : SCREENSHOT NO.

TESTING AND DEBUGGING

I. Test Plan

Before turning in the work, a test plan should be made base on the requirements of the problem given. The test plan focuses on testing categories and the result comes with them. The test plan will also come with the measure for achievements.

  • Menu operation: function well and regularly with each request, which is doing the right order and taking requests repeatedly. Beside, invalid input will be solved by the program.
  • Data: have to make sure that the information is in the correct data type and stored in the right arrays. In addition, the test plan also includes testing with negative numbers, off-limit numbers or switch data types such as: characters or strings. At the end, the information can be correctly displayed.
  • The highest/lowest grade modules: function normally, no infinite loop happens or any unexpected result.
  • Result layout: visual-friendly and easy to see.

II. Test Cases

I am going to stick with a data test plan with 5 students ( num =5). The students’ IDs will vary from 261 to 265. Their grades will be tested as followed:

  • Student 261: 9.
  • Student 262: 7.
  • Stduent 263: 10
  • Student 264: 6.
  • Student 265: 8. Test case no. Test case’s target Test location Original condition Taken steps Input data Expected result Actual result Status 1 Enter ID student_input Integer Run code Enter num value Type “261" 261 261 261 Passed 2 Enter ID student_input Integer Run code Enter num value Type “abc" abc Retype ID Infinite loop Failed

Enter grades student_input Float 0<= grade <= Run code Enter num value Type ID Type “90” 90 Retype grade Retype grade Passed 4 Enter grades student_input Float 0<= grade <= Run code Enter num value Type ID Type “9.0” 9.0 9.0 9.0 Passed 5 Choose request Main function menu != 4 Run code Enter num value Type ID & grades Type “1” 1 student_output student_output Passed 6 Choose request Main function menu != 4 Run code Enter num value Type ID & grades Type “2” 2 max_score max_score Passed 7 Choose request Main function menu != 4 Run code Enter num value Type ID & grades Type “3” 3 min_score min_score Passed 8 Choose request Main function menu != 4 Run code Enter num value Type ID & grades Type “5”

Reorder request Reorder request Passed 9 Choose request Main function menu != 4 Run code Enter num value Type ID & grades Type “4” 4 Stop program Stop program Passed 10 Display IDs and grades student_output ID: integer Grades: float Run code Enter num value Type ID & grades Type “1” 1 Display list Display list Passed 11 Display the highest grade max_score max= sc[0] Float Run code Enter num value Type ID & grades Type “2”

Show the highest grade along with the ID: 263 – 10. Show the highest grade along with the ID: 263 – 10. Passed 12 Display the lowest grade min_score min= sc[0] Float Run code Enter num value Type ID & grades Type “3”

Show the lowest grade along with the ID: 264 – 6. Show the lowest grade along with the ID: 264 – 6. Passed Table 1 : TEST CASES

  1. Test case number 4: Figure 26 : TEST RESULT NO.
  2. Test case number 5: Figure 27 : TEST RESULT NO.
  3. Test case number 6: Figure 28 : TEST RESULT NO.
  4. Test case number 7: Figure 29 : TEST RESULT NO.
  1. Test case number 8: Figure 30 : TEST RESULT NO.
  2. Test case number 9: Figure 31 : TEST RESULT NO.
  3. Test case number 10: Figure 32 : TEST RESULT NO.
  4. Test case number 11: Figure 33 : TEST RESULT NO.
  5. Test case number 12: Figure 34 : TEST RESULT NO.