(COM 211) Computer Programming in Basic FT. Assignment
(COM 211) Computer Programming in Basic FT. Assignment
COM 211
ASSIGNMENT
1
1(A) i. The Sequence Structure
flowchart above demonstrates a sequence of steps. The reader would start at the Start shape and
follow the arrows from one rectangle to the other, finishing at the End shape. A sequence is the simplest
flowcharting construction. You do each step in order. if your charts are all sequences, then you probably
don't need to draw a flowchart. You can type a simple list using your word processor. The power of a
flowchart becomes evident when you include decisions and loops.
RFFlow allows you to number your shapes if you wish. Run RFFlow and click on Tools, Number Shapes,
and put a check mark in Enable numbers for the entire chart. You can also choose to have a number or
not in each individual shape and you can quickly renumber your chart at any time.
This structure is called a decision, "If Then.. Else" or a conditional. A question is asked in the decision
shape. Depending on the answer the control follows either of two paths. In the chart above, if the
temperature is going to be less than freezing (32 degrees Fahrenheit) the tomatoes should be covered.
Most RFFlow stencils include the words "Yes" and "No" so you can just drag them onto your chart.
"True" and "False" are also included in most of the flowcharting stencils
2
(iii) Repetition Structure
Repetition : A sequence of steps which are repeated a number of times is called repetition. For a
repeating process to end, a decision must be made. The decision is usually called a test. The position of
this test divides repetition structures into two types : Pre-test and Post-test repetitions.
Pre-test repetitions (sometimes called guarded loops) will perform the test before any part of the loop
occurs. (sometimes called un-guarded loops) will perform the test after the main part of the loop (the
body) has been performed at least once.
3
A traffic lights example follows :
The terms class and object are sometimes used interchangeably, but in fact, classes describe the type of
objects, while objects are usable instances of classes. So, the act of creating an object is called
instantiation. Using the blueprint analogy, a class is a blueprint, and an object is a building made from
that blueprint.
To define a class:
VB
4
Class SampleClass
End Class
Visual Basic also provides a light version of classes called structures that are useful when you need to
create large array of objects and do not want to consume too much memory for that.
(ii)Inheritance
Inheritance enables you to create a new class that reuses, extends, and modifies the behavior that is
defined in another class. The class whose members are inherited is called the base class, and the class
that inherits those members is called the derived class. However, all classes in Visual Basic implicitly
inherit from the Object class that supports .NET class hierarchy and provides low-level services to all
classes.
VB
Class DerivedClass
Inherits BaseClass
End Class
By default all classes can be inherited. However, you can specify whether a class must not be used as a
base class, or create a class that can be used as a base class only.
VB
End Class
3(a). Identifier type characters, Literal type characters, Hexadecimal, binary, and octal literals
5
And use everage formula
a=5;
b=7;
c=5;
d=8;
Float ave;
ave=a +b+c+d+/4
Print(“average=”ave)
4(a). The three step involves setting up user interface, defining the properties, and creating code
In planning: Design the user interface: When you plan the user interface, you draw a sketch of screens
the user will see when running your project. On your sketch, show the forms and all the controls that
you plan to see. Indicate the name that you planed to give the form and each of objects on the form.
Plan the properties: For each object, write down properties that you plan to set or change during the
design of the form.
Plan the basic code: This step is where you plan procedures that will execute when your project runs.
You will determine which events require action to be taken and then make a step-by-step plan for those
actions
In programming:
After you have completed the planning steps and have agreement form your user, you are ready to
begin the actual construction of the project. You will use the same three steps process that you used for
planning.
Define the user interface: When you define the user interface, you create the forms and controls that
you designed in planning stage.
Set the properties: When you set the properties of objects, you give each object name and define such
attributes as the contents of the label, the size of text, and the words that appear on the top of
command button and in the form’s title bar.
Write the Basic Code: You will use Basic programming statements to carry out the actions needed by
your program. You will be surprised and pleased by how few statements you need to create powerful
Windows program.
6
(b). Default: A default property is a class or structure property that your code can access without
specifying it. When calling code names a class or structure but not a property, and the context allows
access to a property, Visual Basic resolves the access to that class or structure's default property if one
exists.
A class or structure can have at most one default property. However, you can overload a default
property and have more than one version of it.
To declare a default property
Declare the property in the normal way. Do not specify the Shared or Private keyword.
Include the Default keyword in the property declaration.
Specify at least one parameter for the property. You cannot define a default property that does
not take at least one argument.
(ii)Implicit: If a name appears in a program and is not explicitly declared, it is implicitly declared. The
scope of an implicit declaration is determined as if the name were declared in a DECLARE statement
immediately following the PROCEDURE statement of the external procedure in which the name is used.
With the exception of files, entries, and built-in functions, implicit declaration has the same effect as if
the name were declared in the outermost procedure. For files and built-in functions, implicit declaration
has the same effect as if the names were declared in the logical package outside any procedures
(iii)Explicit: Forces explicit declaration of all variables in a file, or allows implicit declarations ofvariables.
On
Optional. Enables Option Explicit checking. If On or Off is not specified, the default is On.
Off
Optional. Disables Option Explicit checking.
When Option Explicit On or Option Explicit appears in a file, you must explicitly declare all variables by
using the Dim or ReDim statements. If you try to use an undeclared variable name, an error occurs at
compile time. The Option Explicit Off statement allows implicit declaration of variables.If used, the
Option Explicit statement must appear in a file before any other source code statements.