























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
prog102-asm2 effective for everyone
Typology: Assignments
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























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 Student ID 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 P 4 P 5 M3 M4 D
Grade: Assessor Signature: Date: Lecturer Signature:
I use void as a function return type, the function does not return any value. I use int as a function return type, the function does return value.
This function prints a line with n characters "". For presentation purposes. n: is the number of "" characters that will be printed to the screen. This function ends the operation and clears the previous screen, allowing the next operation to be performed. “ system(“cls”) ” to clear previous screen, “ getch ” to pause the menu until a key is pressed, “fflush(stdin)” to clear cache, avoid overflowing memory.
The requirement of the problem is that the student id automatically increases. So I will create this function to get the largest id of the list of students a[]. When add new student, the id will increase by 1 and idMax1 will be updated. a[]: is the student list array. n: amount of student in the list.
This function is used to add new students to the student list. I split into two functions:
a[]: is a list of students. id: is the id (auto increment) of the student. n: is the number of students in the list. void inputstudentinformation(STD &stdx, int id) to input information of student who added. You enter student information then use the function Average and status to calculate average and identify status of that student inputed. void inputstudent(STD &stdx, int id, int n) to add new student. I used function printLine for presentation and increase n by 1. Do the function inputstudentinformation.
This function is used to update student information by ID. With this function we will split into the following two functions:
This function is used to search for students in a list by name. Does not distinguish uppercase and lowercase letters. a[i]: list of students name[]: the keyword to compare with student’s name in the list n: number if students in the list
Average function is used to calculate average of 3 subjects of each students in the list Status function is used to identify if student passed or failed. If average >=6, student is passed. If not, student failed. I used “strcpy” to copy string of status point to student’s status.
This function used to sort student list according to the average score in ascending order a[i]: list of students n: number if students in the list
n: number of student in the array i, j: position of student in the array First, I assign i=0 and max =a[0] (the first value in array).
that smallest element with the element it is traversing ( find the smallest element in the range from a[j] to a[n-1]). If a[j+1] is smaller than min, then a[j] is the smallest. Min=a[j+1].Average (Save the newly found min position). If n=1 (have 1 student in the array), student average is min. Position of student is 0. If n not equal 1 or n more than 2, display: “There are no student in the list”. When i is different from - 1 or there are value i in array, display the name and average of that student to the screen.
Function printLine(130) for the presentation, use “For” to display student and their infomation in the list to the screen
This is the function where other functions will take order as well as every other command is created and adjusted. In main, I declare the data types of the variables first:
Getting to the menu operation, I used “while” to take orders repeatedly. Here how it’s going:
▪ Case 6 and 7 : Show student have highest average and student have lowest average If the amount of student in the array is >0, display “Show student have highest or lowest average” and do the function showmax or showmin. If not, display: “There are no student in the list”. After all do the function pressAnyKey then break and go back to the main menu. ▪ Case 8 : Display student list: If amount of student array is >0, do the function showStudent. If not, display: ”There are no student in the list”. After all do the function pressAnyKey then break and go back to the main menu. ▪ Case 0 : Break from the iteration, end the program ▪ Another cases : users might make mistakes of typing the wrong number, this is when a notification of retyping
III. PROGRAM RESULTS
I choose case 1 to enter each student to the list. Then choose case 8 to display all students to the screen. ID, name, gender, age, Math grade, Physic grade, Chemistry grade will be entered by hand. The average and status will be calculated by the program.
I choose case 2 then enter the ID which student I want to update information. Then I choose case 8 to display the updated list to the screen. The student I updated is the student who have ID is 3.
I choose case 5 to sort the student list by with the ascending average order. The list will be sorted and displayed to the screen.
I choose case 6 to find who have the highest score in the list.
I choose case 7 to find who have the lowest score in the list