Homework 1 Exercises on Data Structures and Algorithms | CSCE 310, Assignments of Algorithms and Programming

Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science and Engineering ; University: University of Nebraska - Lincoln; Term: Fall 2004;

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-91t
koofers-user-91t 🇺🇸

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCE 310 Data Structures & Algorithms
Fall 2004
Steve Goddard
Homework 1, September 2
(Total of 100 points)
Chapters 1 and (portions of) 2
Due: 9:00pm Thursday, September 16, 2004
____________________________________________________________
Exercises from the Text (50 points):
Section 1.1 #4, #5
Section 1.2 #4
Section 1.3 #1
Section 1.4 #10
Section 2.2 #1, #2
Section 2.3 #6
____________________________________________________________
Programming Exercises (50 points):
Given below is a generic List ADT. From this ADT, write three implementations in C++, one using a
stack, one using a priority queue, and one using a linked list.
bool isEmpty(FloatList list) – returns true if the list is empty, otherwise false.
FloatList constructList(float newElement, FloatList oldList) – constructs a new list with copies of all of the
elements from oldList and newElement
Precondition: oldList is a list with 0 or more elements
Postcondition: the list returned by constructList contains newElement
float firstElement(floatList list) – returns the first element in the list, but does not remove it
Precondition: isEmpty(list) == false
Postcondition: none
FloatList restOfList(FloatList oldList) – returns a copy of list that contains every element except
firstElement(oldList)
Precondition: oldList is a list with 1 or more elements
Postcondition: newList = restOfList(oldList)
newList contains every element in oldList except the first element
Note: This is an abstract definition of the operations that the List ADT should perform. It is your job to
create classes for this ADT which implement at least these features.
What the program does
pf3

Partial preview of the text

Download Homework 1 Exercises on Data Structures and Algorithms | CSCE 310 and more Assignments Algorithms and Programming in PDF only on Docsity!

CSCE 310 Data Structures & Algorithms

Fall 2004

Steve Goddard

Homework 1, September 2

(Total of 100 points)

Chapters 1 and (portions of) 2

Due: 9:00pm Thursday, September 16, 2004

____________________________________________________________

Exercises from the Text (50 points):

Section 1.1 #4, # Section 1.2 # Section 1.3 # Section 1.4 # Section 2.2 #1, # Section 2.3 #

____________________________________________________________

Programming Exercises (50 points):

Given below is a generic List ADT. From this ADT, write three implementations in C++, one using a stack, one using a priority queue, and one using a linked list.

bool isEmpty(FloatList list) – returns true if the list is empty, otherwise false.

FloatList constructList(float newElement, FloatList oldList) – constructs a new list with copies of all of the elements from oldList and newElement Precondition: oldList is a list with 0 or more elements Postcondition: the list returned by constructList contains newElement

float firstElement(floatList list) – returns the first element in the list, but does not remove it Precondition: isEmpty(list) == false Postcondition: none

FloatList restOfList(FloatList oldList) – returns a copy of list that contains every element except firstElement(oldList) Precondition: oldList is a list with 1 or more elements Postcondition: newList = restOfList(oldList) newList contains every element in oldList except the first element

Note : This is an abstract definition of the operations that the List ADT should perform. It is your job to create classes for this ADT which implement at least these features.

What the program does

We are interested in generating forecasts of sales data based on the three calculations below. Your task is to write a program called forecast that will take as its arguments the name of a data file and the name of a product. From these arguments, the program will extract the data needed to perform calculations for the specified product. You must use the generic ADT List defined above. For the data file, use the comma- delimited file similar to the one for Homework 0.

The output of the program, if the product is listed in the data file, should be exactly as below (truncate values to integers for the output, but not during the calculations, as this would decrease the accuracy of the results):

Product: Wheel Simple average: 2491 Slope: 2019 Linear regression: 2148

If the product is not found in the file, the output should be exactly as below:

Product productName not found in fileName

Where productName is the name of the product and fileName is the name of the input file. For example, if the product Wheel is not found in the file Forecast, the output should be exactly as below:

Product Wheel not found in Forecast

Desired forecasts I. Simple average – use the average number of historical products needed in the file given to estimate the next period’s value.

Numberof periods

Historicalvalues

Forecasted value

II. Slope – use the slope of the line between the first and last points to estimate the future value

Forecastedvalue ( Slope )( Numberof periods ) Intercept

Intercept Firsthistoricalvalue Slope First periodnumber

First periodnumber Last periodnumber

Firsthistoricalvalue Lasthistoricalvalue Slope

III. Linear regression – use a linear regression to find a best-fitting line, and then evaluate the point on the line that represents the next period to find its forecasted value.

Forecastedvalue ( Slope )( Numberof periods ) Intercept

Numberof periods

SumY Slope SumX Intercept

Numberof periods SumXSquared SumX SumX

Numberof periods SumXY SumX SumY Slope

SumXSquared Period number Periodnumber

SumXY Periodnumber Historicalvalue

SumY Historicalvalues

SumX Periodnumber