Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011.

Slides:



Advertisements
Similar presentations
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Advertisements

Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
Object class.
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,
Problem Solving #1 ICS Outline Review of Key Topics Review of Key Topics Example Program Example Program –Problem 7.1 Problem Solving Tips Problem.
6.1 P OLYNOMIALS Identify, evaluate, add, and subtract polynomials. Classify and graph polynomials. Learning Targets monomial polynomial degree of a monomial.
10.1 Adding and Subtracting Polynomials
EXAMPLE 1 Identify polynomial functions 4 Decide whether the function is a polynomial function. If so, write it in standard form and state its degree,
EXAMPLE 1 Identify polynomial functions
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Warm Up Solve using synthetic OR long division Polynomial Functions A polynomial is written in standard form when the values of the exponents are.
1 Classes Instructor: Mainak Chaudhuri
Homework #3: Classes and Constructors
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
Question and Answer Samples and Techniques. Simplify the expression: (x 4 y -2 )(x -3 y 8 )
Homework #5: Pointers, Dynamic Arrays and Inheritance
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
1.2 Algebraic Expressions 8/24/12. Vocabulary Variable: A letter used to represent one or more numbers Exponent: The number or variable that represents.
1. The term STL stands for ? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Exam 3 Preview.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Text Exercise 12.2 (a) (b) (c) Construct the completed ANOVA table below. Answer this part by indicating what the f test statistic value is, what the appropriate.
Chapter 11 Friends and Overloaded Operators. Introduction to function equal // Date.h #ifndef _DATE_H_ #define _DATE_H_ class CDate { public: CDate();
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
5.2 – Evaluate and Graph Polynomial Functions Recall that a monomial is a number, variable, or a product of numbers and variables. A polynomial is a monomial.
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 10 More on Objects and Classes.
Homework #4: Operator Overloading and Strings By J. H. Wang May 12, 2014.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Homework #3: Classes and Constructors
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
ECE 264 Object-Oriented Software Development
1 Algebra 2: Section 6.2 Evaluating and Graphing Polynomial Functions (Day 1)
Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.
Learners Support Publications Constructors and Destructors.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Real Zeros of Polynomial Functions
Do Now: Match each polynomial function with its graph. Explain your reasoning. Use a graphing calculator to verify your answers. 1. f (x) = x 3 − x 2.
Module 14 Polynomials and Operations
Constructors and Destructors
4.3: Introduction to Polynomials
Andy Wang Object Oriented Programming in C++ COP 3330
COMP 2710 Software Construction Inheritance
Notes Over 3.4 The Rational Zero Test
Do Now: Evaluate the function for the given value of x.
Algebra II Explorations Review ( )
Section 6.2: Polynomials: Classification, Addition, and Subtraction
2.1 Day 2 Homework Answers D: −2,∞
Multiplying Polynomials
Basic C++ What’s a declaration? What’s a definition?
Foundational Data Structures
Notes Over 6.2 Identifying Polynomial Functions Polynomial Function
Constructors and destructors
Constructors and Destructors
Indirection.
5.2 WARM-UP.
5.3 Polynomial Functions By Willis Tang.
CMSC202 Computer Science II for Majors Lecture 10 and 11 – Inheritance
Object class.
5.2B Graphing Polynomial Functions
Objective Please copy on your packet
Presentation transcript:

Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011

Part I: Hand-Written Exercises 1.Give at least three uses of the * operator. Name and describe each use. 2.You know that an overloaded assignment operator and a copy constructor are not inherited. Does this mean that if you do not define an overloaded assignment operator or a copy constructor for a derived class, then that derived class will have no assignment operator and no copy constructor? Please explain your reasons.

Part II: Programming Exercises 3. Using dynamic arrays, implement a polynomial class with polynomial addition, subtraction, and multiplication. Discussion : A variable in a polynomial does nothing but act as a placeholder for the coefficients. Hence, the only interesting thing about polynomials is the array of coefficients and the corresponding exponent. Think about the polynomial x*x*x + x+ 1. Where is the term in x*x? One simple way to implement the polynomial class is to use an array of doubles to store the coefficients. The index of the array is the exponent of the corresponding term. If a term is missing, then it simply has a zero coefficient. (There are techniques for representing polynomials of high degree with many missing terms. These use so-called sparse matrix techniques. Unless you already know these techniques, or learn very quickly, don’t use these techniques.) (To be continued on the next slide…)

(…Continued from the previous slide) (1) Provide a default constructor, a copy constructor, and a parameterized constructor that enables an arbitrary polynomial to be constructed. (2) Supply an overloaded operator = and a destructor. (3) Provide these operations: polynomial+polynomial, constant+polynomial, polynomial+constant, polynomial-polynomial, constant-polynomial, polynomial-constant, polynomial*polynomial, constant*polynomial, polynomial*constant, (4) Supply functions to assign and extract coefficients, indexed by exponent. (5) Supply a function to evaluate the polynomial at a value of type double. You should decide whether to implement these functions as members, friends, or standalone functions.

4. Define a class named Payment that contains a member variable of type float which stores the amount of the payment and appropriate accessor and mutator functions. Also create a member function named paymentDetails that outputs a sentence describing the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s). (To be continued on the next slides…)

(… continued from the previous slide) Define a class named CreditCardPayment that is derived from Payment. This class should contain member variables for the name on the card, expiration date, and credit card number. Include appropriate constructor(s). Finally, redefine the paymentDetails function to include all credit card information in the printout. Create a main function that creates at least two CashPayment and two CreditCardPayment objects with different values and calls to paymentDetails for each.

Homework Submission Due: 2 weeks (June 14, 2011) Hand-written exercises –Please write your names and answers on papers. Programs –Please submit to homework submission Web site: