DOC PREVIEW
FIU EEL 2880 - HW Plumbing

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline to the quality of service provided by the company. Refer to the program outline shell program at the end of these instructions. Your assignment is to take that shell program and complete the code to read the company names from the pipes.bin database and print them to a text file. Once the output text file is created, it can be loaded into an editor and printed to be turned in as completion of this homework.Create a CodeBlocks project to build a program to open the plumbing database and print each data block to a text file.The database is located at http://web.eng.fiu.edu/watsonh/EEL2880/pipesDatabase.html Download and save the binary database in the project folder you created for the program. When the program is compiled and executed from within CodeBlocks (Run), the default directory for the data file is where the main.cpp code is located.The steps are as follows:1. Create CodeBlocks project (C++ console application)2. Download the binary database file to project folder3. Copy the skeleton code to the project source file (main.cpp)4. Fill in and complete the blanks for the source code5. Compile and build the 'plumbing' program6. Run the program: use the database as the input file (pipes.bin) and output to a text fileMacros:Complete the lines of code to read the plumbing database using the following features:Define in the program that there are three defined string lengths (lines 5-7)STRSHORT = 15 charsSTRMED = 30 charsSTRLONG = 80 charsEach block is location and contact information for a single plumbing company. Consider it similar to having a single index card for each company with the database being a collection of 10 cards.The idea is to retrieve a single block from the database at a time and output all the information for each card to the output text file. Once all 10 blocks have been processed, all files can be closed. The output text file can be opened with an editor, printed, and turned in for the assignment.Illustration 1: Diagram of program function and data flowDefine data structure:The structure for each company data block has the following members in the exact sequence (line 12): char name [STRLONG]; char street [STRLONG]; char city [STRMED]; char state [STRMED]; char zip [STRSHORT]; char phone [STRSHORT]; char cell [STRSHORT]; int rating; char contact [STRLONG];Function Prototype:One user defined function is in the program has to have a prototype (line 15) as follows: void printInfo(company* info, FILE* fp);Declare file pointers:Inside the program main function, two file pointers need to be declared: Input database file pointer line 19 and Output text file pointer line 20.Declare data structure:Declare an instance of the generic company data structure line 25 used to hold read file contents. Use the 'new' operator creating a block of memory returning a pointer to the block. The pointer is named and is used throughout the program to reference the structure.company* info= new company;Open input database file:Lines 27-29 prompt the user for the input file name. A char array for the input file name needs to be declared before it is used. The array can be declared with a long string constant [STRLONG]. The declaration should be placed at line 22. That input file name is then used on line 32 where the file is to be opened.The 'if' epression should look like the following and specify read binary :if ((file pointer = fopen (calling arguments)) == NULL)Line 32 uses the fopen function http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#fopen . Fill in the appropriate values used in the 'if' condition expression. Since the pipes database file is a binary database, the fopen specification should be to 'read binary' mode .Open output text file:Lines 38-40 prompt the user for the output text file name. A char array for the output file name needs to be declared before it is used. The array can be declared with a long string constant [STRLONG]. The declaration should be placed at line 23. That output file name is then used on line 43 where the file is to be opened.The 'if' epression should again look like the following except now specify write text:if ((file pointer = fopen (calling arguments)) == NULL)Use the fopen function referenced above to open the output text file. Fill in the appropriate values used in the 'if' condition expression. Since the output text file is composed of strings, the fopen specification should be set to 'write text' mode.Line 48 sets up a loop to read each company information block one-at-a-time from the beginning of the file to the end. Each time a block is read, the contents are printed to the output text file.Loop through the database:First the database file needs to be positioned to the block corresponding to the current BlockNumber. In order to do that, the file is positioned to the block using fseek using the offset.Line 51 is the 'if' statement useed for fseek to position the file. The rest of the 'if' statement detects a failed seek condition and exits the program (lines 52-55).Seek to data block:The specification for the fseek function (other than the text book) can be found at http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#fseek Fill in the appropriate values used in the 'if' condition expression. The 'if' expression should look like the following, but specify the condition expressionif ( (fseek( correct calling arguments ), != 0)The input file stream returns the file pointer value when the the file is successfully opened (line 32). The fseek offset is calculated from the beginning of the file, position 0 using the appropriate whence constant. The appropriate Block Number offset is computed as the BlockNumber*sizeof( company data structure ).Read the database block:The specification for fread on line 57 function (other than the text book) can be found athttp://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#fread fread(information structure pointer, sizeof(information structure), Number of blocks to read, input file pointer)Fread has 4 calling arguments, see the web reference or the text book. The first calling argument is the name of a pointer for the database information structure where the input data will be placed. The second


View Full Document

FIU EEL 2880 - HW Plumbing

Download HW Plumbing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view HW Plumbing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view HW Plumbing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?