Loyola College in Maryland

CS 301 - Data Structures and Algorithms I
Fall 2003


Loyola College > Department of Computer Science > CS 301 > Homework > Homework 2

Due

Friday, September 12 at the beginning of class

Problems

1. Explain what .data abstraction. means.

Use the following declarations for Problem 2
enum MonthType {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV,

DEC};
class WeatherType {
public:
int avgHiTemp;
int avgLoTemp;
float actualRain;
float recordRain;
};

2. a. Declare a one-dimensional array type, weatherListType, of WeatherType components, to be indexed by values of type MonthType. Declare a variable, yearlyWeather, of weatherListType.

b. Assign the value 1.05 to the actual rainfall member of the July record in yearlyWeather.

c. If the base address of yearlyWeather is 200, what is the address of the member that you assigned in part (b)?

3. For each of the following, write a single statement that performs the indicated task.

a. Get the next character from the input stream without extracting it from the stream.

b. Input a single character into variable c of type char using the istream (cin) member function get in two different ways.

c. Input and discard the next six characters in the input stream.

d. Read 10 characters into a character array name. Stop reading characters if the ... Delimiter is encountered. Do not remove the delimiter from the input stream. Write another statement that performs this task and removes the delimiter from the input.

e. Input an integer value into int variable months and a floating-point value into float variable percentageRate.