CS Haskell Assignment 2 Solution

$30.00 $24.00

Overview For this assignment you are encoding the decision process that a committee chairman uses to determine if a committee meeting will be held or cancelled. The entire problem involves reading lines of data from a le, and for each line of data, determine if the meeting will be cancelled. You are not writing code…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Overview

For this assignment you are encoding the decision process that a committee chairman uses to determine if a committee meeting will be held or cancelled. The entire problem involves reading lines of data from a le, and for each line of data, determine if the meeting will be cancelled. You are not writing code for the entire problem, instead, you are writing a module which will include a function which will process its arguments and have a value of a tuple (number, True) if the meeting will be held, (number, False) if the meeting is cancelled. The number in the tuple is the number of committee members who arrived early enough to participate. The idea is that a meeting will be held if enough committee members arrive early enough to hold the meeting. The committee chairman is not always patient, and will wait for some time (or not wait at all) for enough members to arrive.

Speci cs

Your program will work on a le containing lines of integers.

The rst integer on a line will be the number of members who must arrive at or before the wait time in order to hold a meeting. This will be a positive integer no larger than the number of committee members.

The second integer on the line will be the wait time. This is an integer value of 0 or larger. A value of 0 means that committee members must arrive on time or earlier. A positive wait time means the chairman will wait that many minutes before cancelling the meeting. For example, a wait time of 3 means the chairman will not cancel the meeting if enough committee members arrive up to a time of 3 minutes late.

The remaining integer values on the line will be arrival times. These are integers which are negative, 0, or positive. An arrival time of 0 means the member arrived exactly on time. A negative value means the committee member arrived early, for example, -5 means an arrival time of 5 minutes early. A positive value means the committee member arrived that many minutes late.

The portion of the program which does input and output will be provided to you as part of this assignment. This portion of the code is located in module Main, which is stored in le Main.hs. You will write module HoldMeeting which you will store in le HoldMeeting.hs. HoldMeeting will have a function holdMeeting of

type

holdMeeting :: String -> (Int, Bool)

in which String is a line from the input le, and Bool is True if the meeting will be held, False if the meeting will be cancelled. Note that all you are really doing is converting the String argument into a list of Int, considering the rst Int value as the number required to be of size max or smaller, the second int value is this max. Your code will count how many of the rest of the Int values in the list are less than or equal to the max value. This count is the Int part of the tuple your function evaluates to. If this count is the number required or bigger, your function will evaluate to (count, True), otherwise it evaluates to (count, False).

Sample input le

320-14175-3

40760821-10

1

Output from sample input le

Committee

Meeting

Held

Members Needed

Members

on Time

Meeting Held

3

3

yes

4

3

no

Explanation of the example input lines:

320-14175-3

3 committee members must arrive before the wait time expires ( rst integer on line).

2 is the wait time (second integer on line).

The only integers of size 2 are smaller are (in order) 0 -1 -3 and there are three of these so holdMeeting evaluates to (3, True)

40760821-10

4 members are required

0 wait time means members must arrive on time or early (only 0 and negative values are counted). Arrival times which can be counted are (in order) 0 -1 0 and there are only 3 of these which is smaller

than the required 4, thus the function evaluates to (3, False)

Deliverables

Submit your source code module HoldMeeting (in le HoldMeeting.hs) via Blackboard by 11:59:59 p.m. on Friday May 17. You should have this project completed by lab time during week 7, but if not, be prepared to ask questions about problems you are having.

Put comments in your program telling me who you are and what each function you have written does.

This lab is worth 30 points.

2

CS Haskell Assignment 2 Solution
$30.00 $24.00