Homework #4: Operator Overloading and Strings By J. H. Wang May 12, 2014.

Slides:



Advertisements
Similar presentations
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1 Overview 8.1 An Array Type for Strings 8.2 The Standard string.
Chapter 10.
Friday, January 05, 2007 A few weeks of developing and testing can save a whole afternoon in the library. -Anonymous.
C-Strings A C-string (also called a character string) is a sequence of contiguous characters in memory terminated by the NUL character '\0'. C-strings.
CS161 Introduction to Computer Science Character Data.
Definition Class In C++, the class is the construct primarily used to create objects.
Determine whether each curve below is the graph of a function of x. Select all answers that are graphs of functions of x:
1 Chapter 10 Characters, Strings, and the string class.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT8: Characters and Strings CS2311 Computer Programming.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Homework #3: Classes and Constructors
5-1 C201 Schedule of First Two Weeks: Review of C101  Week 1  Functions  Array and sorting  Week 2  C-String  An application.
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
Homework #5: Pointers, Dynamic Arrays and Inheritance
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
Copyright © 2012 Pearson Education, Inc. Chapter 10: Characters, C- Strings, and More About the string Class.
9-1 Learning Objectives  An Array Type for Strings  C-Strings.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10: Characters, Strings, and the string class.
Characters, Strings, And The string Class Chapter 10.
IR Homework #1 By J. H. Wang Mar. 5, Programming Exercise #1: Indexing Goal: to build an index for a text collection using inverted files Input:
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
CSC 270 – Survey of Programming Languages
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Project 3: Ticket Printer
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 10 Characters, Strings, and the string class.
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
Chapter 15 Strings as Character Arrays
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009.
An Array Type For Strings. Two ways to represent strings – i.e. “Hello” cstring An array with base type char Older way of processing strings Null character.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
More about strings in C++. String member functions The next three slides present information about functions that are members of the C++ string class.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011.
Chapter Characters, Strings, and the string class 10.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
11 Introduction to Object Oriented Programming (Continued) Cats.
Homework #3: Classes and Constructors
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.
Slide 1 Chapter 9 Strings. Slide 2 Learning Objectives  An Array Type for Strings  C-Strings  Character Manipulation Tools  Character I/O  get, put.
Identities, Contradictions and Conditional Equations.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Eight: Streams Slides by Evan Gallagher.
Chapter 1 Introduction to Java
Selection Control Structure
Fundamentals of Characters and Strings
Rule Exercises Status of the Ball Definitions and Rule 15
getline() function with companion ignore()
Use proper case (ie Caps for the beginnings of words)
Learning Objectives String Class.
Strings A collection of characters taken as a set:
Algorithms computer as the tool process – algorithm
CS 101 First Exam Review.
C++ Programming Lecture 20 Strings
Today’s Objectives 28-Jun-2006 Announcements
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
getline() function with companion ignore()
Lecture 17 – Practice Exercises 3
Lecture 17 – Practice Exercise 3 SOLUTIONS
Chapter 12: More on C-Strings and the string Class
Presentation transcript:

Homework #4: Operator Overloading and Strings By J. H. Wang May 12, 2014

Part I: Hand-Written Exercises 1.What is the difference between a friend function for a class and a member function for the class? What are the advantages of a friend function? 2.Why can’t we overload >> or << as member operators?

3. Consider the following code (and assume it is embedded in a complete and correct program and then run): (a) string s1, s2; cout > s1 >> s2; cout << s1 << ‘-’ << s2 << “<End of Output”; If the dialogue begins as follows, what will be the next line of output? Enter a line of input: Los Angeles is the city of Angels.

(b) Consider the following code: string s; cout << “Enter a line of input:\n”; cin.getline(s, 11); cout << s << “<End of Output”; If the dialogue begins as follows, what will be the next line of output? Enter a line of input: Los Angeles is the city of Angels.

Part II: Programming Exercises 4. Do Programming Project 6.10, the definition of a Weight class, except overload ==, > operators. The == operator should return true if the two weight values are identical, while > should input the weight in pounds. Create appropriate tests for the overloaded operators.

(Project 6.10: Create a Weight class that internally stores a weight in kilograms. However, create functions named setWeightPounds and set WeightKilograms that takes an input weight and converts the weight to kilograms, and stores that weight in the class member variable. Also create functions that return the stored weight in kilograms and pounds. Write a main function to test your class. Use the equations below to convert between the two weight scales. 1 kilogram = pounds 1 pound = kilogram)

5. Write a function to compare two C-strings for equality. The function should return true if the strings are equal and false if they are not. Your function should ignore case, punctuation, and whitespace characters. Test your function in a C++ program with a variety of input strings. [Note: Please do not use the standard library functions such as strlen(), strcmp(), and strncmp(). ]

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

Any Questions?