CMSC 132, Object-Oriented Programming II Summer Lecture 1:
|
|
- Conrad Newman
- 6 years ago
- Views:
Transcription
1 CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 1: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 1.1 Course Introduction Check the course website for the syllabus and course introduction slides. 1.2 Java Review We start by introducing Object Oriented Programming (OOP) concepts, such as class, inheritance, and encapsulation Code Examples: Fraction Class In this example, we implement a Fraction class, which can represent fractions and support arithmetic operations on the fractions. A common fraction consists of an integer numerator, and non-zero denominator For example: 10 or 5. The Fraction class has two private members numerator and denominator. Listing 1: Fraction Class 1 / 2 Fraction c l a s s implements non n e g a t i v e f r a c t i o n s anwar 4 / 5 public class Fraction { 6 protected int numerator ; 7 protected int denominator ; 8 / Constructs a Fraction n/d. n i s the numerator, assumed non n e g a t i v e. d i s t he denominator, assumed p o s i t i v e. 11 / 12 Fraction ( int n, int d ) { 13 int g = gcd (d, n ) ; 14 / reduce the f r a c t i o n / 15 numerator = n/ g ; 16 denominator = d/ g ; 17 } / Constructs a Fraction n /1. n i s the numerator, assumed non n e g a t i v e. 21 / 1-1
2 1-2 Lecture 1: 22 public Fraction ( int n ) { 23 this (n, 1 ) ; 24 } / Constructs a Fraction 0/1. 27 / 28 public Fraction ( ) { 29 numerator = 0 ; 30 denominator = 1 ; 31 } public S t r i n g t o S t r i n g ( ) { 34 return ( numerator + / + denominator ) ; 35 } / C a l c u l a t e s and r e t u r n s the double f l o a t i n g p o i n t v a l u e o f a f r a c t i o n. a double f l o a t i n g p o i n t v a l u e f o r t h i s Fraction. 39 / 40 public double e v a l u a t e ( ) { 41 double n = numerator ; // convert to double 42 double d = denominator ; 43 return ( n / d ) ; 44 } / Add f 2 to t h i s f r a c t i o n and return the r e s u l t. f 2 i s the f r a c t i o n to be added. the r e s u l t o f adding f 2 to t h i s Fraction. 49 / 50 public Fraction add ( Fraction f 2 ) { 51 Fraction r = new Fraction ( ( numerator f 2. denominator ) + 52 ( f 2. numerator denominator ), 53 ( denominator f 2. denominator ) ) ; 54 return r ; 55 } / s u b t r a c t f 2 from t h i s f r a c t i o n and return the r e s u l t. f 2 i s the f r a c t i o n to be added. the r e s u l t o f adding f 2 to t h i s Fraction. 60 / 61 public Fraction sub ( Fraction f 2 ) { 62 Fraction r = new Fraction ( ( numerator f 2. denominator ) 63 ( f 2. numerator denominator ), 64 ( denominator f 2. denominator ) ) ; 65 return r ; 66 } / m u l t i p l e f 2 to t h i s f r a c t i o n and return the r e s u l t. f 2 i s the f r a c t i o n to be added. the r e s u l t o f adding f 2 to t h i s Fraction. 71 / 72 public Fraction mul ( Fraction f 2 ) {
3 Lecture 1: return ( 74 new Fraction ( numerator f 2. numerator, 75 denominator f 2. denominator ) 76 ) ; 77 } / d i v i d e f 2 to t h i s f r a c t i o n and return the r e s u l t. f 2 i s the f r a c t i o n to be added. the r e s u l t o f adding f 2 to t h i s Fraction. 82 / 83 public Fraction div ( Fraction f 2 ) { 84 return ( 85 new Fraction ( numerator f 2. denominator, 86 denominator f 2. numerator ) 87 ) ; 88 } / Computes the g r e a t e s t common d i v i s o r ( gcd ) o f the two i n p u t s. a i s assumed p o s i t i v e b i s assumed non n e g a t i v e the gcd o f a and b 94 / 95 static private int gcd ( int a, int b ) { 96 int t ; 97 // a must be g r e a t e r than or e q u a l to b 98 i f ( a < b ){ 99 t = a ; 100 a = b ; 101 b = t ; 102 } 103 i f ( b == 0){ 104 return a ; 105 } else { 106 return gcd (b, a%b ) ; 107 } 108 } public static void main ( S t r i n g [ ] argv ) { 111 / Test a l l t h r e e c o n t r u c t o r s and t o S t r i n g. / 112 Fraction f 0 = new Fraction ( ) ; 113 Fraction f 1 = new Fraction ( 3 ) ; 114 Fraction f 2 = new Fraction (12, 2 0 ) ; System. out. p r i n t l n ( \ ntesting c o n s t r u c t o r s ( and t o S t r i n g ) : ) ; 117 System. out. p r i n t l n ( The f r a c t i o n f 0 i s + f 0. t o S t r i n g ( ) ) ; 118 System. out. p r i n t l n ( The f r a c t i o n f 1 i s + f 1 ) ; // t o S t r i n g i s i m p l i c i t 119 System. out. p r i n t l n ( The f r a c t i o n f 2 i s + f 2 ) ; / Test methods on Fraction : add and e v a l u a t e. / 122 System. out. p r i n t l n ( \ ntesting add and e v a l u a t e : ) ; 123 System. out. p r i n t l n ( The f l o a t i n g point value o f + f 1 + i s +
4 1-4 Lecture 1: 124 f 1. e v a l u a t e ( ) ) ; 125 System. out. p r i n t l n ( The f l o a t i n g point value o f + f 2 + i s f 2. e v a l u a t e ( ) ) ; Fraction sumoftwo = f 1. add ( f 2 ) ; 129 Fraction sumofthree = f 0. add ( f 1. add ( f 2 ) ) ; System. out. p r i n t l n ( The sum o f + f 1 + and + f 2 + i s + sumoftwo ) ; 132 System. out. p r i n t l n ( The sum o f + f 0 +, + f 1 + and + f 2 + i s sumofthree ) ; 134 / 135 t e s t sub, div, mul here 136 / 137 / Test gcd f u n c t i o n ( s t a t i c method ). / 138 System. out. p r i n t l n ( \ ntesting gcd : ) ; 139 System. out. p r i n t l n ( The gcd o f 2 and 10 i s : + gcd ( 2, 1 0 ) ) ; 140 System. out. p r i n t l n ( The gcd o f 15 and 5 i s : + gcd (15, 5 ) ) ; 141 System. out. p r i n t l n ( The gcd o f 24 and 18 i s : + gcd (24, 1 8 ) ) ; 142 System. out. p r i n t l n ( The gcd o f 10 and 10 i s : + gcd (10, 1 0 ) ) ; 143 System. out. p r i n t l n ( The gcd o f 21 and 400 i s : + gcd (21, ) ) ; 144 } 145 } MixedFraction inherits Fraction, so that it inherits addition, subtraction etc. Only difference is that mixed fraction is a whole number and a fraction combined. For example: = 13 5 Listing 2: MixedFraction Class 1 / 2 This c l a s s implements mixed f r a c t i o n anwar mamat 4 / 5 public class MixedFraction extends Fraction { 6 / Constructs a Fraction m n/d. m i s the i n t e g e r p a rt. n i s the numerator, assumed non n e g a t i v e. d i s t he denominator, assumed p o s i t i v e. 10 / 11 public MixedFraction ( int m, int n, int d ){ 12 super (m d+n, d ) ; // convert mixed f r a c t i o n i n t o proper f r a c t i o n. 13 } / Constructs a Fraction m n/d. f i s a f r a c t i o n 17 / 18 public MixedFraction ( Fraction f ) { 19 super ( f. numerator, f. denominator ) ; 20 } public S t r i n g t o S t r i n g ( ) { 23 int m = numerator / denominator ; 24 int n = numerator % denominator ;
5 Lecture 1: return (m + + n + / + denominator ) ; 26 } 27 } Main is the fraction test driver class. The main method of this class creates Fraction objects and prints the result in the console. Listing 3: Fraction Test Driver 1 public class Main{ 2 public static void main ( S t r i n g [ ] args ) { 3 Fraction f 1 = new Fraction ( 2, 1 0 ) ; 4 Fraction f 2 = new MixedFraction ( 1, 2, 1 0 ) ; 5 System. out. p r i n t l n ( f 1= + f 1 ) ; 6 System. out. p r i n t l n ( f 2 = + f 2 ) ; 7 MixedFraction f 3 = new MixedFraction ( f 2. add ( f 1 ) ) ; 8 System. out. p r i n t l n ( f f 2 + = + f 3 ) ; 9 Fraction f 4 = f 2. sub ( f 1 ) ; 10 System. out. p r i n t l n ( f f 1 + = + f 4 ) ; 11 Fraction f 5 = f 1. mul ( f 2 ) ; 12 System. out. p r i n t l n ( f f 2 + = + f 5 ) ; 13 Fraction f 6 = f 1. div ( f 2 ) ; 14 System. out. p r i n t l n ( f 1 + / + f 2 + = + f 6 ) ; 15 } 16 } We also create a JUnit test class for fraction. Listing 4: Fraction JUnit Test 1 2 import static org. j u n i t. Assert. ; 3 import org. j u n i t. Test ; 4 import org. j u n i t. After ; 5 import org. j u n i t. A f t e r C l a s s ; 6 import org. j u n i t. Before ; 7 import org. j u n i t. B e f o r e C l a s s ; 8 import org. j u n i t. Test ; 9 import static org. j u n i t. Assert. ; / 12 anwar 14 / 15 public class FractionTest { public FractionTest ( ) { 18 } public static void setupclass ( ) { 22 System. out. p r i n t l n ( UtilsJUnit4Test method ) ;
6 1-6 Lecture 1: 23 } public static void teardownclass ( ) { 27 System. out. p r i n t l n ( UtilsJUnit4Test method ) ; 28 } public void setupagain ( ) { 32 System. out. p r i n t l n ( UtilsJUnit4Test method ) ; 33 } public void teardown ( ) { 37 System. out. p r i n t l n ( UtilsJUnit4Test method ) ; 38 } 39 / 40 Test o f t o S t r i n g method, o f c l a s s Fraction. 41 / 43 public void t e s t T o S t r i n g ( ) { 44 System. out. p r i n t l n ( t o S t r i n g ) ; 45 Fraction i n s t a n c e = new Fraction ( 2, 1 0 ) ; 46 S t r i n g expresult = 1/5 ; 47 S t r i n g r e s u l t = i n s t a n c e. t o S t r i n g ( ) ; 48 a s s e r t E q u a l s ( expresult, r e s u l t ) ; 49 } 50 / 51 Test o f e v a l u a t e method, o f c l a s s Fraction. 52 / 54 public void t e s t E v a l u a t e ( ) { 55 System. out. p r i n t l n ( e v a l u a t e ) ; 56 Fraction i n s t a n c e = new Fraction ( 5, 1 0 ) ; 57 double expresult = 0. 5 ; 58 double r e s u l t = i n s t a n c e. e v a l u a t e ( ) ; 59 a s s e r t E q u a l s ( expresult, r e s u l t, 0. 0 ) ; 60 } / 63 Test o f add method, o f c l a s s Fraction. 64 / 66 public void testadd ( ) { 67 System. out. p r i n t l n ( add ) ; 68 Fraction f 2 = new Fraction ( 2, 7 ) ; 69 Fraction i n s t a n c e = new Fraction ( 1, 5 ) ; 70 Fraction expresult = new Fraction ( 1 7, 3 5 ) ; 71 Fraction r e s u l t = i n s t a n c e. add ( f 2 ) ; 72 a s s e r t E q u a l s ( expresult, r e s u l t ) ; 73 }
7 Lecture 1: / 76 Test o f sub method, o f c l a s s Fraction. 77 / 79 public void testsub ( ) { 80 System. out. p r i n t l n ( sub ) ; 81 Fraction f 2 = new Fraction ( 1, 5 ) ; 82 Fraction i n s t a n c e = new Fraction ( 4, 1 0 ) ; 83 Fraction expresult = new Fraction ( 1, 5 ) ; ; 84 Fraction r e s u l t = i n s t a n c e. sub ( f 2 ) ; 85 a s s e r t E q u a l s ( expresult, r e s u l t ) ; 86 } / 89 Test o f mul method, o f c l a s s Fraction. 90 / 92 public void testmul ( ) { 93 System. out. p r i n t l n ( mul ) ; 94 Fraction f 2 = new Fraction ( 3, 5 ) ; 95 Fraction i n s t a n c e = new Fraction ( 2, 3 ) ; 96 Fraction expresult = new Fraction ( 6, 1 5 ) ; 97 Fraction r e s u l t = i n s t a n c e. mul ( f 2 ) ; 98 a s s e r t E q u a l s ( expresult, r e s u l t ) ; 99 } / 102 Test o f d i v method, o f c l a s s Fraction. 103 / 105 public void t e s t D i v ( ) { 106 System. out. p r i n t l n ( div ) ; 107 Fraction f 2 = new Fraction ( 2, 5 ) ; 108 Fraction i n s t a n c e = new Fraction ( 3, 7 ) ; 109 Fraction expresult = new Fraction ( 1 5, 1 4 ) ; 110 Fraction r e s u l t = i n s t a n c e. div ( f 2 ) ; 111 a s s e r t E q u a l s ( expresult, r e s u l t ) ; 112 } }
CMSC 132, Object-Oriented Programming II Summer Lecture 6:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 6: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 6.1 Singly
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 10:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 10: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 10.1 RECURSION
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 12
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees
More informationLecture 5: Jun. 10, 2015
CMSC 132, Object-Oriented Programming II Summer 2015 Lecturer: Anwar Mamat Lecture 5: Jun. 10, 2015 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor.
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 11:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 11: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 11.1 Recursion
More informationLecture 14: Nov. 11 & 13
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting
More informationLecture 5: Sep. 23 &25
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 5: Sep. 23 &25 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Doubly Linked
More informationCSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic
CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equal if they have the same elements A = B x (x A x B) A is a subset of B if every
More informationInstance Methods and Inheritance (1/2)
Instance Methods and Inheritance (1/2) 1 class Professor { 2 p u b l i c void say_hello ( ) { 3 System. out. p r i n t l n ( " Hello! " ) ; 4 } 5 } 6 class CSIEProfessor extends Professor { 7 p u b l i
More informationOutline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University
COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 10 - November 14 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Adding Finding and Removing
More informationCSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic
CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equalif they have the same elements A = B x(x A x B) A is a subsetof B if every
More informationOutline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University
COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying
More informationAdam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course
Adam Blank Spring 2017 CSE 311 Foundations of Computing I * All slides are a combined effort between previous instructors of the course HW 3 De-Brief HW 3 De-Brief PROOFS! HW 3 De-Brief Proofs This is
More informationCSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic
CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equalif they have the same elements A = B x(x A x B) A is a subsetof B if every
More informationElementary Sorts 1 / 18
Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the
More informationCS Java. Introduction to Java. Andy Mroczkowski Department of Computer Science Drexel University
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University February 18, 2008 / Lecture 5 Outline Course Status Course Information & Schedule
More informationCSE 311: Foundations of Computing. Lecture 26: Cardinality
CSE 311: Foundations of Computing Lecture 26: Cardinality Cardinality and Computability Computers as we know them grew out of a desire to avoid bugs in mathematical reasoning A brief history of reasoning
More informationMore About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010
More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p
More information1 Java Night Countdown (30%)
Midterm Examination Problem Sheet TIME: 04/18/2009, 19:00 21:00 This is a open-textbook exam. You can use the Absolute Java textbook as your reference during the exam. Any other references are not allowed.
More informationpublic void run ( ) { i f ( this. id == 0) System. out. p r i n t ( 3 ) ; bro. j o i n ( ) ; else System. out. p r i n t ( 2 ) ;
1 Unusual programs 1. Consider the following Java program : public c l a s s Thread2 extends Thread { public int id ; public Thread2 bro ; public Thread2 ( int id, Thread2 bro ) { this. id = id ; this.
More informationCSE 311 Lecture 11: Modular Arithmetic. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 11: Modular Arithmetic Emina Torlak and Kevin Zatloukal 1 Topics Sets and set operations A quick wrap-up of Lecture 10. Modular arithmetic basics Arithmetic over a finite domain (a.k.a
More informationGenerics. Hsuan-Tien Lin. OOP Class, May 23, Department of CSIE, NTU. H.-T. Lin (NTU CSIE) Generics OOP 05/23/ / 16
Generics Hsuan-Tien Lin Department of CSIE, NTU OOP Class, May 23, 2013 H.-T. Lin (NTU CSIE) Generics OOP 05/23/2013 0 / 16 How can we write a class for an Integer set of arbitrary size? H.-T. Lin (NTU
More informationSFWR ENG 3S03: Software Testing
(Slide 1 of 69) Dr. Ridha Khedri Writing in Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on [HT03] Unit Testing in Java with
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationThe Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010
The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified
More informationcse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications
cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications n-bit unsigned integer representation Represent integer x as sum of powers of 2: If x = n 1 i=0 b i 2 i where each b i
More informationDNHI Homework 2 Solutions Recursion
Solutions Recursion Problem 1 Part A Write an iterative method that computes a value of x n for a positive integer n and a real number x. The return value of -1 indicates an error condition. 1 public static
More informationFall 2017 Test II review problems
Fall 2017 Test II review problems Dr. Holmes October 18, 2017 This is a quite miscellaneous grab bag of relevant problems from old tests. Some are certainly repeated. 1. Give the complete addition and
More informationcse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications
cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications casting out 3s Theorem: A positive integer n is divisible by 3 if and only if the sum of its decimal digits is divisible
More informationComp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33
Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T F : If a child overrides its parent
More informationMore on Methods and Encapsulation
More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local
More informationCompiling Techniques
Lecture 7: Abstract Syntax 13 October 2015 Table of contents Syntax Tree 1 Syntax Tree Semantic Actions Examples Abstract Grammar 2 Internal Representation AST Builder 3 Visitor Processing Semantic Actions
More information1. Write a program to calculate distance traveled by light
G. H. R a i s o n i C o l l e g e O f E n g i n e e r i n g D i g d o h H i l l s, H i n g n a R o a d, N a g p u r D e p a r t m e n t O f C o m p u t e r S c i e n c e & E n g g P r a c t i c a l M a
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent
More informationExam 2 Review Chapters 4-5
Math 365 Lecture Notes S. Nite 8/18/2012 Page 1 of 9 Integers and Number Theory Exam 2 Review Chapters 4-5 Divisibility Theorem 4-1 If d a, n I, then d (a n) Theorem 4-2 If d a, and d b, then d (a+b).
More informationCSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 13: Primes and GCD Emina Torlak and Kevin Zatloukal 1 Topics Modular arithmetic applications A quick wrap-up of Lecture 12. Primes Fundamental theorem of arithmetic, Euclid s theorem, factoring.
More informationChapter 4 Number Representations
Chapter 4 Number Representations SKEE2263 Digital Systems Mun im/ismahani/izam {munim@utm.my,e-izam@utm.my,ismahani@fke.utm.my} February 9, 2016 Table of Contents 1 Fundamentals 2 Signed Numbers 3 Fixed-Point
More informationAdding and Subtracting Rational Expressions. Add and subtract rational expressions with the same denominator.
Chapter 7 Section 7. Objectives Adding and Subtracting Rational Expressions 1 3 Add and subtract rational expressions with the same denominator. Find a least common denominator. Add and subtract rational
More informationCSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD
CSE 311: Foundations of Computing Lecture 12: Two s Complement, Primes, GCD n-bit Unsigned Integer Representation Represent integer as sum of powers of 2: If 2 where each {0,1} then representation is b
More informationChapter. Algebra techniques. Syllabus Content A Basic Mathematics 10% Basic algebraic techniques and the solution of equations.
Chapter 2 Algebra techniques Syllabus Content A Basic Mathematics 10% Basic algebraic techniques and the solution of equations. Page 1 2.1 What is algebra? In order to extend the usefulness of mathematical
More information6.001 Recitation 22: Streams
6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris
More informationFractions. Review R.7. Dr. Doug Ensley. January 7, Dr. Doug Ensley Review R.7
Review R.7 Dr. Doug Ensley January 7, 2015 Equivalence of fractions As long as c 0, a b = a c b c Equivalence of fractions As long as c 0, a b = a c b c Examples True or False? 10 18 = 2 5 2 9 = 5 9 10
More informationAlgorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse
Algorithms CMSC-27200 Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse Instructor: László Babai Last updated 02-14-2015. Z denotes the set of integers. All variables in
More informationFall 2015 Lecture 14: Modular congruences. cse 311: foundations of computing
Fall 2015 Lecture 14: Modular congruences cse 311: foundations of computing If a and b are positive integers, then gcd a, b = gcd (b, a mod b) Useful GCD Fact Proof: By definition a = a div b b + (a mod
More informationLab Exercise 6 CS 2334
Lab Exercise 6 CS 2334 September 28, 2017 Introduction In this lab, you will experiment with using inheritance in Java through the use of abstract classes and interfaces. You will implement a set of classes
More informationDiscrete Structures CRN Test 3 Version 1 CMSC 2123 Spring 2011
Discrete Structures CRN 1858 Test 3 Version 1 CMSC 13 Spring 011 1. Print your name on your scantron in the space labeled NAME.. Print CMSC 13 in the space labeled SUBJECT. 3. Print the date, 5--011, in
More informationFunction Operations and Composition of Functions. Unit 1 Lesson 6
Function Operations and Composition of Functions Unit 1 Lesson 6 Students will be able to: Combine standard function types using arithmetic operations Compose functions Key Vocabulary: Function operation
More informationOutline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10
Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays
More informationSDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version
SDS developer guide Develop distributed and parallel applications in Java Nathanaël Cottin sds@ncottin.net http://sds.ncottin.net version 0.0.3 Copyright 2007 - Nathanaël Cottin Permission is granted to
More informationmith College Computer Science CSC231 - Assembly Week #7 Dominique Thiébaut
mith College Computer Science CSC231 - Assembly Week #7 Dominique Thiébaut dthiebaut@smith.edu public class JavaLimits { public static void main(string[] args) { // -----------------------------------------------
More information5.1. Integer Exponents and Scientific Notation. Objectives. Use the product rule for exponents. Define 0 and negative exponents.
Chapter 5 Section 5. Integer Exponents and Scientific Notation Objectives 2 4 5 6 Use the product rule for exponents. Define 0 and negative exponents. Use the quotient rule for exponents. Use the power
More information1. (16 points) Circle T if the corresponding statement is True or F if it is False.
Name Solution Key Show All Work!!! Page 1 1. (16 points) Circle T if the corresponding statement is True or F if it is False. T F The sequence {1, 1, 1, 1, 1, 1...} is an example of an Alternating sequence.
More informationIntroduction to Programming (Java) 3/12
Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationCSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015 Today Registration should be done. Homework 1 due 11:59pm next Wednesday, April 8 th. Review math
More informationMeasuring Goodness of an Algorithm. Asymptotic Analysis of Algorithms. Measuring Efficiency of an Algorithm. Algorithm and Data Structure
Measuring Goodness of an Algorithm Asymptotic Analysis of Algorithms EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG 1. Correctness : Does the algorithm produce the expected output?
More informationName CMSC203 Fall2008 Exam 2 Solution Key Show All Work!!! Page (16 points) Circle T if the corresponding statement is True or F if it is False.
Name CMSC203 Fall2008 Exam 2 Solution Key Show All Work!!! Page ( points) Circle T if the corresponding statement is True or F if it is False T F GCD(,0) = 0 T F For every recursive algorithm, there is
More informationBasic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University
Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic
More informationRegister machines L2 18
Register machines L2 18 Algorithms, informally L2 19 No precise definition of algorithm at the time Hilbert posed the Entscheidungsproblem, just examples. Common features of the examples: finite description
More informationShor s Algorithm. Polynomial-time Prime Factorization with Quantum Computing. Sourabh Kulkarni October 13th, 2017
Shor s Algorithm Polynomial-time Prime Factorization with Quantum Computing Sourabh Kulkarni October 13th, 2017 Content Church Thesis Prime Numbers and Cryptography Overview of Shor s Algorithm Implementation
More informationECE 646 Lecture 5. Mathematical Background: Modular Arithmetic
ECE 646 Lecture 5 Mathematical Background: Modular Arithmetic Motivation: Public-key ciphers RSA as a trap-door one-way function PUBLIC KEY message ciphertext M C = f(m) = M e mod N C M = f -1 (C) = C
More informationAssignment #1 Sample Solutions
CS 320L Applied Discrete Mathematics Spring 2018 Instructor: Marc Pomplun Assignment #1 Sample Solutions Question 1: Hair Splitting with Set Expressions Let us define the successor of the set A to be the
More informationModular Arithmetic (Read Sections 4.1 thro 4.4)
Modular Arithmetic (Read Sections 4.1 thro 4.4) Set of all integers Set of positive integers less than m We want to perform arithmetic in Z m Equivalence Classes Say m = 5 Z m ={0,1,2,3,... m 1} EC of
More informationSlides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006
Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Spring 2006 1 / 1 Computer Science & Engineering 235 Introduction to Discrete Mathematics Sections 2.4 2.6 of Rosen Introduction I When talking
More informationTI-84+ GC 2: Exponents and Scientific Notation
Rev 6-- Name Date TI-84+ GC : Exponents and Scientific Notation Objectives: Use the caret and square keys to calculate exponents Review scientific notation Input a calculation in scientific notation Recognize
More informationNumber Theory Basics Z = {..., 2, 1, 0, 1, 2,...} For, b Z, we say that divides b if z = b for some. Notation: b Fact: for all, b, c Z:
Number Theory Basics Z = {..., 2, 1, 0, 1, 2,...} For, b Z, we say that divides b if z = b for some z Z Notation: b Fact: for all, b, c Z:, 1, and 0 0 = 0 b and b c = c b and c = (b + c) b and b = ±b 1
More information1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;
1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).
More informationCOMS W4995 Introduction to Cryptography September 29, Lecture 8: Number Theory
COMS W4995 Introduction to Cryptography September 29, 2005 Lecture 8: Number Theory Lecturer: Tal Malkin Scribes: Elli Androulaki, Mohit Vazirani Summary This lecture focuses on some basic Number Theory.
More informationA JML Specification of the Design Pattern Visitor
A JML Specification of the Design Pattern Visitor Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University Linz, Austria Wolfgang.Schreiner@risc.jku.at September
More informationSummary: Divisibility and Factorization
Summary: Divisibility and Factorization One of the main subjects considered in this chapter is divisibility of integers, and in particular the definition of the greatest common divisor Recall that we have
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationNumber Sense. Basic Ideas, Shortcuts and Problems #1-20 from the Sequence Chart
UIL Number Sense Contest Basic Ideas, Shortcuts and Problems #1-20 from the Sequence Chart Larry White UIL State Number Sense Contest Director texasmath@centex.net http://www.uiltexas.org/academics/number-sense
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationIntroduction to Computing II (ITI 1121) MIDTERM EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification
More informationGeneralization of Pythagorean triplets, Quadruple Prof. K. Raja Rama Gandhi 1 and D.Narasimha murty 2
The Bulletin of Society for Mathematical Services and Standards Online: 2012-03-01 ISSN: 2277-8020, Vol. 1, pp 40-45 doi:10.18052/www.scipress.com/bsmass.1.40 2012 SciPress Ltd., Switzerland Generalization
More informationAnalysis of Algorithms
Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Analysis of Algorithms Input Algorithm Analysis
More informationCollege Algebra. Basics to Theory of Equations. Chapter Goals and Assessment. John J. Schiller and Marie A. Wurster. Slide 1
College Algebra Basics to Theory of Equations Chapter Goals and Assessment John J. Schiller and Marie A. Wurster Slide 1 Chapter R Review of Basic Algebra The goal of this chapter is to make the transition
More informationMA 180 Lecture. Chapter 0. College Algebra and Calculus by Larson/Hodgkins. Fundamental Concepts of Algebra
0.) Real Numbers: Order and Absolute Value Definitions: Set: is a collection of objections in mathematics Real Numbers: set of numbers used in arithmetic MA 80 Lecture Chapter 0 College Algebra and Calculus
More informationINF Models of concurrency
INF4140 - Models of concurrency Fall 2017 October 17, 2017 Abstract This is the handout version of the slides for the lecture (i.e., it s a rendering of the content of the slides in a way that does not
More informationLecture Notes. Advanced Discrete Structures COT S
Lecture Notes Advanced Discrete Structures COT 4115.001 S15 2015-01-13 Recap Divisibility Prime Number Theorem Euclid s Lemma Fundamental Theorem of Arithmetic Euclidean Algorithm Basic Notions - Section
More informationSEVENTH EDITION and EXPANDED SEVENTH EDITION
SEVENTH EDITION and EXPANDED SEVENTH EDITION Slide 5-1 Chapter 5 Number Theory and the Real Number System 5.1 Number Theory Number Theory The study of numbers and their properties. The numbers we use to
More informationMath 3012 Applied Combinatorics Lecture 4
August 27, 2015 Math 3012 Applied Combinatorics Lecture 4 William T. Trotter trotter@math.gatech.edu The Principle of Math Induction Postulate If S is a set of positive integers, 1 is in S, and k + 1 is
More informationCSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 28: Undecidability of the Halting Problem Emina Torlak and Kevin Zatloukal 1 Topics Final exam Logistics, format, and topics. Countability and uncomputability A quick recap of Lecture 27.
More informationThe Euclidean Algorithm and Multiplicative Inverses
1 The Euclidean Algorithm and Multiplicative Inverses Lecture notes for Access 2009 The Euclidean Algorithm is a set of instructions for finding the greatest common divisor of any two positive integers.
More informationMiddle school mathematics is a prerequisite for Algebra 1A. Before beginning this course, you should be able to do the following:
Syllabus Algebra 1A Course Overview Algebra is a branch of mathematics that uses symbols in place of numbers to describe and generalize relationships. In Algebra 1A, you will explore relationships between
More informationInfinite Sequences and Series Section
A B I L E N E C H R I S T I A N U N I V E R S I T Y Department of Mathematics Infinite Sequences and Series Section 8.1-8.2 Dr. John Ehrke Department of Mathematics Fall 2012 Zeno s Paradox Achilles and
More informationAlgebra 2 Summer Assignment - Non Regents
Name: Date: This assignment is to be completed over the summer. It must be turned in the first day of classes. It will be counted as a quiz. You MUST SHOW all work for each question in the space provided
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!
More informationCSE 311: Foundations of Computing. Lecture 27: Undecidability
CSE 311: Foundations of Computing Lecture 27: Undecidability Last time: Countable sets A set is countable iff we can order the elements of as = {,,, Countable sets: N-the natural numbers Z - the integers
More informationArithmetic Wordsearch
Arithmetic Wordsearch Why didn't the skeleton cross the road? He didn't have the guts. When you locate a word from the list, draw a circle around it. P R O D U C T F R A C T I O N X D P Q E T U C O W R
More informationArthur & Polly Mays Conservatory Of The Arts
Arthur & Polly Mays Conservatory Of The Arts Dear Honors Chemistry Student, This packet is prepared to provide entering students of Honors Chemistry with practice to be familiar with the following skills
More informationHomework #2 solutions Due: June 15, 2012
All of the following exercises are based on the material in the handout on integers found on the class website. 1. Find d = gcd(475, 385) and express it as a linear combination of 475 and 385. That is
More informationJava Programming. Final Examination on December 13, 2015 Fall 2015
Java Programming Final Examination on December 13, 2015 Fall 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (10 points) Multiple choice questions.
More informationLecture 7 Number Theory Euiseong Seo
Lecture 7 Number Theory Euiseong Seo (euiseong@skku.edu) 1 Number Theory God created the integers. All else is the work of man Leopold Kronecker Study of the property of the integers Specifically, integer
More informationConductors in Electrostatic Equilibrium
Lecture 5 Chapter 27 Physics II 09.19.2014 Conductors in Electrostatic Equilibrium 95.144 Course website: http://faculty.uml.edu/andriy_danylov/teaching/physicsii Lecture Capture: http://echo360.uml.edu/danylov201415/physics2fall.html
More informationFunctions and Their Graphs
Functions and Their Graphs DEFINITION Function A function from a set D to a set Y is a rule that assigns a unique (single) element ƒ(x) Y to each element x D. A symbolic way to say y is a function of x
More informationCOT 3100 Applications of Discrete Structures Dr. Michael P. Frank
University of Florida Dept. of Computer & Information Science & Engineering COT 3100 Applications of Discrete Structures Dr. Michael P. Frank Slides for a Course Based on the Text Discrete Mathematics
More information1.00 Lecture 31. Systems of Linear Equations
1.00 Lecture 31 Systems of Linear Equations Reading for next time: Numerical Recipes, pp. 129-139 http://www.nrbook.com/a/bookcpdf.php Systems of Linear Equations 3x 0 + x 1-2x 2 = 5 2x 0 + 4x 1 + 3x 2
More informationAssignment #2 COMP 3200 Spring 2012 Prof. Stucki
Assignment #2 COMP 3200 Spring 2012 Prof. Stucki 1) Construct deterministic finite automata accepting each of the following languages. In (a)-(c) the alphabet is = {0,1}. In (d)-(e) the alphabet is ASCII
More informationDM49-2. Obligatoriske Opgave
DM49-2. Obligatoriske Opgave Jacob Christiansen, moffe42, 130282 Thomas Nordahl Pedersen, nordahl, 270282 1/4-05 Indhold 1 Opgave 1 - Public Exponent 2 1.1 a.................................. 2 1.2 b..................................
More information