Type Conversions Lecture 14 Wed, Feb 22, 2006.

Slides:



Advertisements
Similar presentations
Operator overloading redefine the operations of operators
Advertisements

For(int i = 1; i
12-8 Mixed Expressions and Complex Fractions Objective Students will be able to simplify complex fractions.
Introduction to Programming Lecture 39. Copy Constructor.
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
Operator Overloading Fundamentals
C++ Features and Constructs Ch. 3 except 3.2, 3.4, 3.9, 3.11.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
CS-240 Operator Overloading Dick Steflik. Operator Overloading What is it? –assigning a new meaning to a specific operator when used in the context of.
7.3 Reduce Rational Expression Before we start, let’s look at some definitions… A Rational (Rational Expression): A fraction that has a polynomial (something.
Decimals and Fractions
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Case Study - Fractions Timothy Budd Oregon State University.
Rational numbers. Whole numbers Whole numbers Rational numbers Whole numbers Natural numbers Integers / ¾ 18% A rational number.
Operator Overloading & Exception Handling TCP1201 OOPDS 1 Lecture 5 1.
12-6 Rational Expressions with Like Denominators Objective: Students will be able to add and subtract rational expressions with like denominators.
 Multiply rational expressions.  Use the same properties to multiply and divide rational expressions as you would with numerical fractions.
CISC105 – General Computer Science Class 9 – 07/03/2006.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Part 9:
Unit: 7 Operator Overloading and Type Conversions Course: MBATech Trimester: II.
Add & Subtract Rationals – Common Denominator To add or subtract rational expressions with common denominators: 1) Add or subtract the numerators 2) Write.
Conversion of Fractions - Mixed Number to Improper Fraction
Ch 8: Exponents D) Rational Exponents
Section 9.4 Combining Operations and Simplifying Complex Rational Expressions.
1 Lecture 17 Operator Overloading. 2 Introduction A number of predefined operators can be applied to the built- in standard types. These operators can.
Methods Methods are how we implement actions – actions that objects can do, or actions that can be done to objects. In Alice, we have methods such as move,
Rational Exponents Rules Examples Practice Problems.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
OpenGL Shading Language
To simplify a rational expression, divide the numerator and the denominator by a common factor. You are done when you can no longer divide them by a common.
Date: Topic: Simplifying Radicals (9.1) Warm-up:Find the square root Simplify the radical:
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Object-Oriented Programming (OOP) Lecture No. 16
Adding and Subtracting Rational Expressions
6.8 Multiplying and Dividing Rational Expressions
CSC 143 Introduction to C++ Classes and User-Defined Data Types
Programming with ANSI C ++
Operator overloading Conversions friend inline
Operator overloading Conversions friend inline
Developed By : Ms. K. S. Kotecha
Object-Oriented Programming (OOP) Lecture No. 21
Lecture 16: Introduction to Data Types
Operator overloading Conversions friend inline
Object-Oriented Programming (OOP) Lecture No. 16
Operator Overloading BCA Sem III K.I.R.A.S.
Type Conversions Lecture 13 Wed, Feb 21, 2007.
Conversions of the type of the value of an expression
Data Types and Expressions
Unit-2 Objects and Classes
Advanced Program Design with C++
Multiplying and Dividing Rational Expressions
Simplify Complex Rational Expressions
Operator overloading Dr. Bhargavi Goswami
Simplifying Complex Rational Expressions
5.7 Rational Exponents 1 Rules 2 Examples 3 Practice Problems.
Default Arguments.
Complex Rational Expressions
The Destructor and the Assignment Operator
Type Conversions Lecture 14 Wed, Feb 18, 2004.
COMS 261 Computer Science I
7.4 Adding and Subtracting Rational Expressions
COP 3330 Object-oriented Programming in C++
Java Programming Language
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Warm-Up Which expression below represents the following: seven less than the product of two and a number? Write one sentence explaining why. 7 – 2x.
The Constructors Lecture 7 Fri, Feb 2, 2007.
Unit 3: Rational Expressions Dr. Shildneck September 2014
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
Unit-2 Objects and Classes
Presentation transcript:

Type Conversions Lecture 14 Wed, Feb 22, 2006

Topics Constructors as type converters Conversion operators 11/9/2018 Type Conversion

Conversion of Types Frequently in a program an object must be converted from one type to another. For the built-in types, this is done automatically whenever it is sensible. Convert float to int. Convert int to float. How can it be done with created types? 11/9/2018 Type Conversion

Converting to a Created Type A class uses its constructors to define rules for converting an object of another type to an object of that type. The prototype is Class-name::Class-name(other type); Rational::Rational(int); Complex::Complex(double); 11/9/2018 Type Conversion

Example: Convert int to Rational // Rational constructor Rational::Rational(int n) { numerator = n; denominator = 1; return; } // Usages int i = 100; Rational r(i); Rational r = i; r = (Rational)i; r = Rational(i); 11/9/2018 Type Conversion

Example How would you convert a Point to a Vector? 11/9/2018 Type Conversion

Converting to a Built-in Type Sometimes we want to convert an object of a created type to an object of a built-in type. For example, we might want to convert A Rational to a float. A Complex to a double. For this we need a conversion operator. 11/9/2018 Type Conversion

Conversion Operators A conversion operator has prototype The operator converts the created-type object to the built-in type and returns the object of the built-in type. Class-name::operator built-in-type() const; Rational::operator float() const; Complex::operator double() const; 11/9/2018 Type Conversion

Example: Convert Rational to float Rational::operator float() const { return (float)numerator/denominator; } 11/9/2018 Type Conversion