Lab I Questions - Object Oriented Data Structure | COMP 310, Lab Reports of Data Structures and Algorithms

Material Type: Lab; Class: OBJECT ORIENTED DATA STRUCTURE; Subject: Computer Science; University: Wentworth Institute of Technology; Term: Unknown 1989;

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-84a
koofers-user-84a 🇺🇸

8 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 1 - due Jan 18
1. Arrays. Write a program which creates an array x containing 100 randomly chosen
integers in the range 0 .. 99. The main() function asks the user to enter a target number to
search for, then tells the user how many times it was found in the array.
You may use this code for generating random numbers:
srand( (unsigned)time( NULL ) ); /* to seed the random
number stream for fresh random numbers */
rand()%n; /* to generate a random number in the range 0 ..
n-1 */
2. You are to create a personal telephone directory with these capabilities:
1. Add new entry
2. Lookup phone number
3. Change phone number
4. Remove entry
5. Print all entries
6. Exit
A phone entry is a struct with these fields:
firstname: 10 chars
lastname: 15 chars
phone: 15 chars
Use either a struct or a class to create the ENTRY type.
The main() function sets up an infinite loop which presents a menu of choices to the user
and carries out the request.
Phone entries are to be kept in an array of size MAXSIZE, which is defined. The main()
function declares the array, and keeps track of the next available slot for adding a new
entry. When an entry is removed, the entries following it are moved down to fill the gap.
Provide a find function, which asks the user for the first and last names of the entry to
find. It then returns the array index of the entry, or -1 if not found. The lookup, change
and remove functions start off by calling find.
3. Modify problem 2 in the following ways:
Change the array to be an array of pointers to ENTRY, rather than an array of ENTRY.
The function, which adds a new entry, must allocate space for it using malloc and return a
pointer. Removing an entry should free the memory.
pf3
pf4
pf5

Partial preview of the text

Download Lab I Questions - Object Oriented Data Structure | COMP 310 and more Lab Reports Data Structures and Algorithms in PDF only on Docsity!

Lab 1 - due Jan 18

  1. Arrays. Write a program which creates an array x containing 100 randomly chosen integers in the range 0 .. 99. The main() function asks the user to enter a target number to search for, then tells the user how many times it was found in the array. You may use this code for generating random numbers: srand( (unsigned)time( NULL ) ); /* to seed the random number stream for fresh random numbers / rand()%n; / to generate a random number in the range 0 .. n-1 */
  2. You are to create a personal telephone directory with these capabilities:
    1. Add new entry
    2. Lookup phone number
    3. Change phone number
    4. Remove entry
    5. Print all entries
    6. Exit A phone entry is a struct with these fields: firstname: 10 chars lastname: 15 chars phone: 15 chars Use either a struct or a class to create the ENTRY type. The main() function sets up an infinite loop which presents a menu of choices to the user and carries out the request. Phone entries are to be kept in an array of size MAXSIZE, which is defined. The main() function declares the array, and keeps track of the next available slot for adding a new entry. When an entry is removed, the entries following it are moved down to fill the gap. Provide a find function, which asks the user for the first and last names of the entry to find. It then returns the array index of the entry, or -1 if not found. The lookup, change and remove functions start off by calling find.
  3. Modify problem 2 in the following ways: Change the array to be an array of pointers to ENTRY, rather than an array of ENTRY. The function, which adds a new entry, must allocate space for it using malloc and return a pointer. Removing an entry should free the memory.
  1. (Extra credit - 1 point) The find function is passed a match function, which is used to determine if an entry matches the one being looked for. The formal match function takes 2 ENTRY* parameters and returns true or false. The actual match functions passed to it are:  matchByFname  matchByLname  matchByBothNames Add menu choices to see if the user would like to search by first name, last name, or both.
  2. (Extra credit - 1 point) Add menu choices and functions to save your telephone directory into a file and load it from the file. Use fread and fwrite.

Lab 3 due Feb 1

p. 164 #

Lab 4 due Feb 8

p. 164 # p. 207 #

Lab 5 due Feb 22

p. 208 #12, #14ac

Lab 6 due Mar 1

  1. p. 226 #5,6,7,
  2. Write a function named average, which is passed a queue of doubles, and returns their average. Write a driver to test your average function.
  3. Extra Credit (2 points) p. 227 #

Lab 7 due Mar 15

  1. p. 267 Exercises 4,5,6 (For 6 use a simple sort like bubble sort)
  2. p. 315 #4,5,6 (drivers to test template functions in part 1)

Lab 8 due Mar 22

  1. p. 289 Exercise 17 (Convert the Queue class from Exercise 5 of Sec 5.2 into a class template.)
  2. p. 315 #11 (test your queue class)
  3. p. 290 Exercise 15 (A template function to see if the values stored in a vector are in ascending order)
  4. p. 315 #9 (Test the above function)

Lab 9 due Mar 29

  1. p. 317 #28 prime factorization
  1. p. 317 #30 Memory Recall queue
  2. (extra credit - 2 points) p.315 #18 Pascal's Triangle

Lab 10 - due Apr 5

p. 389 5a p. 464 1 In this lab you will create a polynomial class. The book suggests using a linked list to hold the terms. You may find it easier to use a vector. That's how I did it. If v is the vector, v[i] holds the coefficient of the term for xi. Your program should allow the user to enter the polynomial by typing it in using "^" for powers. You should get the entire line containing the user input, and construct a polynomial from it. To do this, I built a constructor for Polynomial, which takes a string as parameter. It eliminates spaces from the string, and then parses it into tokens representing terms, using the "+", "-" and end-of-string as delimiters. It then parses the tokens, picking out the coefficient and power.

Lab 11 - due Apr 12

p. 465 20 Extra Credit (2 points) Modify the Polynomial class from Lab 10, so that the terms are stored in descending order (by exponent) in linked lists of nodes.

Lab 12 – due Apr 19

p. 450 20 (Write a complete LinkedList class template) p. 464 9 (Write a driver to test your LinkedList class)