Selection Statements: Practise Exercise(s)

For these flowchart solutions, you may opt to:

  1. Draw the solution in your notebook OR
  2. Draw the solution in a word processing document OR
  3. Draw the solution in an online tool OR
  4. Create a solution using flowgorithm.

Exercise 1

Create a flowchart solution which prompts the user to enter a student’s math mark and outputs “You have passed” if the mark is 50 and/or greater or “You have failed” if the mark is less than 50.

Exercise 2

Create a flowchart solution which prompts the user to enter two numbers, A and B, and outputs the larger number.


© 2020  Vedesh Kungebeharry. All rights reserved. 

Videos: Search/Replace, Tables, Columns

These video(s) were chosen for each topic because they cover the subject matter in a relevant context. They definitely were not created specifically for the CSEC Syllabus, however , they do address the fundamental concepts in real world scenarios and classroom context.

 3. use appropriate editing features to structure and organize a document; Drag and drop editing: perform block operations on selected areas of text within a document.

Use search and replace functions appropriately to edit a document.

Use of tables, table styles, shading, borders, row and column insertion, split cells, split tables, text direction and cell margins, cell size.

Use of columns (one, two, three, left and right columns, column breaks).
        https://www.youtube.com/watch?v=8ZSlu4DWJ5k    

https://www.youtube.com/watch?v=XNBrCEgzddw    

    https://www.youtube.com/watch?v=X1n2VG1yxFs  

© 2020  Vedesh Kungebeharry. All rights reserved. 

Serial, Sequential, Direct (Random) Access

In this class we seek to understand the concept of logical storage for computer files stored on a physical medium.

Even though all data is stored as a sequence of zeros and ones not this binary data; we learned that this data can have some logical organization on the physical access medium.

Serial access is where data can only be accessed in the order that it was written. This is usually because of the inherent nature of the storage medium for example a magnetic tape.

Sequential access is a form of Serial access, when we organize our data in some order before storing the Data on the storage medium.

Direct access is where the location of the data on the storage medium is known beforehand, thus accessing a logical file on a direct access medium does not require accessing any other data but that specific file.

below is a video which demonstrates an analogy for data storage for direct access serial access and sequential access:

© 2020  Vedesh Kungebeharry. All rights reserved. 

Closure on Sequence with flow charts

Exercise 1 :

Modify previous example to find the average of four numbers. The previous example can be found below:

https://islandclass.wordpress.com/2020/11/02/flowchart-practise-finding-the-average-of-3-numbers/

Exercise 2:

Create a program which Prompts the user to enter a the radius of a circle and outputs the circumference and diameter.

Hint:

IPO Table

InputProcessing Output
radiusCircumference <– 2* Pi * radius
Area <– Pi * r * r
Circumference
Diameter
IPO Table

Exercise 3

Create a solution which prompts the user to enter the length and breadth of a rectangle and output the area.

Hint:

InputProcessingOutput
length, breadtharea<– length* breadtharea

© 2020  Vedesh Kungebeharry. All rights reserved. 

Videos: Data Validation And Verification

These video(s) were chosen for each topic because they cover the subject matter in a relevant context. They definitely were not created specifically for the CSEC Syllabus, however , they do address the fundamental concepts in real world scenarios and classroom context.

 differentiate  between  validation  and
verification of data;
 Difference between validation and
verification. 
 https://www.youtube.com/watch?v=wNMAtc_PzuI
 14. identify appropriate validation and verification checks given a particular scenario; and, Methods of validation: range check, reasonableness checks, data type checks, consistency checks, presence, format and length.

Methods of verification: double entry and proofreading (to identify and correct typographical and transpositional errors).
 https://www.youtube.com/watch?v=OeHe61pT9CI  

More Detailed:  https://www.youtube.com/watch?v=iS9tqYuVQ08

© 2020  Vedesh Kungebeharry. All rights reserved. 

Bubble Sort Implementation & Demonstration

Bubble Sort (Ascending)

  1. In this algorithm we compare  the first two adjacent items in the  list. If the first item is larger than the item next to it, we swap them, else we do nothing.
  2. This process (step1) is repeated until we have reached the end of the list.  At this point, the largest item is at the end of the list, we say it was “bubbled” up the list.
  3. Repeat step 1 and 2 for items 1 .. n-1, then 1 .. n-2 and so on until we reach 1..2

It seems difficult to understand but we can observe the algorithm in action in the following flowchart:

You can download the file here:

https://drive.google.com/file/d/1RvZ-dBvbHf0icL083d7vSnnce3_XDyyj/

Demonstration

See : https://youtu.be/KgqM6sC5Q4M

Exercise

Implement the algorithm in c with the following modifications:

  • The array stores double data
  • Print the array to the screen as a comma separated list before sorting.
  • Print the array to the screen as a comma separated list after sorting.

Challenge

Create a function with the following functions declaration which will sort any double array using bubble sort:

            void bubbleSort(double array[], int sizeOfArray);

© 2020  Vedesh Kungebeharry. All rights reserved. 

Hyperlinks

Definition: A hyperlink is actionable text or an object found in a hyper text document which navigates the user to the start of another hypertext document or a specific location within a hypertext document. An action could be from a gui : a click or a tap; or using the keyboard to press the “enter key” on a selected link.

Examples:

This is a hyperlink to wikipedia.org

This is a hyperlink to wikipedia.org opened in a new tab or browser.

This is a link to ……..

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

The Bottom Of The Page

This is a link to the top of the page

That is all!

© 2020  Vedesh Kungebeharry. All rights reserved. 

Flowchart Practise – Finding the average of 3 numbers.

Task

Create a flowchart algorithm which prompts the user to enter 3 numbers and outputs the average of the numbers.

Guided Solution

First, let us use an IPO Table:

InputProcessing Output
Three Numbers num1, num2, num3average=(num1+num2+num3)/3average

After considering what needs to be done, we see that we need 4 variables

Solution in flowgorithm:

Download the solution here

© 2020  Vedesh Kungebeharry. All rights reserved. 

Debugging and Refactoring exercise

0008.2

Definition: Debugging is the process of finding and fixing errors in program code.

Definition: Factoring (Decomposition) is the breaking of a complex task to its atomized sub parts. The goal of factoring is to reach a level of detail that can be represented in an algorithm and eventually programming code.  

Definition: Refactoring – Changing program code’s structure to improve readability or efficiency without changing it’s behavior; or, to change a code’s factoring

Instructions

Copy and paste the following code into the main.c file of  a new project:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main()
{
    float a,b,c,D,root1,root2;

    printf("Please enter a value for a...\n");
    scanf("%f",a);

    printf("Please enter a value for b...\n");
    scanf("%f",&b);

    printf("Please enter a value for c...\n");
    scanf("%f",&c);

    printf("\n");

    D=(b*b)-(4*a*c);


    if(D<0)
    {
        printf("no roots\n Exiting program...\n");
    }
    else if (D=0)
    {
        root1=(b*b)/(2*a);
        printf("Equation has only one root = %.2f \n Exiting program...\n ");

    }
    else
    {
        root1=((b*b)-sqrt(D))(2*a);
        root2=((b*b)+sqrt(D))/(2*a);
        printf("Roots are %.2f and %.2f \n Exiting program...\n",root1,root2);

    }
    return 1;




}

  1. Debug your program so that it produces correct results in all cases.
  2. Modify your code to use functions.
    • Move the code for calculating the Discriminant into another function. Do this by
      • Create a new function,which returns the value of the discriminant. The new function should implement the function declaration: float discriminant (acoef,bcoef,ccoeff);
      • Change the line which contains
        D=(b*b)-(4*a*c); to D=discriminant(a,b,c);
    • Move the code for calculating root 1 and root 2 into 2 separate functions. To do this, you must create suitable function declarations and accompanying function declarations which can accomplish the task.

© 2020  Vedesh Kungebeharry. All rights reserved. 

Introduction to functions

0008.1

Required reading: C functions (This is a link to an external website)

Exercise

Similar to our previous example, create a program which contains:

  1. A function which returns the area of a circle given its radius (assume all variables used are double)
  2. A Function which returns the volume of a circle given the radius(assume all variables used are double)
  3. A function which does not return any data and takes no parameters but outputs the author of your program .  Name your function Signature.

Solution

Note the function declarations.  This is necessary for proper execution of our code.

#include <stdio.h>
#include <stdlib.h>

//global variables
double area,volume;
double radius;
const double PI = 3.14;

//function declarations
double Area(double radius);
double Volume(double radius);
void Signature();

int main()
{
    //initialization
    area,radius,volume = -999;

    printf("enter radius\n");
    scanf("%lf", &radius);

    area    =   Area(radius);
    volume  =   Volume(radius);

    printf("The  Area is \t: \t%.2f\n",area);
    printf("The  Volume is \t: \t%.2f\n",volume);

    Signature();



}

double Volume(double radius)
{
    return((4/3)*PI*radius*radius*radius);
}

double Area(double radius)
{
    return (PI*radius*radius);
}

void Signature()
{
	//ASCII Art Generated using https://patorjk.com/software/taag/#p=testall&f=Big&t=kunge
    printf("Thanks for using my program!  \n");
    printf("  _  __                       \n");
    printf(" | |/ /                       \n");
    printf(" | ' /_   _ _ __   __ _  ___  \n");
    printf(" |  <| | | | '_ \ / _` |/ _ \ \n");
    printf(" | . \.|_| | | | | (_| |  __/ \n");
    printf(" |_|\_\__,_|_| |_|\__, |\___| \n");
    printf("                   __/ |      \n");
    printf("                  |___/       \n");
    printf("Author: Vedesh Kungebeharry   \n");
    printf("contact: VKunge@gmail.com     \n");
    printf("exiting...  \n");


}

© 2020  Vedesh Kungebeharry. All rights reserved.