
























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-Procedural programming
Typology: Assignments
1 / 32
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 P4 P5 M3 M4 D 1
Grade: Assessor Signature: Date: Lecturer Signature: 2
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: void inputstudent(STD &stdx, int id, int n) void inputstudentinformation(STD &stdx, int id) &sv: enter student information sv. Use & reference, meaning the information will be changed both inside and outside the function. a[]: is a list of students. 7
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: void updatestudentinformation(STD&stdx) void updatestudent(STD a[], int id, int n) &sv: enter student information sv. Use & reference, meaning the information will be changed both inside and outside the function. 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 updatestudentinformation(STD&stdx) to update information of student whose ID is searched. You enter student information then use the function Average and status to calculate average and identify status of that student updating. 8
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 10
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). If n>=2 ( student in the array is more than 2), assign j=0. Start from second element in the array (i=j+1). Iterates form the beginning to the last element of the array, traverses the largest element form the position next to the element being browsed to the end, then replaces the value of that largest element with the element it is traversing ( find the largest element in the range from a[j] to a[n-1]). If a[j+1] is larger than max, then a[j] is the largest. Max=a[j+1].Average (Save the newly found max position). If n=1 (have 1 student in the array), student average is max. Position of student is 0. If n not equal 1 or n more than 2, display: “There are no student in the list”. 11
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: op: is the value you enter to select an option in the menu. arraySTD[]: store an array of student structs. amountSTD: the current number of students of the arraySTD array. idCount: is the auto-incrementing id counter of the student. Note: functionName(a,n) mean do the function for array a with n variable This menu will show up at the first time you run the program and after you finish one case. 13
Getting to the menu operation, I used “while” to take orders repeatedly. Here how it’s going: Display the menu operation, showing options and orders Read the number from the keyboard to determine which option the user requests and we get into the “switch…case” conditional statements: Case 1 : Add student to the student list Display: “Add student”, “idCount++” and “amountSTD++” mean increase number of students in the list by 1when add new student. Do the function inputstudent it enter student information then display ”Add student successful”. Do function pressAnyKey to end the function and break back to main menu. Case 2 : Update student information in the student list by enter the student ID If student in the list is higher than 0, display: “Input ID” and “Update student information”. Then use “scanf” to get id variable that you want to find student. Do the function updatestudent the enter information. If not, Display: “There are no student in the list”. After all, use function pressAnyKey to break function and return to main menu. 14
If the amount of student in the array is >0, display: “Sort student by average” then do functions sortbyaverage and 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 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 16
If the number orders are different from 9, then the loop is still going 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 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. 19
I choose case 7 to find who have the lowest score in the list 20