Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
1 Week 2 Questions / Concerns Schedule this week: Homework1 & Lab1a due at midnight on Friday. Sherry will be in Klamath Falls on Friday Lexical Analyzer.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Strings Testing for equality with strings.
Strings.
Classes and Data Abstraction Lecture 9. Objects Models of things in the real world Defined in classes  Class name is the object name Example: Library.
Character I/O. COMP104 Character I/O Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable.
Characters. COMP104 Lecture 21 / Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable assignment.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
An Introduction to Textual Programming
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT8: Characters and Strings CS2311 Computer Programming.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Homework #3: Classes and Constructors
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
September1999 CMSC 203 / 0201 Fall 2002 Week #8 – 14/16 October 2002 Prof. Marie desJardins.
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
COMP313A Programming Languages Lexical Analysis. Lecture Outline Lexical Analysis The language of Lexical Analysis Regular Expressions.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
9-1 Learning Objectives  An Array Type for Strings  C-Strings.
Lab5 Please submit the lab before you leave Please include at a minimum your name, the date, and the lab- program number at the top of the program as a.
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.
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 #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
1 CS161 Introduction to Computer Science Topic #8.
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
Chapter 9 Strings. Learning Objectives An Array Type for Strings – C-Strings Character Manipulation Tools – Character I/O – get, put member functions.
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.
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Homework #2 J. H. Wang Mar. 29, Homework #2 Chap.3 –3.5 (a) –3.8 (b) –3.16 –3.23 (a)
Homework #3: Classes and Constructors
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Slide 1 Chapter 9 Strings. Slide 2 Learning Objectives  An Array Type for Strings  C-Strings  Character Manipulation Tools  Character I/O  get, put.
A Sample Program #include using namespace std; int main(void) { cout
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Strings in Python String Methods. String methods You do not have to include the string library to use these! Since strings are objects, you use the dot.
Constants, Data Types and Variables
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
DEVRY COMP 122 L AB 7 L AB R EPORT AND S OURCE C ODE C HECK THIS A+ TUTORIAL GUIDELINE AT HTTP :// WWW. ASSIGNMENTCLOUD. COM / COMP -122/ COMP LAB.
Last week: We talked about: History of C Compiler for C programming
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Strings (part 2) Dr. Xiao Qin Auburn.
Chapter 9 Strings Copyright © 2016 Pearson, Inc. All rights reserved.
Data Transfer ASCII FILES.
Announcements 2nd homework is due this week Wednesday (October 18)
Manipulating Text In today’s lesson we will look at:
Announcements 3rd homework is due this week Wednesday (March 15)
CEV208 Computer Programming
String What it is Why it’s useful
Chapter 9 Strings Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Announcements HW1 is due TODAY.
getline() function with companion ignore()
Presentation transcript:

Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009

Part I: Hand-Written Exercises 1. (a) What is the difference between an operator and a function? (b) What is the difference between a friend function for a class and a member function for the class?

2. What (if anything) is wrong with the following code? char stringVar[] = “Hello”; strcat(StringVar, “ and Good-bye.”); cout is in the program file.

3. How many characters are in each of the following character and string constants? a.‘\n’ b.‘n’ c.“Mary” d.“M” e.“Mary\n”

Part II: Programming Exercises 4.Define a class named MyInteger that stores an integer and has functions to get and set the integer’s value. Then, overload the [] operator so that the index returns the digit in position i, where i=0 is the lease-significant digit. If no such digit exists then -1 should be returned. For example, if x is of type MyInteger and is set to 418, then x [0] should return 8, x [1] should return 1, x [2] should return 4, and x [3] should return -1.

5.Write a program that will read in a line of text and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas, and periods. When outputting the number of letters that occur in a line, be sure to count upper and lowercase versions of a letter as the same letter. Output the letters in alphabetical order and list only those letters that occur in the input line. For example, the input line “I say Hi.” should output similar to the following: 3 words 1 a 1 h 2 i 1 s 1 y

Homework Submission Due: 3 weeks (May 8, 2009) Hand-written exercises –Please write your names and answers on A4 papers. Programs –Forum: –Submission site: