Presentation is loading. Please wait.

Presentation is loading. Please wait.

Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.

Similar presentations


Presentation on theme: "Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter."— Presentation transcript:

1 Variables and Arithmetic

2 From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter for fill gives you grey scale capablity Second parameter to stroke and fill is for transparency noFill(); noStroke(); smooth(); noSmooth(); Few others we will learn as we go along

3 Topics: pages 37-50 Section: Data1: variables; Section: Math1: Arithmetic, functions Data types: int, float, Boolean Assignment operator = Width, height Boolean values: true, false Arithmetic functions: variables, operators, expression

4 Data Types Data is the representation of real world items Example: int numStudents; // number of students float avgScore; // average score in an exam: 88.86 boolean hot; //condition of “hot” can be false or true char middleInitial; // middle initial in the name of a student Syntax or “format” for specifying a variable is:

5 Assigning values int numStudents; numStudents = 162; float avgScore; avgScore = 76.5; print(“ This is CSE113 Spring 2015”); println(“Average score for the class is: “ + avgScore);

6 size function Size function sets the variable width and height When you say size(300,400); // sets a variable width = 300, height = 400 You can use these variables in your programming/code Example: line(0, height, width, 0);

7 Arithmetic Add + Subtract - Multiply * Divide / (this gives the quotient of division) Modulus % (this gives the remainder of division) Lets do the exercises in pages 44-46

8 Operator Precedence Multiplicative * / % Additive + - Assignment = If two operators are of equal precendece: evaluate them left to right Example: a = 5; c = 8; b = 10 int x = a + b * c; int y = a – b + b/a;

9 Constraining numbers ceil() floor() round() min() max() Examples: int x = ceil(3.1); // x = 4 int y = floor(4.8); // y = 4 int w = round(3.1) // w = 3 int z = round (3.9); // w = 4

10 Example for min and max Min and max functiosn take a list of data as parameters Lets work out your overall percentage for the course using these functions. Problem statement: Define variables for the 3 exams, 4 quizzes, 5 labs and write a expressions to compute the overall percent.

11 Overall Course Grade int ex1, ex2, ex3; int q1, q2, q3, q4; int lab1, lab2, lab3, lab4, lab5; int ex, quiz, lab; ex = ex1 + ex2 + ex3 – min(ex1, ex2); quiz = q1+ q2 + q3 + q4 – min(q1,q2,q3,q4); lab = lab1 + lab2 + lab3 + lab4 – min(lab1, lab2, lab3, lab4) + lab5; float overallPercent = ex *0.6 + lab*0.35 + quiz*0.15; int percent = round(overallPercent);

12 Try this Speech Library import guru.ttslib.*; TTS tts; void setup() { tts = new TTS(); } void draw() { } void mousePressed() { tts.speak("Hello, I am Bina Ramamurthy"); }

13 Summary We studied Variables Arithmetic operations Arithmetic expressions Predefined constraining functions such as min(), max(), ceil() etc.


Download ppt "Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter."

Similar presentations


Ads by Google