Course Home | Homework | Lab Open Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 180
Data Structures

Michael Goldwasser

Spring 2007

Dept. of Math & Computer Science

Homework Assignment 03

Usage of the (simpified) vector class

Contents:


Overview

Topic: Usage of the (simpified) vector class
Related Reading: Ch. 4.1 (and 4.3)
Due: Friday, 16 February 2007, 2:10pm

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


Problems to be Submitted (20 points)

Chapter 4.1 introduces a (simplified) public interface for a vector class. A table of those behaviors is given on page 236 and an animated example of its usage is given as "Example 4.1" on pages 234-235. Our goal in this assignment is to verify that you understand the basic semantics and to have you demonstrate that by working through our own example. You will be responsible for two things:

  1. (12 points)

    string csci140 = "B+";
    string csci150 = "B-";
    string math135 = "B";	
    vector<string> grades;
    grades.push_back(csci140);
    grades.push_back(csci150);
    grades.push_back(math135);	
    // DIAGRAM #1 HERE
    
    cout << grades[1] << endl;      // DESCRIBE OUTPUT
    cout << grades.size() << endl;  // DESCRIBE OUTPUT
    grades[1] = "A-";	
    math135 = "A+";
    // DIAGRAM #2 HERE
    
    grades.insert(1, "C");
    grades.insert(3, "A");
    grades.erase(2);
    grades.pop_back();
    cout << grades.size() << endl;  // DESCRIBE OUTPUT
    cout << grades.at(2) << endl;   // DESCRIBE OUTPUT
    cout << grades.at(3) << endl;   // DESCRIBE OUTPUT
    // DIAGRAM #3 HERE
    

  2. (8 points)

    vector<double> control;
    int j;
    for (j=3; j<7; j++)
      control.push_back(1.2 * j);
    // DIAGRAM #1 HERE
    
    vector<double> measured(control);
    control.pop_back();
    measured[3] = 5.4;
    // DIAGRAM #2 HERE
    
    control.swap(measured);
    control[1] = 3.3;	
    // DIAGRAM #3 HERE
    
    measured = control;
    measured.pop_back();
    // DIAGRAM #4 HERE
    


Michael Goldwasser
CSCI 180, Spring 2007
Last modified: Monday, 12 February 2007
Course Home | Homework | Lab Open Hours | Programming | Schedule & Lecture Notes | Submit