Difficulty with comprehension....

I have this assignment to do, and it is very difficult for me to understand the actual question, and even more so what to do.

Here is the program mission (translated):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Write a program that receive from the user 2 names of files: 
 -First: Input file
 -Second: Output file
(Without input requests from the program- meaning only input)

Every line in the input file is supposed to include: 4 strings
The program needs to receive the 4 strings into an array of strings.
The program has to sort through use of strcmp the strings, and then print to the output file a new string
which includes the linking of the strings in a rising order with a "character space" between them  through use of strcat and strcpy.
Other than that, at the beginning of each line of the output file, print the number of the line (starting from '0'), colon, and space.

For Example:

For book space information zone on line number 0, program will print:  0: book information space zone

For near name net nutrition on line number 148, program will print:   148: name near net nutrition

You may assume:
1.That there are 4 strings in every line of the input file.
2.That the maximum size of every single of the 4 strings is: 20.
3.That in the input file, all the strings are lower case letters only, without numbers.

If there will be an error in the opening of the files, send an error message to the standard output (meaning, print using cout):
				"Failed to open the file nameOfFile\n"


So, here is the source of my confusion/incomprehension:

1. How do I receive a name of an input and output file? How am I supposed to place that in the actual code of the output/input? I only recall how to set the names in the programming writing itself (meaning, that I set the names, and the program does what it needs to do with what I set).

2. How do I find the line number of the text? It's like, the user enters input, and I am supposed to find on which line it is in the text?

3. Lexicographically speaking, how do I put all the words in order?

Note: I am not looking for a coded answer to the question, I am just looking for some technical guidelines of how to perform general operations (alphabetical order, line numbers, general comprehension). So, please, don't think that I am requesting that you solve this problem for me. I just need some general guidelines to assist me......

Thanks!
1. How do I receive a name of an input and output file? How am I supposed to place that in the actual code of the output/input? I only recall how to set the names in the programming writing itself (meaning, that I set the names, and the program does what it needs to do with what I set).


Do you mean getting input at run-time instead of compile-time? This part seems to be a bit confusing to me.

(Without input requests from the program- meaning only input)

Since it says "without input", does that mean you don't input anything at all?

2. How do I find the line number of the text? It's like, the user enters input, and I am supposed to find on which line it is in the text?

you can check for the '\n' character and have a counter that counts how many of those it has detected. Since \n would give you a new line 100 of them would give you 100 lines and so on if I'm not mistaken.

3. Lexicographically speaking, how do I put all the words in order

it says there that you should use strcmp to compare the words, strcmp would return a value greater than 0 if the first string is larger, 0 if they're equal and less than 0 if the second string is larger. For example

strcmp("z", "a") would return greater than 0
strcmp("z", "z") would return 0
strcmp("a", "z") would return less than 0

so you can use that to check if the words are already in order or not, you will have to go through all the words though a number of times until it's all alphabetized. You can read on improved bubble sort to get an idea on how it all works.
I don't really know the difference between run-time and compile time. The program gets the input during the running of it on the command line window. I really hope that answered that question.

There are no input requests for the user, meaning, the program doesn't print something like: "Please enter name of file..."

The input is just what is needed to have the program run.

I don't really know how to write the code to open up a file that I myself have not set in the compiler. How would I do that?
run-time means you get the data from the user while the program is running, compile-time means that you set the data inside the source code before compiling.


I don't really know how to write the code to open up a file that I myself have not set in the compiler. How would I do that?

That really depends on what your instructor wants you to use, I mean they want you to use cout which is C++, yet they also want you to use strcmp which is for C which also means you'll have to use C-style strings. For files you may use FILE* which is for C and open it using fopen, you may also use C++ file I/O using ifstream and ofstream. For ifstream and ofstream examples check this link.

http://www.cplusplus.com/doc/tutorial/files.html
Last edited on
Topic archived. No new replies allowed.