0

I don't know how to write a c++ program to execute the following operations. could anyone help me??

Write a C++ program that opens a comma-separated values file and performs various functions on it. The first line is a
header containing the names of the fields. The available fields are different in different CSV files. Each
subsequent line corresponds to a row in the table. Within a line, fields are separated by commas. The
following is an example:
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


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: 3
Field number or name: student_no
Search string: 101
* begin output
Wong Siu Keung,20091014,80
Chau Cheong,20091012,58
* 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: 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.

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

Take it one small step at a time, and soon you will have that program written. First learn how to open a file and read it one line at a time. After you have that working, learn how to split up the rows into columns (you can use stringstream c++ class for that). Then make the menu, add a switch statement to implement each menu item.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.