Tải bản đầy đủ (.docx) (7 trang)

Assignment 2 Procedural Programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (104.38 KB, 7 trang )

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

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

D2


 Summative Feedback:

Grade:
Lecturer Signature:

 Resubmission Feedback:

Assessor Signature:

Date:


ASSIGNMENT 2 GUIDE

1 Implementation (P4, M3)
Declaring libraries used in program
#include <stdio.h>

<stdio.h>: Provide the core of the typing capabilities in C.


int inputsvID(char ID[][10]);
void inputgrade(float grade[], int n);
void max(char studentID[][10], float studentgrade[],int n);
void min(char studentID[][10], float studentgrade[], int n);
void displayall(int numstudent);

Declaring variables used in program: Int main(void) is a variable to declare main() function used in the program.
Int means that main() can only return integer values.
Void has the effect of specifying the main() function to return no value.

int main (){
    char ID[50][10];
    float grade[50];
    int n = inputsvID(ID);
    inputgrade(grade, n);
    float studentgrade;
    max(ID ,grade, n);
    min(ID ,grade, n);
    int numstudent;
}

Int: This is an integer; it basically represents the natural size of the integer. It is used to set variables a, c, option, ID
in the program.


•Float: This is a real number type, used to store floating point numbers. For example 2.5 and 5.6 are real numbers. It
is used to declare the variable Sgrade in the program.
char: this is the character type used in Name.

void displayall(int numstudent){

    printf("Total number of student: %d",numstudent);
    for (int i = 0; i < numstudent; i++){
  }
}

We create a function void displayall(int numstudent) used to input data from the keyboard for arrays. In the function
we use a for loop starting from int i =0 and ending when i
INPUT ID:
int inputsvID(char ID[][10]){
    int n =0;
    printf("Input student ID: ");
    //printf("Student ID must be greater than 0!\n");
    scanf("%d", &n);
    for(int i = 0; i < n; i++ ) {
    
        printf("Enter ID:");
        scanf("%s", ID[i]);
  }
    return n;
}

INPUT GRADE:
void inputgrade(float grade[], int n){
    printf("Input grade\n");
    // printf("Grade greater than 0 and lower than 10");


    for (int i = 0; i < n; i++) {
    

        printf("Enter grade: ");
        scanf("%f", &grade[i]);  
  }
  
}

MAX:
void max(char studentID[][10], float studentgrade[], int n) {
    printf("Student ID: ");
    float max = studentgrade[0];
    printf("Has the highest grade %.2f\n", max);
    for (int i = 0; i < n; i++) {
        if(max <= studentgrade[i]) {
            max = studentgrade[i];
    }
  }
    for(int i = 0; i < n; i++){
        if(max == studentgrade[i]){
    }
        printf("%s", studentID[i]);
  }
  
}

We initialize the void function void max(char studentID[][10], float studentgrade[], int n) used to find the largest
value in the array. In the function we declare the variable int Max = studentgrade[0] used to assign the maximum
value of the array, we use a for loop that starts at int i =0 and ends when itraverse each element in the array. In the for loop we use if with the condition that if studentgrade[0].averade is
greater than Max then we assign the value of Max = studentgrade[i].; At the end of the for loop, we print Max to the
screen.


MIN:
void min(char studentID[][10], float studentgrade[], int n){
    printf("Student ID: ");
    float min = studentgrade[0];
  
    for (int i = 0; i < n; i++){


        printf("Has the lowest grade %.2f", min);
        if(min >= studentgrade[i]){
            min = studentgrade[i];
    }
  }
    for (int i = 0; i < n; i++){
        if(min == studentgrade[i]){
            printf("%s", studentID[i]);
    }
  }
}

We initialize the void function void min(char studentID[][10], float studentgrade[], int n) used to find the largest
value in the array. In the function we declare the variable int Min = studentgrade[0] used to assign the minimum
value of the array, we use a for loop that starts at int i =0 and ends when itraverse each element in the array. In the for loop we use if with the condition that if studentgrade[0].averade is
greater than Min then we assign the value of Min = studentgrade[i].; At the end of the for loop, we print Min to the
screen.

2 Program results (P4)
Show screenshots of your program in running

- Starting the program will appear the number of students that you choose for you to choose to start.
- When you have finished entering the number of students, you will enter the All Student IDs first and go to the
Score.


2.2
- When entering the ID, the score will display the updated information.

It will then display the student information and show the student ID with the highest and lowest scores.
If two or more students have the same highest or lowest score, it will show both or more students.

3 Testing (P5, M4)

Write test plan and perform tests to get results. Show test log.
Analyse test results in test log.

4 Evaluation (D2)

Evaluate your program, state lessons learnt and future improvements.
Evaluate how procedural programming is applied in your program (advantages, disadvantage, difficulties)



×