Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.

Slides:



Advertisements
Similar presentations
Exercises for CS1512 Week 12 Sets (questions).
Advertisements

Homework #2: Functions and Arrays
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Writing and Testing Programs Drivers and Stubs Supplement to text.
Get number The ginput command creates crosshairs. When the user clicks the x,y values of the crosshairs are returned.
Definition Class In C++, the class is the construct primarily used to create objects.
1 Project 6: Cats in Tree. 2 Project 3: Cats in Tree In this project you will Create a class definition for a Cat class. Populate a BST with Cat information.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Unit 1 Relationships Between Quantities and Expressions Week 3 Lesson 5 Unit Conversations.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Homework #3: Classes and Constructors
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
Homework #5: Pointers, Dynamic Arrays and Inheritance
Type Conversions Implicit Conversion Explicit Conversion.
C++ Basics #7 Basic Input and Output. In this video Standard output (cout) Standard input (cin) stringstream.
Homework #3 J. H. Wang Nov. 1, Homework #3 Chap. 4 –4.1 (c) –4.7 (c) –4.8 (a)(b)(c) –4.11.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
11 Project 2 Towers of Hanoi. 22 Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily.
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.
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.
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Project 3: Ticket Printer
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Homework #1: C++ Basics, Flow of Control, and Function Basics
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
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.
Variables, Types, Expressions Intro2CS – week 1b 1.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011.
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.
Homework #1 J. H. Wang Oct. 24, 2011.
1 Project 2: Sorting Cats. Write a C++ console application to read a text file containing information about cats and output the information to the screen.
Homework 1 (due:April 8th) Deadline : April 8th 11:59pm Where to submit? eClass “ 과제방 ” ( How to submit? Create a folder. The name.
Homework #3: Classes and Constructors
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
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.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
1 Project 4: Venue Sort. 2 This project is an exercise in Using C++ strings. Operator overloading. Text File Input.
CS 240 Computer Programming 1
Chapter 1 Introduction to Java
Data Types and Conversions, Input from the Keyboard
Object-Oriented Programming (OOP) Lecture No. 21
C++ Basic Syntax – Homework Exercises
Chapter 2 Assignment and Interactive Input
Big Data Analytics: HW#3
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Structures Cont. Dr. Xiao Qin Auburn.
Rule Exercises Status of the Ball Definitions and Rule 15
group work #hifiTeam
Use proper case (ie Caps for the beginnings of words)
Learning Objectives String Class.
Introduction to Programming
Python Basics with Jupyter Notebook
Determine the graph of the given function. {image}
CS 101 First Exam Review.
Using string type variables
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.
Hint idea 2 Split into shorter tasks like this.
Lecture 17 – Practice Exercises 3
Lecture 17 – Practice Exercise 3 SOLUTIONS
Presentation transcript:

Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015

Part I: Hand-Written Exercises 1.Is it possible to overload all the operators? 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: A string is a joy forever!

(b) Consider the following code: string s; cout << “Enter a line of input:\n”; getline(cin, s); cout << s << “<End of Output”; If the dialogue begins as follows, what will be the next line of output? Enter a line of input: A string is a joy forever!

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 that converts a string into an integer. For example, given the string “1234” the function should return the integer If you do some research, you will find that there is a function named atoi and also the stringstream class that can do this conversion for you. However, in this Programming Project, you should write your own code to do the conversion. Also test your function in a C++ program.

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

Any Questions or Comments?