PROG 102 - Assignment 2, Essays (university) of C programming

This is PROG 102 - Assignment 2

Typology: Essays (university)

2020/2021

Uploaded on 03/03/2022

Vincent_Louis_Pham
Vincent_Louis_Pham 🇻🇳

4.8

(15)

6 documents

1 / 16

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
Phạm Hoàng Gia Khang
Student ID
GCS210702
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
P5
M3
M4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download PROG 102 - Assignment 2 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 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

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

Task 1: Program implements the designed solution

1. Library function declaration

2. Struct declaration

5. Max grade.

6. Min grade.

7. Menu design.

8. Display: Number of student

10. Output the information.

11. Menu option:

12. Choice 1: Input a new list of information.

13. Choice 2: Output a new list of information.

15. Choice 4: Print the min ID and min grade.

16. Choice 5: Exit the program.

17. And this is my code:

#include <stdio.h> #include using namespace std;

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; }

Task 3: Review and evaluate the program design

Advantages:

  • The program runs very well
  • The program is very short, so testing will be easier.
  • The information of input and output data are good, not missing data, and have no

errors.

Disadvantages:

  • If entering the wrong ID from number to char, the program will run without

stopping.

  • The program needs Function statements to edit students’ names formally.