Art Show | Course Home | Homework | Labs | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science P125
Introduction to Computer Science

Michael Goldwasser

Spring 2005

Dept. of Math & Computer Science

Homework Assignment 03

Using String Objects

Contents:


Overview

Topic: Using String Objects
Related Reading: Ch. 3
Due: Friday, 11 February 2005, 12:00pm

Please make sure you adhere to the policies on academic integrity.


Practice Problems

Please note that the answer to "self-check" questions from the text are available via the author's website.


Problems to be Submitted (20 points)

  1. (20 points)

    Consider the following declarations:

    string greet = "Hello!";
    string welcome = "Welcome to computer science";
    string com = "to";
    What is the output of each of these subsequent code fragments?
    1. cout << greet.size() << endl;

    2. cout << welcome.size() << endl;

    3. cout << (com+com) << endl;

    4. cout << welcome.substr(8,5) << endl;

    5. cout << welcome.substr(5,8) << endl;

    6. cout << welcome.find("e") << endl;

    7. cout << welcome.find("e",10) << endl;

    8. cout << welcome.find("com") << endl;

    9. cout << welcome.find("com",5) << endl;

    10. cout << welcome.find(com) << endl;


Extra Credit

  1. (2 points)

    Exercise 3.31 of the text (p. 151)
    A code fragment is sufficient (i.e. you do not need to specify all of the typical header information needed for a truly compilable program).


Michael Goldwasser
CS-P125, Spring 2005
Last modified: Thursday, 03 February 2005
Art Show | Course Home | Homework | Labs | Programming | Schedule & Lecture Notes | Submit