btec level 5 hnd diploma in computing prog102 procedural programming

28 0 0
Tài liệu đã được kiểm tra trùng lặp
btec level 5 hnd diploma in computing prog102 procedural programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ASSIGNMENT 1 FRONT SHEET Unit number and title Prog102: Procedural Programming Student declaration I certify that the assignment submission is entirely my own work and I fully understan

Trang 1

ASSIGNMENT 1 FRONT SHEET

Unit number and title Prog102: Procedural Programming

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

Trang 3

Summative Feedback: Resubmission Feedback:

Lecturer Signature:

Task 1:

- Computer programming languages:

A program is what instructs the computer to perform a task in other words, the control of a computer program that uses the computer as a device to process data The raw data is processed into the desired output format during program execution These programs are written in high-level programming languages It is similar to human language It's too complicated for a computer to understand Computers can only understand machine language and low level language So we have to create simple and basic program People have different languages to communicate with each other computers also have different

Trang 4

languages to communicate with each other like C, C++, C#, Java, Python, etc In conclusion, computers only understand machine language, also known as binary language (language of 0 and 1).But computers can also understand programs written in high-level languages by humans(C, C++, C#, Java, Python, etc)

-Procedural programming:

The first thing a programmer can learn is procedural programming Procedure code is code that directly instructs devices to complete a task It takes a top-down linear approach and treats data and procedures as two different things According to the concept of procedure, procedural programming can be called

Trang 5

routine or function, it contains many steps to be performed In short, procedural programming generates a list of instructions for the computer tells the computer what to do to complete the task

-Key features of procedural programming:

+ Predefined functions: a command identified by name These functions are usually created in high-level programming languages they are in the library or the registry

+ Local Variable: a variable declared in the main struct and limited to the provided local scope code will stop working if used outside the specified method

+ Global Variable: a variable declared outside of a function every other function So global variable can be used in all functions

+ Modularity: Two systems with different missions work together to complete the most important task first Once done, the two systems will do separate tasks

+ Parameter Passing: used to pass parameters to functions, subroutines or procedures Can be done via 'pass by name', 'pass by result', 'pass by value', 'pass by value-result' 'pass by reference'

Task 2:

- The variables and data types required in the program : int n,id,a,maxid,minid;

char name; student sv,temp;

Trang 6

int n;

float grade,math,phys,chemis,max,min;

-Two different selection structures: 1) void max(student sv[100],int n); 2) void increase(student sv[100],int &n);

Trang 7

+Condition to check: input student’s grade (both structures) +The reason it’s necessary:

1) Finding max student’s grade.2) Sort increasing student’s grade.+It can be used in:

1) Outside the main function In my assignment: After void output(student sv[100],int &n) and before void min(student sv[100],int n)

2) Outside the main function In my assignment: After void hoanvi(student &x,student &y) and before void decrease(student sv[100],int &n)

+ Iteration constructs if max < sv[i] then max = sv[i] Repeat in succession to find the max : Code:

for(int i = 0;i < n;i++){ if(max < sv[i].grade){

max = sv[i].grade; maxid = sv[i].id; }

}

Task 3:

-Flow chart diagrams for finding max grade:

Trang 8

g g g

Trang 9

Start

Max = [0]; sv i = 0 to n - 1

Trang 10

-Flow chart diagrams for finding m grade: in

End

Trang 11

Start

Min = sv[0]; i = 0 to n - 1

Trang 12

-Review / evaluate my design:

+pros: The program looks easy to understand and full of requirements +cons: The program is still too simple and lacks clarity

End

Trang 13

+which needs to improve: Added more features to be more clear

Test plan:

1 Validation of input Enter integer number to the menu input

Number from 1 to 6 and other numbers

from 1 to 6: excepted, other numbers will tell the user “no option”and “try again”

2 Validation of input name Enter character

student’name Any letters Show successfully and correct student name

3 Accurate calculations of finding max grade

Enter float student’s grade

Trang 14

#include<stdio.h> #include<string.h> #include<math.h> using namespace std; struct student {

int id;

Trang 15

float grade,math,phys,chemis; char name[30];

};

void input(student sv[100],int &n); void output(student sv[100],int &n); void menu(student sv[100],int n); void max(student sv[100],int n); void min(student sv[100],int n); void increase(student sv[100],int &n); void decrease(student sv[100],int &n); int main()

{

student sv[100]; int n;

menu(sv,n); return 0; }

void menu(student sv[100],int n){

Trang 16

int a; do{

cout<<" MENU \n";

cout<<"1: input information student\n"; cout<<"2: output information student\n"; cout<<"3: max average grade\n"; cout<<"4: min average grade\n";

Trang 17

cout<<"5: average grade increase\n"; cout<<"6: average grade decrease\n"; cout<<"> 7: out of the menu\n"; cout<<" CHOSE OPTION: "; cin>>a;

switch (a) {

case 1:

input(sv,n); break;

case 2:

output(sv,n); break;

case 3:

max(sv,n);

Trang 18

break;

case 4:

min(sv,n); break; case 5:

increase(sv,n);

Trang 19

output(sv,n); break; case 6:

decrease(sv,n); output(sv,n);

break; default:

} while (a < 6); }

void input(student sv[100],int &n){ cout<<"\ninput number student: "; cin>>n;

Trang 20

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

cout<<"\nStudent "<<i+1; cout<<"\ninput id "; cin>>sv[i].id; cout<<"input name: "; fflush(stdin); gets(sv[i].name);

Trang 21

cout<<"physics grade: "; cin>>sv[i].phys; cout<<"math grade: "; cin>>sv[i].math; cout<<"chemistry grade: "; cin>>sv[i].chemis; cout<<"\n"; }

cout<<"\nName student: "<<sv[i].name; cout<<"\nphysics grade: "<<sv[i].phys; cout<<"\nmath grade: "<<sv[i].math; cout<<"\nchemistry grade: "<<sv[i].chemis;

Trang 22

sv[i].grade = (sv[i].phys + sv[i].math + sv[i].chemis) / 3; cout<<"\naverage grade: "<<sv[i].grade<<"\n\n"; }

}

void max(student sv[100],int n){ float max = sv[0].grade; int maxid = sv[0].id;

Trang 23

for(int i = 0;i < n;i++){ if(max < sv[i].grade){

max = sv[i].grade; maxid = sv[i].id; }

if(min > sv[i].grade){ min = sv[i].grade; minid = sv[i].id; }

}

cout<<"\n\nMIN AVERAGE GRADE: "<<min<<"\nID: "<<minid<<endl<<endl;

Trang 24

}

void hoanvi(student &x,student &y){ student temp;

temp = x; x = y; y = temp; }

Trang 25

void increase(student sv[100],int &n){ for(int i = 0; i < n;i++){

for(int j = i+1;j < n;j++){

if(sv[i].grade > sv[j].grade){ hoanvi(sv[i],sv[j]); }

} }

cout<<"\n -GRADE INCREASE: "; }

void decrease(student sv[100],int &n){ for(int i = 0; i < n;i++){

for(int j = i+1;j < n;j++){

if(sv[i].grade < sv[j].grade){ hoanvi(sv[i],sv[j]); }

} }

Trang 26

cout<<"\n -GRADE DECREASE: "; }

Ngày đăng: 09/05/2024, 14:14

Tài liệu cùng người dùng

Tài liệu liên quan