Assignment 2 PROG102, Essays (university) of C programming

Your next task is to implement the software that you designed in previous steps. You need to implement the software designed in assignment 1 using C programming language. Your code must make use of programming standards, including file headers and effective code commenting. You need to provide screenshots of your program when running. During the development of your program, if you make any changes to the original design, state them with reasons in report. Your code listings must be included as a

Typology: Essays (university)

2022/2023

Uploaded on 02/26/2023

trinh-nguyen-phuong-fgw-hn
trinh-nguyen-phuong-fgw-hn 🇻🇳

4.8

(4)

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 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
Trinh Nguyen Phuong
Student ID
GCH210876
Class
GCH1108
Assessor name
Pham Danh Tuyen
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
PHUONG
Grading grid
P4
P5
M3
M4
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Assignment 2 PROG102 and more Essays (university) C programming in PDF only on Docsity!

ASSIGNMENT 2 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 Trinh Nguyen Phuong Student ID GCH

Class GCH1108 Assessor name Pham Danh Tuyen

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 PHUONG

Grading grid

P 4 P 5 M3 M4 D

r Summative Feedback:Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

I. Screenshots & Explain

  1. Problem:

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 this 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 the 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 the

program.

  1. Problem solving: I write a program to manage student information. The main function of program is:
    • Input student information. (Student ID, student grade)
    • Output student information. (Print to the screen)
    • Find the student has highest grade.
    • Find the student has lowest grade.
    • Exit.

II. Implements (P4, M3)

  1. Coding standard: To enter, save, and show a list of student grades, use this straightforward software. The application was created using the C programming language and has the following features:
  • The enter_grades function: Gets student names and grades from the user and stores them in the ids and grades arrays. Student information is entered until the user enters the word "exit".
  • Print_grades function: Prints a list of students and their respective scores.
  • Find_highest_lowest function: Finds the student with the highest and lowest scores in the list and prints their information. If more than one student has the same score, all of them will be printed.
  • Indentation:
  • A space is required after entering a comma between the arguments of both functions.
  • Each nested block should be properly indented and spaced.
  • Proper indentation should be at the beginning and end of each block in the program.
  1. Library in the program: In this program, I use <stdio.h> library because it provides the core of the input function. This library contains the print function to display the input data to the screen. In the above code, #define MAX_STUDENTS 50 is used to define a constant named MAX_STUDENTS with a value of 50. This constant is used to define the maximum number of students stored in the ids array. and grades array. Constant definition avoids the use of hard numbers in the code, making it easier to manage and modify the code. If we want to change the maximum number of students, we just need to change the value of MAX_STUDENTS without having to modify other commands in the code. Figure 1. Library of the program

Finally, the function increases the number of students using the ‘++’ operator. Figure 3. Input information and grades of students.

  1. Function output information of student: The function outputs the information (name and grade) of all students entered using the ‘ enter_grades()’ function. It takes in three parameters:
  • ‘Ids' : a 2D character array to store the names of the students.
  • ‘Grades' : a 1D float array to store the grades of the students.
  • ‘Count' : an integer representing the number of students entered. The function loops through all the students entered (up to ‘ count’ ) and prints out their name and grade in the format "name: grade".

Figure 4. Output grades of students.

  1. Functions find the highest and lowest grades of student: The function finds the highest and lowest grades of students in an array of grades and their corresponding names in an array of student IDs. It takes the following parameters:
  • char ids [][100] : an array of student IDs
  • float grades [] : an array of grades
  • int count : the number of students The function first initializes max_index and min_index to 0, which represent the indexes of the students with the highest and lowest grades, respectively. It also initializes max_count and min_count to 1, which represent the number of students who have the same highest and lowest grades. The function then loops through the grades array, comparing each grade to the current maximum and minimum grades. If a grade is greater than the current maximum grade, the max_index is updated to the current index and max_count is reset to 1. If a grade is equal to the current maximum grade, the ID of the student is added to the max_names array and max_count is incremented. Similarly, if a grade is less than the current minimum grade, the min_index is updated to the current index and min_count is reset to 1. If a grade is equal to the current minimum grade, the ID of the student is added to the min_names array and min_count is incremented. Finally, the function prints out the student IDs and grades of the students with the highest and lowest grades, along with their names if there is more than one student with the same highest or lowest grades.
  • Nhap diem
  • Hien thi danh sach diem
  • Tim diem cao nhat va thap nhat
  • Thoat Figure 9. Menu options of program III. Testing (P4)
  1. Screenshot:

➢ Menu option:

Figure 10. Menu option.

➢ Input student information:

Figure 11. Input ID and Grade of student

➢ Output information of students to the screen:

  • Create date: 26/2/ a. Test Case 1 - Testing input of student information:
  • Input:
  • Option: 1
  • Name: “Phuong”
  • Grade: 9
  • Expected Output:
  • "Phuong: 9" is added to the list of students and their grades. b. Test Case 2 - Testing output of student information
  • Input:
  • Option: 2
  • Students: {“Phuong”, “Hoang”, “Tung”}
  • Grade: {9.0, 4.0, 7.0}
  • Expected Output:
  • The program should display the following output:

“ List of Grade:

Phuong: 9.

Hoang: 4.

Tung: 7.0”

c. Test Case 3 - Testing finding highest and lowest grades of student

  • Input:
    • Option: 3
    • Students: {“Phuong”, “Hoang”, “Tung”}
    • Grade: {9.0, 4.0, 7.0}
  • Expected Output:
    • The program should display the following output:

"Student(s) with the highest grade:

Phuong: 9.

Student(s) with the lowest grade:

Hoang: 4.0"

d. Test Case 5 - Testing invalid input

  • Input:
    • Option: “abcd”
  • Expected Output:
    • The program should display the following output:

"Invalid input. Please enter a valid option."