Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
154 views

IntroductionToCh For ENME2CF Computer Fundamentals

The document provides an introduction to the Ch programming language and includes examples of Ch programs to calculate simple math problems, take user input, and demonstrate the use of variables, conditionals, and loops. It also explains basic syntax and functions of the Ch language.

Uploaded by

Tom Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views

IntroductionToCh For ENME2CF Computer Fundamentals

The document provides an introduction to the Ch programming language and includes examples of Ch programs to calculate simple math problems, take user input, and demonstrate the use of variables, conditionals, and loops. It also explains basic syntax and functions of the Ch language.

Uploaded by

Tom Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

http://www.softintegration.

com

Introduction to Ch for ENME2CF Computer


Fundamentals
What is Ch?
Ch is a user-friendly C/C++ interpreter for absolute beginners to learn C/C++. It helps students create
programs that tell computers, step-by-step, how to solve problems. Programs are behind all of the
computer applications you use every day.

Programs in Ch
Note: If asked to save your program, be sure to save it as a .ch file (e.g. ProgramName.ch). Once the
file is saved as .ch, Ch will be able to find and run your program. Additionally, Ch will know to
automatically color code your program for easier readability!

Program add.ch
Read through and run the program below to improve your understanding of how Ch stores values in
variables. Notice what happens when the same variable name is used to store more than one value.

Complete the following steps to run the program:


1. Type in the code below and save the file as a .ch file (e.g. ProgramName.ch)
2. Click on the Run menu at the top of the screen

1a) Predict the answer to the sum of x+y+z below. Then run the following program to test your
prediction:

/* File: add.ch */
int x, y, z; // initialize variables

x = 4; // assign variable values


y = 2;
z = 6; // the value of 6 is assigned to z
z = 2; // z no longer holds the value 6, the value of 2 is assigned to z

printf("%d\n", x+y+z); // prints the sum of x, y, and z to the screen

Use the table below as a guide to analyze Program 1:

Code Explanation

/* File: add.ch */ a) Comments with the file name add.ch

int x, y, z; b) Assign 4 into the variable x

x = 4; c) Assign 4 into the variable x

1
http://www.softintegration.com

y = 2; d) Assign 2 into the variable y

z = 6; e)

z = 2; f)

printf("%d\n", x+y+z); g)

Note:
● In the final line of program add.ch we also introduced notation \n, which tells Ch that we would
like it to start a new line before printing out the statement that follows.
● Use the format specifier “%d” in function printf() integer numbers.

2
http://www.softintegration.com
Program product.ch
Predict and run the program below, and work through the related tasks to improve your programming
skills.
Note: Quotation marks and commas are NOT optional in Ch. If Ch gives you an error message,
double check to make sure you included all quotation marks and commas!

2a) Predict what the program below will do. Then run the program to test your prediction:

/* File: product.ch */
int firstnumber, secondnumber, product; // declare variables

printf("enter the first number: "); // prints to the screen the message
scanf("%d", &firstnumber); // reads user input and stores into variable
printf("enter the second number: ");
scanf("%d", &secondnumber);

product = firstnumber*secondnumber; // compute the product

printf("%dx%d=%d\n", firstnumber, secondnumber, product);

Use the table below as a guide to analyze Program product.ch:

Code Explanation

int firstnumber, secondnumber, a)


product;

scanf("%d", &firstnumber); b) Store the value that the user enters into the
variable called firstnumber

scanf("%d", &secondnumber); c)

product = firstnumber*secondnumber d)

e)
printf("%dx%d=%d\n", firstnumber,
secondnumber, product);

Note:
● Use the format specifier “%d” in function scanf() for integer numbers.

Task 1: Create new variable names for ‘firstnumber’, ‘secondnumber’, and ‘product’. Be sure to
replace the variables ‘firstnumber’, ‘secondnumber’, and ‘product’ with your own variable names
each time they appear in the program.

Task 2: Change the program to multiply 3 input numbers and print the result.

3
http://www.softintegration.com
Program tall.ch
Predict and run the program below, and work through the related tasks to improve your programming
skills.
Note: On line 12 of the code we divided by 12.0 because if we divide by 12, Ch will cut off the decimal
part of the answer.

3a) Predict what the program below will do. Then run the program to test your prediction:

/* File: tall.ch */
// declare variables
int feet, inches;
double totalinches, totalfeet;

// ask user for input


printf("enter your height as follows: feet, inches: ");
scanf("%d%d", &feet, &inches);

// compute total inches and total feet


totalinches = feet*12 + inches;
totalfeet = feet+inches/12.0;

// prints the answer to the screen


printf("You are %lf inches tall.\n", totalinches);
printf("You are %lf feet tall.\n", totalfeet);

Note:
● Use int and double types to declare variables to hold integer and decimal numbers,
respectively.
● Use the format specifiers “%d” and “%lf” in functions printf() and scanf() for integer and
decimal numbers, respectively.
Use the table below as a guide to analyze Program 3:
Code Explanation

scanf("%d%d", &feet, &inches); a) Store the first value entered into a variable
called feet and the second value into a variable
called inches

totalinches = feet*12 + inches b) Multiply the value stored in feet by 12 and add
the product to the value stored in inches; the sum
is stored in a variable called totalinches

totalfeet = feet+inches/12.0 c)

printf("You are %lf inches tall.\n", d) Print out the specified height in inches
totalinches);

printf("You are %lf feet tall.\n", e)


totalfeet);

4
http://www.softintegration.com

Task 1: Add a line of code that will calculate how many centimeters tall the user is, and a print statement
that will print out the result (note: there are 2.54 cm in one inch).

Program average.ch
Predict and run the program below, and work through the related tasks to improve your programming
skills.

a) Predict what the program below will do. Then run the program to test your prediction:

/* File: average.ch */
// declare variables
double first, second, third, average;

// ask user for input


printf("enter three number, separated by commas: ");
scanf("%lf%lf%lf", &first, &second, &third);

// compute average
average = (first+second+third)/3.0;

// prints average to screen


printf("average: %lf\n", average);

Use the table below as a guide to analyze Program average.ch:

Code Explanation

scanf("%lf%lf%lf", &first, &second, a) Store the first value entered in a variable called
&third); first, the second value in a variable called
second, and the third value in a variable called
third

average = (first+second+third)/3.0 b)

printf("average: %lf\n", average); c) Print out the average of the three specified values

Task 1: Change the program so that it asks the user to enter the three numbers one line at a time, e.g.:

enter the first number:


enter the second number:
enter the third number:

Task 2: Change the program so that it calculates the average of 5 numbers.

5
http://www.softintegration.com
Arithmetic and Parentheses in Ch
Parentheses can change the result of an arithmetic expression. Write a short program, to allow you to
output the following expressions to understand how parentheses affect the order of operations.

Exercise 1 Exercise 2 Exercise 3

1a) 2a) 3a)


>2+3 >9-4 >2*3

Result: __________ Result: __________ Result: __________

1b) 2b) 3b)


>6+10/2 >2+3*5 >(6+(8/4)-2)*3

Result: __________ Result: __________ Result: __________

1c) 2c) 3c)


>(6+10)/2 >(2+3)*5 >6+(8/4)-2*3

Result: __________ Result: __________ Result: __________

Read through the following steps and calculate the expressions.

Several important tips to keep in mind include:


● Use + for addition.
● Use – for subtract.
● Use the ‘*’ symbol for multiplication, e.g. 4*(3+1) not 4(3+1).
● Use the ‘/’ symbol for division.
● Be sure to include all the parentheses you need to perform the correct order of operations.
● Be sure to close any parentheses that you open.

Exercise 4 Exercise 5

4a) 5a)
Step 1: Divide 70 by 5 Step 1: Multiply 5 by 3
Step 2: Multiply the result by 3 Step 2: Add 6 to the product
Step 3: Subtract 12 from the product
Step 3: Multiply the sum by 4
Step 4: Subtract 8 from the product
Step 5: Divide the result by 4

4b) Write the expression described above: 5b) Write the expression described above:
_________________________ _________________________

Type the expression into the interpreter. If correct, Type the expression into the interpreter. If correct,
Ch should tell you that the answer is 30. Ch should tell you that the answer is 19.

6
http://www.softintegration.com
Mathematical Notation in Ch
Ch uses several symbols for mathematical operations that vary from what we usually see in math class.
Test the examples below while looking for patterns that indicate the meaning of each symbol.

Exercise 6
For each of the operations below, enter the four examples into the Ch IDE program to figure out what
each operation does. Use the last column to comment on what you have learned about the operation.

Operation Example 1 Example 2 Example 3 What does this


operation do?

6a) * >7*7 >2*2*2 >2*2*2*2

Result: _______ Result: _______ Result: _______

6b) pow >pow(7,2) >pow(2,3) >pow(2,4)

Result: _______ Result: _______ Result: _______

6c) % >21%4 >24%5 >18%6

Result: _______ Result: _______ Result: _______

6d) / >21/4 >21.0/4 >21/4.0

Result: _______ Result: _______ Result: _______

Note:
The function pow(x, y) is used as the power function for the expression xy.
Unless the result of a division operation is a whole number, to get the correct numerical result,
one of the numbers must be a decimal.

Equality in Ch
Ch has three different symbols to represent different types of equality. In the exercises below, test out the
‘=’, ‘==’, and ‘!=’ symbols looking for patterns that indicate what each one means.

Exercise 7
Write a program in Ch that will output the values of the expressions below, starting with 7a). Use the last
column to comment on what you have learned about that symbol.
Note:
● Be sure to complete 7a) before entering in the other expressions; Ch cannot evaluate an
expression involving a variable until that variable is defined.
● If Ch gives you an error message on any of the above exercises, try defining x again by entering
x=7, and then proceeding.

7
http://www.softintegration.com

Expression Ch’s Response Expression Ch’s Response

7a) 7e)
> int x > x == 7
>x = 7

7b) 7f)
> 4*x > x == 9

7c) 7g)
> pow(x,2) >x != 9

7d) 7h)
>x >x != 7

Note:
1. The symbol int is used to declare a variable to store integers.
2. The symbols ‘=’, ‘==’, and ‘!=’ represent assignment, equal to, and not equal to,
respectively.

Inequality in Ch
Exercise 8
Ch also understands inequalities ‘<’, ‘<=’, ‘>’, and ‘<=’. Enter the expressions below, beginning with 8a),
and record the results.

Expression Ch’s Response Expression Ch’s Response

8a) 8g)
> x=3 > x>=8

8b) 8h)
> x<8 > x>1

8c) 8i)
> x<=8 > x>=1

8d) 8j)
> x<1 > x == 3

8e) 8k)
> x<=1 > x<=3

8f) 8l)
> x>8 > x<=3

Note: The symbols ‘<’, ‘<=’, ‘>’, and ‘>=’ represent less than, less than or equal to, greater than,
and greater than or equal, respectively.

8
http://www.softintegration.com
Logical Operations in Ch
Exercise 9
Ch also understands logical operations. Enter the expressions below, beginning with 9a), and record the
results.

Expression Ch’s Response Expression Ch’s Response

9a) 9d)
> x=3 > x>1 && x<8

9b) 9e)
> x<2 || x>8 > x>5 && x<8

9c) 9f)
> x<5 || x>8 > x<=3 && x<8

Note: For the logical OR (||), either one or both of its operands must be true for the operation to
be true. The logical AND operator (&&) can be used to check whether both the conditions of its
two operands are true.

9
http://www.softintegration.com
Conditional Logic in Ch
Ch uses conditional logic to ‘branch out’ and handle all possible scenarios to solve a problem. Run the
program below three times:
● The first time, enter a number that is less than 2272
● The second time, try a number that is greater than 2272
● The last time, enter 2272
Program 5: guess.ch
Predict and run the program below, and work through the related questions and tasks.

5a) Based on the results and the code below, explain what an ‘if, elif, else’ statement appears to
do in the space below:

/* File: guess.ch */
int guess;
printf("Guess the average number of texts an American teen sends and receives
each month: ");
scanf("%d", &guess);

if (guess == 2272)
printf("You got it!\n");
else if (guess < 2272)
printf("Too low; the average American teen sends 2272 texts per
month\n");
else
printf("Too high; the average American teen sends 2272 texts per
month\n");

Use the table below as a guide to analyze Program 5:

Code Explanation

scanf("%d", &guess); a)

if (guess == 2272) b) Ch checks to see if the user guessed 2272; if


printf("You got it!\n"); she/he did, Ch prints out the words “You got it!”
If we had used the single equal sign ‘=’, Ch would
have assigned 2272 to guess and then been
confused; the double equal sign tells Ch to compare
two values, not to replace one with the other.

else if (guess < 2272) c) If the user did not guess 2272, Ch checks to see
printf("Too low; the average if the value they guessed is less than 2272. If it is,
American teen sends 2272 texts per Ch prints out the words “Too low, try again”
month\n");

else d)
printf("Too high; the average
American teen sends 2272 texts per
month\n");

5f) In the space below, complete the program so that Ch will run as follows:

10
http://www.softintegration.com
● Ask the user how many hours she slept last night.
● If she slept 7 - 9 hours, print out ‘You are right on schedule’.
● If she slept less than 7 hours, print out ‘You need a nap’.
● If she slept more than 9 hours, print ‘Time to set the alarm’.

/* File hour.ch */
int hours;

printf("How many hour did you sleep last night?\n");


scanf("%d", &hours);

if (hours == 7 || hours == 8 || hours == 9)


printf("You are right on schedule.\n");
else if (hours < 7)
printf("You could use a nap.\n");
else
printf("Time to set the alarm.\n");

Type your completed program into the ChIDE editor and run it to check your work.

Programming with Loops in Ch


Ch uses a ‘while loop’ to complete a repetitive task very quickly. A while loop performs a specified
task over and over while a specified condition is true. Run the two ‘blastoff’ programs below and describe
what appears to be happening in each program.

Program guess2.ch: Blastoff outside of the loop Program guess3.ch: Blastoff inside of the loop

/* guess2.ch */ /* File: guess3.ch */


int number; int number;
printf("enter a number between 1 and
50: "); printf("enter a number between 1 and
scanf("%d", &number); 50: ");
while (number >= 0) scanf("%d", &number);
{ while (number >=0)
printf("%d\n", number); {
number = number - 1; printf("%d\n", number);
} number = number - 1;
printf("Blastoff!\n"); printf("Blastoff!\n");
}

Describe the results of this program: How do the results of the program differ now that
the second print statement is inside the braces?

11
http://www.softintegration.com

Program count.ch: We can have Ch count the total number of multiples of 3 between zero and one
hundred by adding a variable that we chose to call counter to our program.

/* File: count.ch */
// initialize variables
int x, counter;

// assign variables values


x = 3;
counter = 0;

// while x is less than 100, run loop


while (x < 100)
{
printf("%d\n", x);
counter = counter+1; // increase count every time program enters loop
x = x + 3; // increase x by 3
}

printf("There are %d multiples of 3 between zero and one hundred.\n",


counter);

12
http://www.softintegration.com

Code Explanation

x = 3; a) Store the value 3 in the variable x

counter = 0; b)

while (x < 100) c) Check to see if x is less than 100. If it is, go


through the next 3 indented lines inside the braces.
If not, skip all of the indented lines.

printf("%d\n", x); d) Print out the value stored in x

counter = counter+1; e) Add 1 to the value stored in counter

x = x + 3; 8f) Add 3 to the value stored in x, and replace the


previous value with this sum. Then return to the
while statement to check to see if the new value
stored in x is still less than 100.

printf("There are %d multiples of 3 g)


between zero and one hundred.\n",
counter);

Note:
● We set counter equal to zero at the beginning of the program. We ‘initialize’ all variables before
using them in a loop. This tells Ch that it will need to save some space for the variable before it
runs through the loop that follows.

Once we learn how to program, we can create a personalized calculator that can do our work for us. In
the program below, we used a while loop to create a calculator that will solve a word problem:

Program earnings.ch: Mai earns $5.50 per hour Program earnings2.ch: Notice that this is the same
at her after-school job. How many hours does she program, with a print statement is included in the
have to work to earn $132? while loop. Compare the results to those of Program
earning.ch.

/* File: earnings.ch */ /* File: earnings2.ch */


double earnings; double earnings;
int hours; int hours;
earnings = 0;
// assign variables values hours = 0;
earnings = 0;
hours = 0; while (earnings < 132)
// while earnings are less than 132, {
run loop earnings = earnings + 5.5;
while (earnings < 132) hours = hours + 1;
{ printf("%d hours $%.2lf\n", hours,
earnings = earnings + 5.5; earnings);
hours = hours + 1; }
}
// prints answer to screen printf("Mai must work %d hours\n",
printf("Mai must work %d hours.\n", hours);
hours);

13
http://www.softintegration.com
Note:
● In these final programs, hours does the same thing that counter does in Program count.ch.
● Use the format specifier “%.2lf” for the function printf() to display a decimal number with two
digits after the decimal point, instead of the default 6 digits after the decimal point.

Random Number Generation and Games


The same programming skills that you learned to use when solving math problems can be used to create
games as well.

Program game.ch
Ch has a function called randint() that will pick a random number between any two values that you
want. Type the guessing game below into the ChIDE editor and then fill out the table below to help you
understand how this program works.

/* File game.ch */
int guess, x;
printf("I'm thinking of a number between 10 and 25. Guess my number: ");
scanf("%d", &guess);

x = randint(10, 25); // generate a random number between 10 and 25


// while the user's guess is wrong, run while loop
while (guess != x)
{
printf("Try again: ");
scanf("%d", &guess);
}

printf("You got it! My number is %d\n", x);

scanf("%d", &guess); a)

x = randint(10, 25); b) Ch generates a random number between 10 and


25, and assigns it to the variable x

while (guess != x) c)

scanf("%d", &guess); d)

printf("You got it! My number is e)


%d\n", x);

Program game2.ch
We can improve our guessing game by providing hints about whether the user’s guess is too high or too
low. We do this by including conditional logic inside a loop. Fill in the two blank lines of code to tell Ch
under what condition it should print out ‘too low, try again:’

14
http://www.softintegration.com

/* File game2.ch */
int guess, x;

// ask user for input


printf("I'm thinking of a number between 10 and 25. Guess my number: ");
scanf("%d", &guess);

x = randint(10, 25); // generate a random number between 10 and 25

// while guess is wrong


while (guess != x)
{
// guess is to low
if (guess < x)
{
printf("too low, try again: ");
scanf("%d", &guess);
}
// guess is too high
else
{
printf("too high, try again: ");
scanf("%d", &guess);
}

printf("You got it! My number is %d\n", x);


}

Did you know: If a person has to guess a number between 1 and 100, it is possible to
guess the number within 7 tries! This might be an exercise to try during lectures if time
permits.

Adapt the code to restrict the user with only a certain number of tries, with the use fo the
WHILE loop.

Can FOR loops be used to allow the user only a restricted number of tries? Give it a try.

15
http://www.softintegration.com
Arrays
Arrays are used for storing data as a string of characters, or in a matrix formation. Some
examples with the use of arrays are given below. More details on the use of strings will be
discussed in lectures.

Ch Professional Edition Demos -- Computational array

/* Example 1:
An array qualified by type qualifier 'array' is called computational
array.
A computational array is treated as a first-class object as in Fortran
90.
*/
#include <stdio.h>
#include <array.h>

int main() {
array double A[2][3] = {1, 2, 3,
4, 5, 6};
array double B[3][2];
printf("A= \n%f \n", A+A);
B = 2*transpose(A);
printf("B= \n%f \n", B);
}

The output is:


A=
2.000000 4.000000 6.000000
8.000000 10.000000 12.000000

B=
2.000000 8.000000
4.000000 10.000000
6.000000 12.000000

/* Example 2:
A function can return a computational array as well.
*/
#include <stdio.h>
#include <array.h>

array double fun(int i)[3] {


array double a[3]={1,2,3};
a = a+a;
return a;
}
int main() {
array double b[3];
b = fun(3);
printf("%f \n", b);

16
http://www.softintegration.com
}

The output is:


2.000000 4.000000 6.000000

Arrays can be used to perform matrix arithmetic. Complex numbers can also be implemented in
Ch.

The example below demonstrates the salient numerical features in Ch.

#include <stdio.h>
#include <numeric.h>
int main() {
complex z;
array double A[3][3], C[3][3] = {1, 2, 3,
4, 5, 6,
7, 8, 9};
A = C*4 + sin(C);
printf("A= \n%f \n", A);
A = C * transpose(C)* inverse(C);
printf("A= \n%f \n", A);
z = complex(3,4);
z = sin(2*z);
printf("z = %f\n", z);
}

The output from the above code is as follows:


A=
4.841471 8.909297 12.141120
15.243198 19.041076 23.780585
28.656987 32.989358 36.412118

A=
64.000000 0.000000 32.000000
128.000000 0.000000 -64.000000
256.000000 0.000000 128.000000

z= complex(-416.462982,1431.113525)

17
http://www.softintegration.com
Plotting in Ch
Ch can plot data conveniently. The relation between Fahrenheit and Celsius are given in a table below.

Fahrenheit -10 20 50 80 110


Celsius -23.33 -6.67 10 26.67 43.33

Program points.ch
Predict and run the program below, and work through the related questions and tasks.

/* File: points.ch
Plot the temperature relationship between Fahrenheit and Celsius
using five points */
#include <chplot.h> // for CPlot
CPlot plot; // declare the variable plot

plot.title("Temperature Relation"); // title of the plot


plot.label(PLOT_AXIS_X, "Fahrenheit"); // x-label of the plot
plot.label(PLOT_AXIS_Y, "Celsius"); // y label of the plot

/* add five data points for plotting */


plot.point(-10, -23.33);
plot.point(20, -6.67);
plot.point(50, 10.00);
plot.point(80, 26.67);
plot.point(110, 43.33);

plot.plotting(); // generate the plot

The output of a plot from the program points.ch is shown below.

18
http://www.softintegration.com

Use the table below as a guide to analyze Program points.ch:

Code Explanation

#include <chplot.h> a) Include the header file chplot.h where all the
plotting information is stored

CPlot plot; b) Declare the variable ‘plot’ of type ‘CPlot’

plot.title("Temperature Relation”); d) Set the title of the plot

plot.label(PLOT_AXIS_X, "Fahrenheit"); e) Set the x label of the plot

plot.label(PLOT_AXIS_Y, "Celsius"); f)

plot.point(-10, -23.33); g) Add the point (-10, -23.33) to the plot

plot.point(20, -6.67); h)

plot.plotting(); i) Generate the plot

Refer to other plotting techniques covered in lectures

19
http://www.softintegration.com

Additional Computer Fundamentals Tutorial Questions


The questions below are ones that were conducted in pure C language, as exercises for
students to in in prior years. Thus, some commands in question 5 might not work.

1. Write a program that allows you to enter a distance in miles, and that would calculate the
distance in kilometers. 1 mile is equivalent to 1.609 kilometers.

2. Write a program that allows a user to determine the surface area of a washer. Use error
checking, to make sure that the inner diameter is not entered to be larger than the outer
diameter of the washer. Consider having a range of values that are suitable for the inner and
outer diameters.

3. Write a program that will be able to calculate the factorial of a number. Modify the program to
calculate the factorial of a number, using only the even OR odd numbers in the series.

4. There are 9870 people in a town whose population increases by 10 percent each year. Write
a program that will display the annual population and determine how many years it will take for
the population to surpass 30 000.

5. Write a program to investigate the usage of the following functions:


abs (x), ceil (x), cos (x), exp (x), fabs (x), floor (x), log (x), log10 (x), rand (), sin (x), sqrt (x), tan
(x)
Note: rand () does not need an argument
Investigate whether these functions need arguments that are integers, double, float etc.

6. Write a program that estimates the temperature in a freezer (in °C) given the elapsed time
(hours) since a power failure. Assume that this temperature (T) is given by:

Where t is the time period since the power failure. The user must enter the exact number of
hours and minutes that the power failure has occurred – you are required to use this information
to perform the calculations.

7. Write a function that will return a 1 for true if a string argument ends with the substring OH.
Try the following data: KOH, H2O2, NaCl, NaOH, C9H8O4, MgOH

8. Write a program that will plot the following functions with a legend. Use different values for
the variables of the Chplot library functions:
S1(t) = 5 sin (2πt)
S2(t) = 3 sin (πt + π)
S = S1 + S2
Re-write the code to use sub-plots.

20
http://www.softintegration.com
Summary
In this lesson we covered several key programming topics that are directly applicable to math curriculum
and computational thinking. These include:

● Parentheses affect the order in which Ch performs a calculation


● Ch stores one value in each variable
● Ch uses several symbols rarely found outside of computer science to evaluate mathematical
expressions, including
○ * : multiplication
○ / : division (note: expressions must include decimals if the quotient is not an integer)
○ % : remainders
○ pow() : power function
○ <= : less than or equal to
○ >= : greater than or equal to
○ != : not equal to
○ == : value comparison
○ ||: logical OR operation
○ &&: logical AND operation
● Ch can tell whether an expression is true or false
● We can use the ChIDE Editor to write our own programs
● We can use Ch to plot data
● We can use conditional logic (if, else if, else) to account for several possible cases of the same
problem
● We can use ‘while loops’ and ‘for loops’ to perform a repetitive calculation quickly and accurately.

Copyright and License


Copyright 2014, SoftIntegration, Inc. http://www.softintegration.com

The content of this lesson is licensed under the Creative Commons Attribution 3.0 License, and code
samples are licensed under the Apache 2.0 License.

The majority of the material in this document was obtained from SoftIntegration, either through
documentation, websites, or shared files. The layout and flow of the document was drastically
altered, with additional examples and comments, to be presented in the course Computer
Fundamentals, presented by Riaan Stopforth.

21

You might also like