Recall that Software is a set of instructions that can be executed by a computer system. System software is used to maintain hardware resources, while application software solves end user problems.
There are, however, other categories of software which are meant to be malicious and disruptive to the computer system.
Copyright is a legal right created by the law of a country that grants the creator of an original work exclusive rights for its use and distribution. This is usually only for a limited time.
Presentation software is used to display information one slide at a time. The term “slide” can be thought of as a single poster used to display a small number of points or a single idea.
Presentation software was made to mimic the behaviour of a traditional slide projector.
Many slides are displayed one at a time by the presenter. The presenter can include the following items on slides:
Text – including short points on the topic being presented. Text is usually held within a Textbox.
Shapes – including pre defined shapes e.g circle, square etc.
Images: users can insert downloaded images, or provided clip art.
Charts: the presentation software provides facilities for creating and inserting various chart types including bar, line, pie charts etc.
Animations – Objects can be set in motion on any slide. Objects include images, shapes, text boxes etc.
Transitions – Slides transform from one to the next in one smooth animation.
Example of presentation software are Microsoft Powerpoint and Prezi.
Having studied the principle of a stack, we will list the principle of operation for a queue:
A queue models a real-life queue, for example, a queue (line) of people in a cafeteria waiting to order and pay for food.
The queue (line) of people can be thought of as a list with a :
Head or Front– the first person in the line, and the first to be served.
Tail or End – the last person in the line and the last to be served.
Every time an lunch order is processed, the head of the queue leaves the line, the entire line moves up , and the next person becomes the new head.
The queue ADT consists of a list of items and at least 3 reference variables which keep track of the location of the head, tail and the size of the queue. Operations on the queue are shown below:
Operation
Explanation
Example
Add(..) or Enqueue(..)
Adds/Enqueues an item to the end of the queue and updates the tail to point to the newly added item. if the queue is full, the item is not added and an error message displayed. If the queue is empty, add the new item at the head. In this case the head and tail point to the newly added item.
A person joins the end of the line at the cafeteria. If the line is full, the person cannot enter the line. If the line is empty, the person goes straight to the head, i.e the cash register.
Remove(..) or Dequeue(..)
Removes/Dequeues and returns the item at the head of the queue. If the que is empty, the remove operation fails , an error message is displayed. An appropriate dummy/null value is returned.
Accept payment from the person at the cash register and send them on their way. If there are more people in the line, the line moves up and the person at the front of the line is at the cash register.
Peek(..)
returns the item at the head of the queue. If the que is empty, the peek operation fails , an error message is displayed. An appropriate dummy/null value is returned.
Size(…)
Returns the size of the queue
IsEmpty()
Returns true if the queue is empty, i.e, size==0
Characteristics of a Queue
In creating a coded implementation of a queue using an array, we observe the following characteristics:
State:
Variable
Description
Value at initialization
size
Integer to keep track of the size f the queue.
0
head
Integer to keep track of the front of the queue. This value stores the array index of the head/front
0
tail
Integer to keep track of the tail/end of the queue. This value stores the array index of the tail/end
-1
MAX_SIZE
This stores he maximum size of the array; the array length
Sufficiently large, chosen by the programmer.
Behavior:
Items are added/enqueued using the tail index, items are removed/dequeued using the head index.
During the enqueue operation
If the queue is full
Cannot add, display error message
Else
Increment tail index
Place new data at tail index
Increment size
During the dequeue Operation
If the queue is empty
Display error message, return dummy value e.g -999
Else
Store the data that was at the head in a new variable, X
Increment the head index
Decrement size
Return X
During the Peek Operation
If the queue is empty
Display error message, return dummy value e.g -999
When processing text data , either from a text file or input entered via the keyboard, we sometimes need to check the data to see if it’s an integer first, then use it for processing.
In this example, we ask our user to enter a valid integer and we output the square of the integer:
/*
we ask our user to enter a valid integer
and we output the square of the integer
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int inputInteger; //string used to store user input
int inputSquared;// used to store the square of a valid integer.
printf("Enter an Integer value....\n");
scanf("\n%d",&inputInteger);//get input from user
printf("You entered : %d\n", inputInteger);
inputSquared = inputInteger*inputInteger;//find square
printf("\n%d squared is %d\n",inputInteger, inputSquared);
printf("\nSuccess! Exiting program\n");
return 0;
}
This code works when we enter valid input , in this case the user enters 12:
However, if the user enters alpha text data, we get strange results:
A simple fix…
To fix this issue we adhere to 2 rules:
Read all text data as character strings, and then
use the atoi(…) function to convert the string to a valid integer
The previous example can be fixed by using the rules above applied to the current situation:
Read all text data as character strings, and then
use the atoi(…) function to TRY to convert the string to a valid integer
If the user had entered alpha text data, generate an error message, prompt the user to re-enter the data, and go to step 1, otherwise :
Calculate the valid output.
Below is the code…
/*
this programs shows how to validate user input as integers.
if the user enters a valid integer, we output the square of the integer,
otherwise we output an error message and prompt the user to re enter a valid integer
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> //in order touse true and false
int main()
{
char input[50]; //string used to store user input
int inputAsAnInteger;//used store the converted input as an integer
int inputSquared;// used to store the square of a valid integer.
while(true)//loop 'infinitely'
{
printf("Enter an Integer value....\n");
scanf("%s",&input);//get input from user
printf("You entered : %s\n", input);
inputAsAnInteger=atoi(input);//convert input to integer
if (inputAsAnInteger==0)//if the input is not a number......
{
printf("Invalid input entered\n\n");
}
else//input is a number
{
inputSquared = inputAsAnInteger*inputAsAnInteger;//find square
printf("\n%d squared is %d\n",inputAsAnInteger, inputSquared);
printf("\nSuccess! Exiting program\n");
break;//exit 'infinite' loop.
}
}
return 0;
}
And a sample run shown below with invalid input and valid input:
However, note that atoi(…) returns 0 when 0 is entered or invalid input entered, an edge case which produces erroneous results:
Fixing the fix…
This problem can be solved by checking every digit in the input string to see if they are all digits, before converting to string. In this way, we cater for a correct result if the text data “0” is entered.
Our rules to fix the problem now becomes:
Read all text data as character strings, and then
Check eack character of the string to ensure they’re all digits, then
use the atoi(…) function to convert the string to a valid integer
This code uses a function which performs that check:
/*
this programs shows how to validate user input as integers.
if the user enters a valid integer, we output the square of the integer,
otherwise we output an error message and prompt the user to re enter a valid integer
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> //in order to use true and false
#include <ctype.h> // in order to use the isdigit function.
bool isNumber(char* stringArray);
int main()
{
char input[50]; //string used to store user input
int inputAsAnInteger;//used store the converted input as an integer
int inputSquared;// used to store the square of a valid integer.
while(true)//loop 'infinitely'
{
printf("Enter an Integer value....\n");
scanf("%s",&input);//get input from user
printf("You entered : %s\n", input);
if (!isNumber(input))//if the input is not a number......
{
printf("Invalid input entered\n\n");
}
else//input is a number
{
inputAsAnInteger=atoi(input);//convert input to integer
inputSquared = inputAsAnInteger*inputAsAnInteger;//find square
printf("\n%d squared is %d\n",inputAsAnInteger, inputSquared);
printf("\nSuccess! Exiting program\n");
break;//exit 'infinite' loop.
}
}
return 0;
}
bool isNumber(char* stringArray)
{
//go through each character
//location in the array until
//we reach the null character (end of input)
for (int i = 0; stringArray[i]!='\000'; i++)
{
if(isdigit(stringArray[i])==0)//if the current character is not a digit....
return false; //return false and end function here
}
return true;//return true since the entire array contained numeric characters
}
Now, we get correct results in all cases:
Conclusion And Thoughts
The basic strategy for checking for integer input, is to read all input as text and use the atoi(…) function to try converting the input whilst performing error checking.
To best understand the coded examples, I insist that you use the data in the sample runs to :
perform a dry run as well as
step through each line of code by running the code in debug mode .
The examples above contain minimal explanation, is intended pre-class preparation and presentation in our classroom where we can have a broader discussion and I can answer any questions that you may have.
So, here’s the thing – creating a virtual classroom for student access is a lot like giving every student a key to your classroom. Yep.
Imagine a physical classroom , say Peter’s Chem Lab, for example. Peter’s Chem Lab is physically locked. With a padlock. The students that belong to you want to be able to enter Peter’s Chem Lab are each given their own key to the padlock. That’s about as far as this analogy goes for an introduction.
Step 1
From your classroom home, Click on the plus –> Create Class
Step 2
Add the details to your class. In this example, I have students from forms 4N, 4A and 4P assigned to me doing IT. On my Timetable it’s labelled Option D.
After adding all details, click on Create .
Step 3 – Done!
The class has been created and google classroom give you tutorial prompts on how to get started . The first prompt is the “key” to your classroom.
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:.....