LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2009, 02:25 AM   #1
hung.rogerchan
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
C++ and CSV file


How to write a c++ program to do the following operations?

Content of a text file:

student_name,student_no,marks
Chan Tai Man,20091001,49
Wong Siu Keung,20091014,80
Chau Cheong,20091012,58
Cheung Man Kit,2008122334,77
Han Keung,2008345778,45

Example:
File name: input.txt
0. Exit
1. Count number of records
2. Dump records to screen
3. Search for a string
Please select an operation: 1
* begin output
Number of records: 14
* end output
Please select an operation: 2
* begin output
Chan Tai Man,20091001,49
Wong Siu Keung,20091014,80
Chau Cheong,20091012,58
* end output
Please select an operation: 3
Field number or name: student_name
Search string: ha
* begin output
Chan Tai Man,20091001,49
Chau Cheong,20091012,58
* end output
Please select an operation: 3
Field number or name: 2
Search string: 4
* begin output
Wong Siu Keung,20091014,80
Cheung Man Kit,2008122334,77
Han Keung,2008345778,45
* end output
Please select an operation: 0

The Bolded text is the user input!

Operation 1
When this operation is selected, the program outputs the number of records to the screen. Note that the first
line is a header line and shouldn't be included in the counting. Also, the lines "* begin output" and
"* end output" should be printed before and after the actual output. Please refer to section 2 for a
sample run.
Operation 2 – Dump records to screen
When this operation is selected, the program outputs all the records to screen. The order of appearance of
the records should be the same as that in the file. Note that the first line is a header line and shouldn't be
included in the output. Again, the lines "* begin output" and "* end output" should be printed
before and after the actual output. Please refer to section 2 for a sample run.
Operation 3 – Search for a string
When this operation is selected, additional information will be asked for. The program first asks for the field
number or field name. The field number is a number (count from 1) that specifies the column of the table,
while the field name is one of the names specified in the header line. To distinguish field number and name,
you may assume that the field name never starts with a number.
Then the program will asked for a search string. The search string is a simplified regular expression, which
will be explained in details in the next section.
Finally, the specified field of all the records will be searched for the specified search string. Records that are
matched will be output to screen. The order of appearance of the records should be the same as that in the
file. Again, the lines "* begin output" and "* end output" should be printed before and after the
actual output.
 
Old 11-15-2009, 03:04 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
show some effort on your homework. what have you written?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace line in CSV file and rename file connected to that name wademac Linux - Newbie 3 07-15-2009 01:09 PM
writting a csv file ajinkyakp Linux - Newbie 6 02-16-2009 11:29 AM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
CSV file merge help lmedland Programming 2 06-04-2008 11:11 AM
CSV File AMMullan Programming 2 11-10-2003 12:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration