Variables and Arithmetic

Slides:



Advertisements
Similar presentations
Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
Advertisements

1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Building Java Programs Primitive Data and Definite Loops.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 CS 1430: Programming in C++ Turn in your Quiz1-1.
Doing math In java.
Operators.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Java Statements –Java Expressions –Postfix Expressions –Prefix Expressions –Evaluating.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Math operations 9/19/16.
CSE 220 – C Programming Expressions.
Chapter 7: Expressions and Assignment Statements
Lecture 4: Expressions and Variables
Building Java Programs
Chapter 7: Expressions and Assignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Assignment statement and Arithmetic operation 2
Algebra 1 Section 2.3 Subtract real numbers
Arithmetic Operator Operation Example + addition x + y
Building Java Programs Chapter 2
Code Elements and Processing Coordinate System
Structure of a C Program
Unit 2 Programming.
Lecture 3 Expressions Richard Gesick.
If statement.
Introduction to Java, and DrJava part 1
Lecture 3: Expressions and Variables
Building Java Programs
Building Java Programs
Arithmetic Expressions & Data Conversions
Code Elements and Processing Coordinate System
Building Java Programs
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Introduction to Java, and DrJava
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Building Java Programs
Data Types and Expressions
SSEA Computer Science: Track A
Building Java Programs
Building Java Programs
Building Java Programs
Lecture 4: Expressions and Variables
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Introduction to Java, and DrJava part 1
Building Java Programs
Building Java Programs
5.03 Apply operators and Boolean expressions
Data Types and Expressions
Building Java Programs
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Introduction to Python
Building Java Programs
Presentation transcript:

Variables and Arithmetic

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

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

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: <type> <name>

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);

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);

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

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;

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

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.

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);

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