SOLUTION_2.1

# SOLUTION_2.1 - CS 31 Introduction to Computer Science I...

This preview shows pages 1–3. Sign up to view the full content.

CS 31: Introduction to Computer Science I: Winter 2010: Homework 2.1 Solution Page 1 // UCLA Winter 2010 // CS 31 Homework 2.1: Vector Operations // John A. Rohr // February 20, 2010 // // // This program performs input and output of vectors. // // A vector of dimension m consists of m elements in consecutive order. // // The program handles vectors of dimension 1 to 10. // // The program can hold one vector at a time. // // The program first reads a vector dimension. If the dimension is negative, // the program terminates. If the dimension is zero or too large, the program // reads the dimension again. If the dimension is valid, the program reads // values for each of the elements of the vector, then displays the vector. // // The program continues until a negative dimension is input. // // All input is read from the file Hw21.In if it can be opened. Otherwise all // input is read from the keyboard. All output is written to cout and the file // Hw21.Out if it can be opened. Otherwise all output is written to cout only. #include <iostream> #include <fstream> using namespace std; // ************************************************************************** // * * // * GLOBAL CONSTANTS * // * * // ************************************************************************** const string INFILE_NAME = "Hw21.In"; const string OUTFILE_NAME = "Hw21.Out"; const int MAX_DIM = 10; // Maximum vector dimension const int PRECISION = 4; // Precision of double output const string TITLE = "VECTOR INPUT AND OUTPUT"; const string DIMPMT = "Dimension:"; const string VELTPMT = "Vector Elements:"; const string VHEAD = "Vector:";

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 31: Introduction to Computer Science I: Winter 2010: Homework 2.1 Solution Page 2 // ************************************************************************** // * * // * GLOBAL VARIABLE DECLARATIONS * // * * // ************************************************************************** ifstream fin; // Input file ofstream fout; // Output file // ************************************************************************** // * * // * MAIN PROGRAM
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

SOLUTION_2.1 - CS 31 Introduction to Computer Science I...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online