CIS 67 Lab Assignments Summer 2001

Lab Assigment Guide:

You have two classes to complete the assignment. For example, Lab 1 should be completed by Thursday , May 24.

Each assignment should include an algorithm and data analysis.


 

Lab 1: May 22

Use Unix
0. Examine metric.cpp.
1. Write and execute the Miles conversion program listed on page 40
2. Eliminate the semicolon at the end of the line
float miles;
and observe the error message.
3. Write, execute and submit programming project #3. (P97)


Note that you do not need to submit parts 1 and 2.


Lab 2: May 24

Write and execute programming project #2. (P97)

Use cin for input and cout for output.
Add an additional line to output their integer quotient:
quotient(int) -- integer quotient of x divided by y.
Test your program with the following pairs:
12 and 4
12 and 5
-12 and 5
12 and -5
-12 and -5



Lab 3: May 29
 
Write and execute a program called roots.cpp which will display the roots of a quadratic equation with integer coefficients. See discussion in Example 3.2 (P117).
The program should use the following function to obtain the coefficients a, b, and c of the quadratic ax^2 + bx + c:
get_int
Declaration
//Prompt user for an integer value
int get_int
(string str); //IN: user prompt
Usage
a = get_int ( "Enter the coefficient of x^2: " );


The program should then compute the discriminant disc = b^2 - 4ac

Using the if-then-else statement (see pp182-183), the program should handle the following alternatives (branches):

If disc < 0, the program should indicate that the quadratic equation has no roots.
Otherwise the program should display the roots of the equation.
In both cases, the quadratic equation should be included in the output.
Bonus point: You can earn a bonus point by formatting the floating point numbers as indicated in 5.3 (PP244-245).



Lab 4: May 31
 
Write and execute programming project #9. (P225)
Test your program with the following pairs:
h and 40000 gallons
c and 3 million gallons
c and 5 million gallons
i and 3 million gallons
i and 5 million gallons
i and 15 million gallons



Lab 5: June 5
 
Write and execute a program called letters.cpp which will prompt the user to enter a word and then display each letter of the word along with the number of times the letter occurs.
If the user enters abracadabra, then the program should output the following:
word: abracadabra
letters: 11
 
a     5
b     2
r     2
c     1
d     1
 
 

You should use the member functions of the C++ string class (p150).

Outline: Take the first letter a and count its frequency 5. While counting, delete it from the word to produce the reduced word brcdbr. Output the letter and its frequency. Repeat until the word is empty.

Test your program with some words of length 10 or more.

Bonus point: You can earn a bonus point by outputting the letters in alphabetical order.



No lab for Thur, June 7

All outstanding labs must be handed in by 2.00 pm on Fri.


Lab 6: Tues June 12 (due June 19)


Programming Project 5 on P477.

Use the keyboard to input the data. The data should include 20 households.
Use an external file to write out the data for part (a).
Format the three columns and include the headers as shown
Add the ouput for parts (b) and (c) to the end of the external data file.
Note that the arrays should have a declared size of 25
Submit the program together with its ouput file.

 

 

Bonus 2 points:
Declare a struct called household consisting of three integer fields id_no, annual_income and size
Declare an array survey of size 25 and type household.
Read the data for each household into the corresonding array element.



Lab 7: June 14 (due June 21)
Modify Lab 6 in the following fashion.
Write a program getData which prompts the user for the following data:
Last name of head of household
First name of head of household
ID number for household
Annual income
Size
The data should be (appended) to an external file "household.dat". Look at the example program


Writing integers and their hex equivalent to a file.

The data for each household should be written on a formatted line. For example:

Clinton               William               2000               3               100,000


Input the data for at least 20 households. Your program shoud write the data for one household at a time (no need for a terminal character). That is, to enter the data for 20 households, you need to run the program 20 times.

Your main program from Lab 6 should be modified to retrieve its data form the file "household.dat" (ignoring the household name fields). The data should be read into the array survey as described in the bonus part of Lab 6. The output should be to the external file "survey.dat".
Submit the three programs together with the files "household.dat" and "survey.dat".

 

 

Bonus 3 points: Write a program survey which ouputs the data in "household.dat", listed in the order of the last name of the head of household, to an external file.



Lab 8:Tues June 19

Repeat Lab 5, using Visual C++
Output characters in alphabetical order


Lab 10: Thurs June 21

Construction of a rational number class (based on class handout)

Incomplete Rational class


Lab 11: Tues June 26

Implement the Stack Abstract Data Type as described in 11.8 and 11.9.

Programming Project 1 on P597 and P601.

Test your methods.

Bonus 3 points: Use pointers for your implementation (see 13.4).