















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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This is a document about the subject PROG 102 - Assignment 1
Typology: Essays (university)
1 / 23
This page cannot be seen from the preview
Don't miss anything!
Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 0 : 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
P1 P2 P3 M1 M2 D
ļ² Summative Feedback: ļ² Resubmission Feedback:
Grade: Assessor Signature: Date:
Lecturer Signature:
A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks. The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal.
Each programming language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions.
1.2.2 / Key Features of Procedural Programming
The key features of procedural programming are given below:
ļ· Predefined functions: A predefined function is typically an instruction identified by a name. Usually, the predefined functions are built into higher-level programming languages, but they are derived from the library or the registry, rather than the program. One example of a pre-defined function is ācharAt()ā, which searches for a character position in a string.
ļ· Local Variable : A local variable is a variable that is declared in the main structure of a method and is limited to the local scope it is given. The local variable can only be used in the method it is defined in, and if it were to be used outside the defined method, the code will cease to work.
ļ· Global Variable : A global variable is a variable which is declared outside every other function defined in the code. Due to this, global variables can be used in all functions, unlike a local variable.
ļ· Modularity : Modularity is when two dissimilar systems have two different tasks at hand but are grouped together to conclude a larger task first. Every group of systems then would have its own tasks finished one after the other until all tasks are complete.
ļ· Parameter Passing: Parameter Passing is a mechanism used to pass parameters to functions, subroutines or procedures. Parameter Passing can be done through āpass by valueā, āpass by referenceā, āpass by resultā, āpass by value-resultā and āpass by the nameā.
1.2.3/ Advantages and Disadvantages of Procedural
Programming
Procedural Programming comes with its own set of pros and cons, some of which are mentioned below.
Advantages
ļ· Procedural Programming is excellent for general-purpose programming ļ· The coded simplicity along with ease of implementation of compilers and interpreters ļ· A large variety of books and online course material available on tested algorithms, making it easier to learn along the way ļ· The source code is portable, therefore, it can be used to target a different CPU as well ļ· The code can be reused in different parts of the program, without the need to copy it ļ· Through Procedural Programming technique, the memory requirement also slashes ļ· The program flow can be tracked easily
Disadvantages
ļ· The program code is harder to write when Procedural Programming is employed ļ· The Procedural code is often not reusable, which may pose the need to recreate the code if is needed to use in another application ļ· Difficult to relate with real-world objects ļ· The importance is given to the operation rather than the data, which might pose issues in some data-sensitive cases ļ· The data is exposed to the whole program, making it not so much security friendly
Conclusion
As we stated throughout this article, Procedural Programming is more of what you are doing than how you are doing it. It is the standard approach used in many computer languages such as C, Pascal, and BASIC. While there is no perfect programming paradigm, it is important to understand that the correct paradigm will always depend on the type of language you use and the program you wish to create. It is advised that for maximum results and a strong portfolio, one should have proficiency in all three major programming paradigms. The best way to try to get better at programming paradigms is to try, and Hackr can help you with that. (Bhatia, n.d.)
Beal, V., n.d. webopedia. [Online] Available at: https://www.webopedia.com/definitions/programming-language/ [Accessed 26 October 2021].
Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The types in C can be classified as follows
The array types and structure types are referred collectively as the aggregate types. The type of a function specifies the type of the function's return value. We will see the basic types in the following section, where as other types will be covered in the upcoming chapters.
The following table provides the details of standard integer types with their storage sizes and value ranges
E.g: int n=10;
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.
The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision
E.g:
switch (choice)
{
case 1: {
input(st, n);
break;
}
case 2: {
output(st, n);
break;
}
case 3: {
maxgrade(st, n);
break;
}
case 4: {
mingrade(st, n);
break;
}
}
Switch structure can be used in place if-else-if statements
Used in situations where the expression being evaluated results in multiple values.
In report, I will use it to declare different options which teacher choose to report in āMenuā. It include will have 4 options:
Do-while structure:
do
{
cout<<"\n\n\n\t\t--MENU--";
cout<<"\nnhap option:";
cout<<"\n***************************************\n";
cout<<" 1. Nhap ds sv \n ";
cout<<" 2. Xuat ds sv \n ";
cout<<" 3. In diem max ds sv \n ";
cout<<" 4. In diem min ds sv \n ";
cout<<" 5. Thoat chuong trinh! \n ";
cout<<"\nLua chon cua ban: ";
cin>>a;
switch(a)
{
2.4/ iteration constructs:
For statement:
E.g: for(initialization; condition; increment/ decrement);
for(int i=0; i<n; i++)
{
cout<<"\nNhap thong tin cho sv thu "<<i+1<<"";
cout<<"\nNhap ma so SV: ";
cin>>st[i].id;
cout<<"\nNhap ten SV: ";
fflush(stdin);
gets(st[i].name);
cout<<"\nNhap diem: ";
cin>>st[i].grade;
}
Here, after entering the information of students.
2.5/ Sub-functions:
Input information of students:
void input(student st[100],int &n)
{
cout<<"Nhap so luong sinh vien: ";
cin>>n;
for(int i=0; i<n; i++)
{
cout<<"\nNhap thong tin cho sv thu "<<i+1<<"";
cout<<"\nNhap ma so SV: ";
cin>>st[i].id;
cout<<"\nNhap ten SV: ";
fflush(stdin);
gets(st[i].name);
cout<<"\nNhap diem: ";
cin>>st[i].grade;
}
}
Lowest grade:
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;
}
2.6/ Hierarchy diagram:
MENU
INPUT
INPUT THE NUMBER OF STUDENT S
INPUT THE STUSENTS ID
INPUT STUDENTā S NAME
INPUT STUDENTā S MATH AND IT SCORE
INPUT LIST OF STUDENTS
ENTER A STUNDENT
DISPLAY HIGHEST AVERAGE SCORE
DISPLAY LOWEST AVERAGE SCORE GRADE
DISPLAY A STUDENT
PRINT LISTS OF STUDENTS
INFORMATION OF STUDENTS
PRINT STUDENT ID
PRINT STUDENT NAME
PRINT STUDENT SCORE
Start
cout<<"\n\n\n\t\tMENU"<<endl;
cout<<"\n***************************************\n";
cout<<"* 1. print ID and grade of student *\n";
cout<<"* 2. Find maximum grade *\n";
cout<<"* 3. Find minimum grade *\n";
cout<<"* 4. Exit *\n";
cout<<"****************************************"<<endl;
do {
cout<<"you choice: ";
cin >> choice;
END
3.2.2/ Input Studentās ID, name and grade.
Start
{
cout<<"\nNhap ma so SV: ";
cin>>st[i].id;
cout<<"\nNhap ten SV: ";
fflush(stdin);
gets(st[i].name);
cout<<"\nNhap diem: ";
cin>>st[i].grade;
}
char Name[50];
int id;
float grade;