Student Lab Activity CIS170 Week 7 Lab Instructions Lab 7 of 7: Sequential Files Lab Overview—Scenario/Summary You will code, build, and execute a program that creates an address database using a...




Student Lab Activity CIS170 Week 7 Lab Instructions Lab 7 of 7: Sequential Files Lab Overview—Scenario/Summary You will code, build, and execute a program that creates an address database using a sequential text file in Comma Separated Value (CSV) format. Learning Outcomes 1. Continue using a menu system with a console application. 2. Read and write a sequential text file. 3. Generate output records in CSV format. 4. Parse CSV formatted input records and display the results. Deliverables Section Deliverable Points Lab Program Listing and Output · Accepts names and addresses from console · Writes addresses to text file · Reads and displays addresses from file · Provides menu options for entry, display, and exit · Code is provided in lab report · Screen shots of working program provided in lab report · Code is appropriately commented, formatted, and readable 5 5 5 5 5 5 10 All Steps Total 40 Lab Steps Preparation: If you are using the Citrix remote lab, follow the login instructions located in the lab area in Course Home. Locate the Visual Studio icon and launch the application. Lab: Step 1: Revjew the Requirements for an Address Record Application Review and analyze the following requirements for a C++ console application that will store and retrieve names and addresses in a text file. The program should do the following. 1. Display a main menu providing the user with options to 1) Enter new address records; 2) Display address records; 3) Exit the program. 2. If the user selects 1) Enter new address records: a. Create a new text file named Address.csv b. Prompt the user to enter a name, street, city, state, and zip code. c. Write the entered data to the text file in Comma Separated Value (CSV) format. d. Ask if the user wants to enter another record. If so, repeat; if not, close the file and return to the main menu. 3. If the user selects 2) Display address records: a. Open the text file named Address.csv b. Read and display the name, street, city, state, and zip code from each record in the file in a readable format. c. Close the file and return to the main menu. 4. If the user selects 3) Exit: Exit the program. Step 2: Create project and enter skeleton code a. In Visual Studio, create a new C++ console application project named Lab7 using the "empty project" option. b. Create a new C++ source file in the project named Lab7.cpp. c. Enter or copy/paste in the following skeleton code, which you will build upon to complete the rest of the assignment: // --------------------------------------------------------------- // Programming Assignment:CIS170C Lab 7 // Developer:______________________ // Date Written: // Purpose:Store and retrieve names and addresses in a //sequential text file in CSV format. // --------------------------------------------------------------- #include #include #include using namespace std; // function prototypes void EnterAndWriteAddresses(void);//Accept address records from user, write to file void ReadAndDisplayAddresses(void); //Read address records from file, display const string ADDRESS_FILE_NAME = "Address.csv";// file name for address data file // main program -- displays main menu and processes user selection void main() { cout < "address="" record="" application"="">< endl="">< endl;="" todo:="" add="" main="" menu="" loop="" here="" with="" options="" for="" 1)="" enter="" new="" address="" records="" 2)="" display="" address="" records="" 3)="" exit="" the="" program="" display="" error="" message="" if="" invalid="" choice="" is="" entered="" repeat="" loop="" while="" user="" has="" not="" entered="" 3="" system("pause");="" }="" enter="" address="" records="" and="" write="" to="" address="" file="" void="" enterandwriteaddresses(void)="" {="" todo:="" declare="" variables="" for="" name="" and="" address="" fields="" todo:="" open="" address="" file="" for="" output="" using="" ofstream()="" todo:="" loop="" to="" accept="" and="" write="" addresses="" prompt="" user="" to="" enter="" name="" and="" address="" fields="" write="" entered="" data="" to="" address="" file="" separated="" by="" commas="" ask="" user="" if="" more="" addresses="" to="" enter="" repeat="" loop="" while="" user="" responds="" 'y'="" or="" 'y'="" todo:="" close="" address="" file="" }="" read="" records="" from="" address="" file="" and="" display="" to="" user="" void="" readanddisplayaddresses(void)="" {="" string="" name,="" street,="" city,="" state,="" zip;="" ifstream="" inputaddress(address_file_name);="" open="" address="" file="" for="" input="" if="" (inputaddress.is_open())="" {="" read="" and="" display="" all="" records="" from="" address="" file="" while="" (getline(inputaddress,="" name,="" ','))="" {="" read="" name="" field="" getline(inputaddress,="" street,="" ',');="" read="" street="" field="" todo:="" add="" getline="" statements="" to="" read="" remaining="" fields="" note:="" delimiter="" for="" last="" field="" must="" be="" newline="" '\n'="" not="" comma="" todo:="" add="" cout="" statements="" to="" display="" addresses="" to="" user="" }="" inputaddress.close();="" close="" address="" file="" }="" }="" d.="" enter="" your="" name="" and="" the="" current="" date="" in="" the="" comment="" header.="" e.="" compile="" and="" test="" the="" program.="" fix="" any="" reported="" errors.="" the="" output="" at="" this="" point="" should="" look="" similar="" to="" the="" following:="" step="" 3:="" code="" and="" test="" main="" menu="" a.="" inside="" the="" main()="" function,="" code="" a="" loop="" that="" will="" display="" a="" main="" menu="" with="" the="" required="" 3="" options,="" accept="" the="" user's="" choice,="" and="" repeat="" while="" the="" user's="" choice="" is="" not="" option="" 3="" (exit).="" note:="" remember="" to="" use="" cin.ignore()="" after="" you="" accept="" the="" user's="" choice,="" to="" discard="" the="" trailing="" newline="" character="" that="" may="" be="" left="" in="" the="" keyboard="" buffer="" after="" input="" of="" a="" number="" or="" single="" character.="" b.="" inside="" your="" main="" menu="" loop,="" code="" a="" switch="" structure="" that="" will="" process="" the="" user's="" choice.="" for="" now,="" for="" each="" option="" simply="" code="" cout="" statements="" to="" display="" an="" appropriate="" message="" for="" each="" choice.="" c.="" display="" an="" error="" message="" if="" the="" user="" made="" an="" invalid="" menu="" choice="" (anything="" other="" than="" 1,="" 2,="" or="" 3).="" d.="" compile="" and="" test="" the="" program.="" fix="" any="" reported="" errors.="" the="" output="" at="" this="" point="" should="" look="" similar="" to="" the="" following:="" step="" 4:="" code="" and="" test="" entering="" address="" data="" and="" writing="" to="" the="" address="" file="" a.="" in="" the="" switch="" statement="" in="" your="" main="" menu="" loop,="" replace="" the="" cout="" statement="" for="" option="" 1="" with="" a="" call="" to="" the="" enterandwriteaddresses()="" function.="" b.="" in="" the="" enterandwriteaddresses()="" function,="" declare="" string="" variables="" to="" hold="" the="" name="" and="" address="" fields="" (name,="" street,="" city,="" state,="" and="" zip="" code).="" c.="" open="" the="" address="" file="" for="" output,="" using="" the="" string="" constant="" address_file_name="" as="" the="" file="" name="" and="" an="" appropriate="" file="" stream="" object.="" d.="" code="" a="" loop="" in="" which="" you="" prompt="" the="" user="" to="" enter="" each="" of="" the="" name="" and="" address="" fields="" and="" accept="" the="" user's="" input="" into="" the="" corresponding="" string="" variable.="" use="" the="" getline()="" function="" as="" some="" fields="" may="" contain="" spaces.="" at="" the="" bottom="" of="" the="" loop,="" ask="" the="" user="" if="" they="" want="" to="" enter="" another="" record,="" and="" repeat="" the="" loop="" as="" long="" as="" they="" respond="" with="" an="" upper-="" or="" lower-case="" y.="" e.="" inside="" the="" data="" entry="" loop,="" after="" the="" user="" has="" entered="" a="" set="" of="" address="" data,="" write="" the="" name="" and="" address="" fields="" to="" the="" address="" file="" using="" the="" file="" stream="" object="" you="" created="" when="" you="" opened="" the="" file.="" output="" a="" comma="" ","="" between="" each="" field.="" at="" the="" end="" of="" the="" address="" record,="" output="" a="" newline="" using="" a="" "\n"="" or="" endl="" (do="" not="" put="" a="" comma="" after="" the="" last="" field="" in="" the="" record).="" f.="" at="" the="" end="" of="" the="" enterandwriteaddresses()="" function,="" close="" the="" address="" file.="" g.="" compile="" and="" test="" the="" program.="" fix="" any="" reported="" errors.="" the="" output="" at="" this="" point="" should="" look="" similar="" to="" the="" following:="" h.="" to="" check="" that="" your="" address="" data="" were="" written="" to="" the="" output="" file="" correctly,="" in="" visual="" studio,="" pull="" down="" the="" file="" menu="" and="" choose="" open=""> File. Select the Address file and click Open. You should see something similar to the following: Check that the name and address fields were written correctly, that the fields within each record are separated by commas, and that each record appears on a separate line. If you see any problems in the output file, make adjustments in your code and test again. Step 5: Code and test reading and displaying data from the address file a. In the switch statement in your main menu loop, replace the cout statement for option 2 with a call to the ReadAndDisplayAddresses() function. b. In the ReadAndDisplayAddresses() function, following the getline() statement that reads the street field, add additional getline() statements to read each of the other fields into the appropriate string variable. These will be similar to the getline() for street, except for the variable name. However, in reading the last field (zip), change the comma ',' delimiter to a newline '\n' because the last field in the record is not followed by a comma. c. After reading in the fields from the address file, add cout statements to display the name and address to the user in a professional, readable format. d. Compile and test the program. Fix any reported errors. The output at this point should look similar to the following: Step 6: Capture and submit screen shots and code a. Do a final end-to-end test of your program in which you enter addresses (option 1) and display these addresses (option 2) in a single run. b. Capture a screen shot of your output and paste into an MS Word document. c. Copy your code and paste it into the same MS Word document. d. Save the Word document as Lab07_LastName_FirstInitial and submit it for the Lab 7 assignment. Version 1.0Page 1 of 9 4/9/2009Lab Activity CIS CIS170B-A1.docx Page 5 of 6 Lab Activity CIS CIS170C-A7
Aug 18, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here