Bbit 222 Assignment
Bbit 222 Assignment
(b) With illustrations describe the following terms as used in structured programming.
(8 Marks)
(i) Function- allows programmers to pass a single or entire structure information to or
from a function. Example ;
#include <stdio.h>
#include <string.h>
Struct student
{
Int id;
Char name[20];
Float percentage;
};
Int main()
{
Struct student record;
Page 1 of 5
Record.id=1;
Strcpy(record.name, “Raju”);
Record.percentage = 86.5;
Func(record);
Return 0;
}
#include <stdio.h>
Int main () {
Int n[ 10 ];
Int I,j;
For ( I = 0; I < 10; i++ ) {
N[ I ] = I + 100; /* set element at location I to I + 100 */
}
For (j = 0; j < 10; j++ ) {
Printf(“Element[%d] = %d\n”, j, n[j] );
}
Return 0;
Page 2 of 5
(iii) Pointer - A pointer is a variable whose value is the address of another variable, i.e.,
direct address of the memory location. Example
#include <stdio.h>
Int main () {
Return 0;
}
(iv) Structure - The struct statement defines a new data type, with more than one
member. Example sytax
Struct Books{
Char title[50];
Char author[50];
Char subject[50];
Int book_id;
}
book;
Page 3 of 5
(c) Explain THREE ways of implementing the looping structure in C++ programming language.
(6 Marks)
While loop- Repeats a statement or group of statements while a given condition is true. It
tests the condition before executing the loop body.
for loop - Execute a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
do...while loop - Like a ‘while’ statement, except that it tests the condition at the end of
the loop body.
Page 4 of 5
(e) Describe any THREE program control structures as used in structured programming.
(6 Marks)
If else -If the Boolean expression evaluates to true, then the if block will be executed,
otherwise, the else block will be executed.
If-then - statement is the most basic of all the control flow statements. It tells your
program to execute a certain section of code only if a particular test evaluates to true
Do…while - is similar to a while loop, except the fact that it is guaranteed to execute at
least one time.
Page 5 of 5