Oxford Information Technology for CSEC Third edition: We continue with pages 138 to 150.
Information Technology for CSCE Examinations 3rd Edition: We continue with pages 161 to 176
Please read these pages if you can in order to continue with you studies during this week.
As you know, school is currently closed. You are not required to read the information above. However, I feel like the majority of students will at least give it a try as long as your personal situation is comfortable for you to make that attempt.
For those of you who cannot read the notes at this point in time, do not worry!!!
When school officially restarts, we will definitely cover the content. In the meantime, keep safe and keep your mind engaged!
Form our discussion. We see that in a real life stack, the most recent item to enter the stack is the first to be processed and leave the stack.
We say that the Last item In is the First item Out (LIFO)
The stack ADT consists of a collection of items and an integer which keeps track of the size of the stack.
The stack supports the following operations:
Operation
Explanation
Push(…)
Adds an item to the top of the stack and returns the size of the stack. If an error occurs, return a negative number
Peek()
Return the data at the top of the stack
Pop(…)
Removes and Returns the item at the top of the stack, keeping track of the size.
IsEmpty()
Returns true if the stack is empty, i.e, size==0
NB, When using a stack, the programmer only has access to the item stored at the top/head of the stack at any given point in time. The programmer is unable to access any other data that is stored under the top.
The top of the stack is also referred to as the head of the stack.
Coded example
Stack.h
#include <stdbool.h>
#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED
//push data if the stack is not full
bool push(int newData);
//returns the +ve integer at the
//top of the stack or -1 if the stack is empty
int peek();
//Removes and returns the +ve integer at the
//top of the stack or -1 if the stack is empty
int pop();
//returns the current size of the stack
int size();
//returns true if the stack is empty
bool isEmpty();
#endif // STACK_H_INCLUDED
Stack.c
#include <stdbool.h>
#include <stdio.h>
#define MAX_SIZE 10
#include "Stack.h"
int stackData[MAX_SIZE];
int sizeOfStack = 0;
bool push(int newData)
{
if(sizeOfStack==MAX_SIZE)
{
puts("ERROR: Tried to push to a full stack. Operation failed\n");
return false;
}
else
{
stackData[sizeOfStack]=newData;//add data to the next available location
sizeOfStack++;//increment size
return true;
}
}
int peek()
{
if(isEmpty())
{
puts("ERROR: Tried to peek at an empty stack. -999999 returned as result\n");
return-999999;
}
else
return stackData[sizeOfStack-1];//return item at the top of the stack
}
int pop()
{
if(isEmpty())
{
puts("ERROR: Tried to pop an empty stack. -999999 returned as result\n");
return -999999;
}
else
{
int result = stackData[sizeOfStack-1];//return item at the top of the stack
sizeOfStack--;//reduce size
return result;
}
}
int size()
{
return sizeOfStack;
}
bool isEmpty()
{
return sizeOfStack==0;
}
The stack ADT consists of a collection of items and an integer which keeps track of the size of the stack.
to:
STATE The stack ADT consists of a collection of items and two integers, top – used to keep track of the top of stack, and size which keeps track of the size of the stack.
BEHAVIOUR The stack supports the following operations:.....
Previously we’ve dealt with primitive datatypes in C.
Examples of some primitive data types are shown below:
Data Type
Example
integer
int a=5;
Floating point numbers
float a=5.1;
Character
char input =’q’;
In this case we see that only one item of data is stored per variable declared.
Abstract Data Types (ADTs) store collections of data and are accompanied by functions which perform operations on the data.
They are created for use by programmers who in turn manipulate the data collection by use of the provided functions. The programmer using the ADT is never expected to directly manipulate the collection of data.
ADTs are used to model collections of data in real world scenarios.
An ADT consists of :
State- The container of items itself, information about the container of items e.g the size, a reference to the first item in the list etc
Behaviour – The operations that can be performed on the collection of data. Usually adding and/or, updating, and/or removing items.
The array is the considered to be a basic abstract data type that was formalized to use indexing during the development of high level languages. supporting programs were built to allow for the creation and management of data access to arrays.
If you’ve previously created c structures and managed their use through functions then you’ve created a specialized ADT. For example, our book catalog is an ADT.
A seemingly unlikely ADT example: The array
Even though assignment and retrieval of data in array seems trivial and is supported by basic syntax as with other primitive data types; this was not the case during the early development of programming languages.
High level programming languages were modified so that arrays could use the basic syntax of variable declaration, initialization, assignment and access because of their expected widespread use.
Updates to this post
4th June 2024 – -Added “Updates to this post” as a section
Creating a button to submit a Word processing Form as an email Attachment
From the developer tab select Command Button:
Change the button’s name:
Right click on the button and select edit:
The button text now becomes editable, change it to what best describes the button. In this case, the text was changed to “Save Document and Send via Email”:
(The text was too long, so the button was widened to display all text.)
Set up the button to send the email when clicked:
Right Click the button and choose view code:
A visual basic window will popup. This gives a place to put some code that will be executed when the button is clicked
Such that it is within the button click sub routine:
You may now close the Visual Basic window.
Now , when the button is clicked, you computer’s default mail client will be opened with the form attached for sending via email.
Note that the method above does not allow for setting a recipient’s address in the opened mail client. If you would like to specify a recipient address and email subject, use the following code within the click subroutine:
Activedocument.HasRoutingSlip = True
With Activedocument.RoutingSlip
.Subject = "New subject goes here"
.AddRecipient "Firstaddress@Mail.com"
.AddRecipient "Secondaddress@Mail.com"
.Delivery = wdAllAtOnce
End With
Activedocument.Route
This is a precise and concise definition of a problem stating what needs to happen to transform from the current state of things to the desired future state. The problem definition should address the inputs to the problem and the desired outcome.
Problem Analysis
We determine:
Input
what data needs to be recorded/managed by our solution;
Processing
What events need to occur during the use of the solution,
the rules for manipulating/processing the data in our solution;
Output
and what data and files our solution needs to deliver to the end user and save for future use.
Identify and evaluate possible solutions
Multiple approaches may be used to solve the problem, thus many solutions may be generated.
Identify and evaluate possible solutions
Multiple approaches may be used to solve the problem, thus many solutions may be generated. Each solution’s comparative strength and weakness is documented at this point.
Select and justify the optimal solutions;
Of all solutions generated, we select the one which is most optimal and best suited to solve the problem.
The optimal solution is chosen based on criteria which point to the most efficient solution based on speed, storage capacity and generally how good the solution is suited against the problem statement/definition.
A detailed algorithm of the best solution is the output of the process.
Implementation and review
Implementation: The algorithm is implemented in code and placed in the environment of its intended and made accessible to users.
Review : To determine any unforeseen issues:
The implementation is observed in its environment.
Feedback is elicited from users.
After the initial review phase, any major issues are fixed.
We compare our solution back to our original problem statement to verify the problem has indeed been solved.
Implementation Review then continues in the form of maintenance where additional feedback is gathered to improve the solution which is implemented at a reasonable future date.
Summary
Problem definition – A concise definition of the problem is made which decribes what the future solution should do
problem analysis – determine all details that are needed to solve the problem, e.g processes, procedures, data etc.
Identify and evaluate possible solutions – generate many solutions and learn each solutions strength and weaknesses compared to each other.
Select and justify the optimal solutions – choose the optimal solution based on criteria which point to the most efficient solution based on speed and storage capacity.
Implementation and review – the solution is created and reviewed to determine any issues that prevents it from solving the problem. The issues, if any are fixed so that the problem is now completely solved.
Algorithms are used to solve computational problems and are a technique for precisely documenting the solution.
Part B
i) Bounded, since the number of iterations are constant every time the algorithm is applied. In this case, the loop is executed 16 times.
ii) Unbounded, since the number of iterations is not set and is dependent on the value of a sentinel variable, in this case X
Part C)
START
rcount, bcount,gcount,ncount <--0
for i<-- 1 to 150 do
input vote
if (vote = "red") then
rcount++
else if (vote = "green") then
gcount++
else if (vote = "blue") then
bcount++
else
ncount++
endif
endfor
output "total votes for color = " + rcount+gcount+bcount
output rcount " voted for red"
output bcount " voted for blue"
output gcount " voted for green"
END
A mail merge is the term used when a database of recipients and other fields are placed (or merged) onto a template letter to produce a mass mailing.
Basically , a template document is created using a list of names. e.g:
Template Document (Primary Document)
List of names (Data source or Secondary Document)
Steps to create a mail merge
These steps vary silghtly from version to version of microsoft word, but the principle is the same. In this case, I’m using the version of microsoft word as current as January 2020.
Create a new document
write and format the basic idea for your letter
save your document. This document is your Primary Document (Template).
Click on Mailings -> Select recipients -> Type new list.
Use the “New Entry” button to add new records. Add as many as you need.
Click on “ok”. Save your list. This document is your secondary document (Data Source).
Finally, from the mailings ribbon, click on Finish and merge -> Edit individual documents. This creates a new document from the previous two. This document is your Merged document (Mass mailing).