COSC 1436 Lab 2
Purpose:
This lab explores using a function to write data to a file.
Due:
Section 2: Before class on February
5, 2013
Section
3: Before class on February
7, 2013
Requirements:
Do the following:
1. Write
a program that will write the prime factors of all the numbers from 1 to 1000
to a disk file. The specific requirements are as follows:
- Write a function that finds the prime factors of any positive number. The
function will take in a positive number as a parameter. We will discuss the
algorithm for doing this at the beginning of the lab. For example, here is
a listing of the prime factors of the numbers from 1 to 15:
- 1 - identity element
- 2 - prime
- 3 - prime
- 4 = 2 * 2
- 5 - prime
- 6 = 2 * 3
- 7 - prime
- 8 = 2 * 2 * 2
- 9 = 3 * 3
- 10 = 2 * 5
- 11 - prime
- 12 = 2 * 2 * 3
- 13 - prime
- 14 = 2 * 7
- 15 = 3 * 5
- Write another function that takes in input from a user for the name of a
disk file and then opens that file. Remember that a file handle must always
be passed by reference.
- Modify your first function so that it receives the file handle from the
main program and then uses the file handle to write the prime factors to a
disk file. The disk file must put the number and factors on a single line
in a manner similar to the example given above. The function prototype for
the function should be as: void
primeFactors(int iNumIn, ofstream & fhOut);
- Write a main program that will call your two functions, once for the file
opening functions and a thousand times for the prime factors function (1 to
1000).
- In the final version, the only console output for this program is to ask
the user for a filename, the rest of the output will be to a file.
2. Your program must compile
and run on clst.tamucc.edu.
3. This lab requires a lab report/documentation
package. All of these items are not typically in the same file (source code
and sample output should definitely be in their own files), but the main lab
report file must reference each item by file name. Here is a
sample lab report. The main lab report must either be a text file (with
a .txt extension) or a Microsoft Word file (with a .doc or .docx extension).
The lab report must includes the following or references (the file name that
was attached to the mail) to the following information:
-
-
-
-
Program output. The output must be from the clst.tamucc.edu
Linux server, not from Windows.
-
What problems/successes did you have with this program?
-
An estimate of how much time you spent working on this
lab
4. Submit this package via BlackBoard. Zip all of the required elements
together into one file that will be submitted to BlackBoard:
- The source code for your programs, called lab02***.cpp. Put your
initials where the 3 asterisks appear. This files must be ready to
compile using the standard g++ compiler on clst.tamucc.edu.
- A digital copy of the program output.
- A copy of your lab report in either a Microsoft Word document or
a text file.
Grading
Criteria: 100 points available for this lab.