









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
This is PROG 102 - Assignment 2
Typology: Essays (university)
1 / 16
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 Phạm Hoàng Gia Khang Student ID GCS
Class GCS1002^ Assessor name Lê Nhị Lãm Thuý
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:
Task 1: Program implements the designed solution
#include <stdio.h> #include
struct student { char name[100]; int id; float grade; }; typedef student st; void input(student st[100],int &n); void output(student st[100],int n); void sort(student st[100],int n); void swap(float &n, float &m); void maxgrade(student st[100],int n); void mingrade(student st[100],int n);
int main() { student st[100]; int n,a; input(st,n); output(st,n); sort(st,n); //output(st,n); do { cout<<"\n\n\n\t\t--MENU--"; cout<<"\nOptions:"; cout<<"\n************************************************\n"; cout<<" 1. Input the information of students \n "; cout<<" 2. Output the information of students \n "; cout<<" 3. Print the highest grade \n ";
cout<<"\nStudent's Grade: "; cin>>st[i].grade; } } void output(student st[100], int n) { for(int i=0; i<n; i++) { cout<<"\nInformation for student "<<i+1; cout<<"\nStudent's ID: "<<st[i].id; cout<<"\nStudent's Name: "<<st[i].name; cout<<"\nStudent's Grade: "<<st[i].grade; } }
void swap(float &n, float &m) { float t = n; n = m; m = t; }
void sort(student st[], int n) { for (int i=0; i < n - 1; i++) { for (int j = i+1; j < n; j++) { if (st[i].grade > st[j].grade) { swap(st[i].grade, st[j].grade); } } } }
void maxgrade(student st[100],int n)
float max; int idmax; max = st[0].grade; idmax = st[0].id; for(int i =1; i<n;i++) if(st[i].grade>max) { max = st[i].grade; idmax = st[i].id; } cout<<"\nmax grade= "<<max; cout<<"\nmax id= "<<idmax; cout<<endl; }
void mingrade(student st[100], int n) { float min; int idmin; min = st[0].grade; idmin = st[0].id; for(int i =1; i<n;i++) if(st[i].grade<min) { min = st[i].grade; idmin = st[i].id; } cout<<"\nmin grade= "<<min; cout<<"\nmin id= "<<idmin; cout<<endl; }