SlideShare una empresa de Scribd logo
1 de 6
CIS 170C iLab 7 of 7 Sequential Files
Click this link to get the tutorial:
http://homeworkfox.com/tutorials/general-
questions/10136/cis-170c-ilab-7-of-7-sequential-files/
Lab # CIS CIS170C-A7 Lab 7 of 7: Sequential Files Lab Overview - Scenario/Summary

You will code, build, and execute a program that requires sequential files to create an address
database.

Learning Outcomes

Continue using a menu system with console applications Be able to write a console application
Demonstrate entering, appending, storing, and retrieving records Be able to write lines of output
to a text file in order to create a report



Deliverables

Section

Deliverable

Points

Step

Program Listing and Output

45

Lab Steps



Preparation:

If you are using the Citrix remote lab, follow the login instructions located in the iLab tab in
Course Home.

Locate the Visual Studio 2010 icon and launch the application.
Lab:

Step 1: Requirements: An Address Database

Create a C++ console application that will store and retrieve names and addresses in a text file.

The program should do the following.

It should accept a series of names and addresses from the console. The user's input should be
written to a text file in the CSV format described in the lecture, but do not include the field
names in the first row of the file. Read the records from the text file, and display them in a user-
friendly format. Provide a menu to allow the user to append records to the file, display the
records, or exit the application.

Build upon the code below to complete the assignment.

//Specification: Append and display records in a address database

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void menu(void);
void writeData(void);
void readData(void);
string * split(string, char);

const char FileName[] = "TestAddress.txt";

int main () {
 menu();
 return 0;
} //end main

void menu(void) {
//allow user to choose to append records, display records or exit the program

}//end menu

void writeData(void){
//Write the Address Info to a file

}//end write data
void readData(void){
//read data from a file
//use the split function to break a
//deliminated line of text into fields

}//end read data

string * split(string theLine, char theDeliminator){
 //Break theline into fields and save the fields to an array.
 //Each field will occupy one element in a character array.
 //theLine is a string with fields separated with theDeliminator character.
 //Assumes the last field in the string is terminated with a newline.
 //Useage: string *(lineBuffer, ',');

 //determine how many splits there will be so we can size our array
 int ;
 for(int ; i < theLine.size(); i++){
 if (theLine[i] == theDeliminator)
 splitCount++;
 }
 splitCount++; //add one more to the count because there is not an ending comma

//create an array to hold the fields
  string* theFieldArray;
  string[splitCount];

//split the string into seperate fields
  string ;
  int ;

 for(int ; i < theLine.size(); i++){ //read each character and look for the deliminator
 if (theLine[i] != theDeliminator) {
 theField += theLine[i]; //build the field
 }
 else { //the deliminator was hit so save to the field to the array
 theFieldArray[commaCount] = theField; //save the field to the array
 ;
 commaCount++;
 }
 }
 theFieldArray[commaCount] = theField; //the last field is not marked with a comma...

 return theFieldArray;
} //end split

Step 2: Processing Logic
Using the pseudocode below, write the code that will meet the requirements.

The pseudocode for the writeData function is shown below.

Start

open the text file to append

start do while loop

Allow user to enter name

store name (using getline method)

Allow user to enter city

store city (using getline method)

.

.

write name, city, etc. to the file

end loop

close the file

End

The program input should appear similar to this.

Append Records

Name..........John Smith
Street.........902 Union Ave
City............Any Town
State...........TX
Zip Code......78552

"Enter another Record? (Y/N) "

The file structure should look like this.
John Smith, 902 Union Ave, Any Town, TX, 79552
Eric Jones, 345 State Way, Fresno, CA, 93432
...

The file output should appear similar to the following.

Show Records
__________________________________________
Record #1
Name...........John Smith
Street..........902 Union Ave
City.............Any Town
State...........TX
Zip Code......78552
__________________________________________
Record #2
Name...........Eric Jones
Street..........345 State Way
City.............Fresno
State...........CA
Zip Code.......93432
__________________________________________

(A)ppend Records, (S)how Records, (E)xit



Step 3: Create a New Project

Create a new project and name it LAB7. Write your code using the processing logic in Step 2.
Make sure you save your program.

Step 4: Compile and Execute

a) Compile your program. Eliminate all the syntax errors.

b) Build your program and verify the results of the program. Make corrections to the program
logic, if necessary, until the results of the program execution are what you expect.

Step 5: Print Screenshots and Program



Capture a screen print of your output. (Do a print screen and paste into an MS Word document.)
Copy your code and paste it into the same MS Word document that contains the screen print of
your output. Save the Word document as Lab07_LastName_FirstInitial.
END OF LAB

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Filehadnling
FilehadnlingFilehadnling
Filehadnling
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
File Handling
File HandlingFile Handling
File Handling
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streams
 
file handling, dynamic memory allocation
file handling, dynamic memory allocationfile handling, dynamic memory allocation
file handling, dynamic memory allocation
 
Files in c++
Files in c++Files in c++
Files in c++
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 
File Pointers
File PointersFile Pointers
File Pointers
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
File management in C++
File management in C++File management in C++
File management in C++
 
File_Management_in_C
File_Management_in_CFile_Management_in_C
File_Management_in_C
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
17 files and streams
17 files and streams17 files and streams
17 files and streams
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
 

Similar a CIS170C Lab 7: Sequential Files

Devry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-filesDevry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-filescskvsmi44
 
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docxStudent Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docxflorriezhamphrey3065
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical fileAnkit Dixit
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System iChuck Walker
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008guestd9065
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NETmentorrbuddy
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with filesramya marichamy
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with fileskirupasuchi1996
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019Karthik Sekhar
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptxradhushri
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual DevelopGourav Kumar
 

Similar a CIS170C Lab 7: Sequential Files (20)

Devry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-filesDevry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-files
 
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docxStudent Lab Activity CIS170 Week 6 Lab Instructions.docx
Student Lab Activity CIS170 Week 6 Lab Instructions.docx
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System i
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Project report
Project reportProject report
Project report
 
srgoc
srgocsrgoc
srgoc
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual Develop
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 

CIS170C Lab 7: Sequential Files

  • 1. CIS 170C iLab 7 of 7 Sequential Files Click this link to get the tutorial: http://homeworkfox.com/tutorials/general- questions/10136/cis-170c-ilab-7-of-7-sequential-files/ Lab # CIS CIS170C-A7 Lab 7 of 7: Sequential Files Lab Overview - Scenario/Summary You will code, build, and execute a program that requires sequential files to create an address database. Learning Outcomes Continue using a menu system with console applications Be able to write a console application Demonstrate entering, appending, storing, and retrieving records Be able to write lines of output to a text file in order to create a report Deliverables Section Deliverable Points Step Program Listing and Output 45 Lab Steps Preparation: If you are using the Citrix remote lab, follow the login instructions located in the iLab tab in Course Home. Locate the Visual Studio 2010 icon and launch the application.
  • 2. Lab: Step 1: Requirements: An Address Database Create a C++ console application that will store and retrieve names and addresses in a text file. The program should do the following. It should accept a series of names and addresses from the console. The user's input should be written to a text file in the CSV format described in the lecture, but do not include the field names in the first row of the file. Read the records from the text file, and display them in a user- friendly format. Provide a menu to allow the user to append records to the file, display the records, or exit the application. Build upon the code below to complete the assignment. //Specification: Append and display records in a address database #include <iostream> #include <fstream> #include <string> using namespace std; void menu(void); void writeData(void); void readData(void); string * split(string, char); const char FileName[] = "TestAddress.txt"; int main () { menu(); return 0; } //end main void menu(void) { //allow user to choose to append records, display records or exit the program }//end menu void writeData(void){ //Write the Address Info to a file }//end write data
  • 3. void readData(void){ //read data from a file //use the split function to break a //deliminated line of text into fields }//end read data string * split(string theLine, char theDeliminator){ //Break theline into fields and save the fields to an array. //Each field will occupy one element in a character array. //theLine is a string with fields separated with theDeliminator character. //Assumes the last field in the string is terminated with a newline. //Useage: string *(lineBuffer, ','); //determine how many splits there will be so we can size our array int ; for(int ; i < theLine.size(); i++){ if (theLine[i] == theDeliminator) splitCount++; } splitCount++; //add one more to the count because there is not an ending comma //create an array to hold the fields string* theFieldArray; string[splitCount]; //split the string into seperate fields string ; int ; for(int ; i < theLine.size(); i++){ //read each character and look for the deliminator if (theLine[i] != theDeliminator) { theField += theLine[i]; //build the field } else { //the deliminator was hit so save to the field to the array theFieldArray[commaCount] = theField; //save the field to the array ; commaCount++; } } theFieldArray[commaCount] = theField; //the last field is not marked with a comma... return theFieldArray; } //end split Step 2: Processing Logic
  • 4. Using the pseudocode below, write the code that will meet the requirements. The pseudocode for the writeData function is shown below. Start open the text file to append start do while loop Allow user to enter name store name (using getline method) Allow user to enter city store city (using getline method) . . write name, city, etc. to the file end loop close the file End The program input should appear similar to this. Append Records Name..........John Smith Street.........902 Union Ave City............Any Town State...........TX Zip Code......78552 "Enter another Record? (Y/N) " The file structure should look like this.
  • 5. John Smith, 902 Union Ave, Any Town, TX, 79552 Eric Jones, 345 State Way, Fresno, CA, 93432 ... The file output should appear similar to the following. Show Records __________________________________________ Record #1 Name...........John Smith Street..........902 Union Ave City.............Any Town State...........TX Zip Code......78552 __________________________________________ Record #2 Name...........Eric Jones Street..........345 State Way City.............Fresno State...........CA Zip Code.......93432 __________________________________________ (A)ppend Records, (S)how Records, (E)xit Step 3: Create a New Project Create a new project and name it LAB7. Write your code using the processing logic in Step 2. Make sure you save your program. Step 4: Compile and Execute a) Compile your program. Eliminate all the syntax errors. b) Build your program and verify the results of the program. Make corrections to the program logic, if necessary, until the results of the program execution are what you expect. Step 5: Print Screenshots and Program Capture a screen print of your output. (Do a print screen and paste into an MS Word document.) Copy your code and paste it into the same MS Word document that contains the screen print of your output. Save the Word document as Lab07_LastName_FirstInitial.