Requesting hints for cpp problem.

Hey, all. I've been struggling with this problem for some time and cannot seem to figure it out; so, if anyone would be kind enough to look at it and push me in the right direction, I'd be extremely grateful.

Here is the problem:

Write a C program to write to an output file different figures depending on the input from
an input file. In main, open the input and output files. If they don't open, print an error
message and end the program. If they do open, call the following in a loop, which you'll
stay in the loop as long as the first function returns true:
 Function to read a line of input from an input file (see 1. below)
 Function to process the line of input (see 2. below)
1. In the input function, read from the input file a char. If the char is 'P' or 'R', read 2
ints (I'm calling int1 and int2) from the input file. If the char is 'S' or 'T', read one int
(int1) from the input file. You MUST use reference parameters in this function!
2. In the function that processes the shape code,
 Use a switch to determine which subfunction to call based on the shape code
 In the switch, call the subfunction (call 3. for 'P', 4. for 'R', 4. for 'S' passing int1
twice, and 5. for 'T') that matches the choice (if 'P', 'R', 'S', or 'T'), or display to
the screen an error message (if none of those)
3. In the function writes a parallelogram, write to the output file (parameter) a
parallelogram int1 rows of int2 '*'s, where each row is shift to the right by one more
space than the previous row. YOU MUST USE NESTED FOR LOOPS HERE (see test
runs)
4. In the function writes a rectangle, write to the output file (parameter) a rectangle of
int1 rows of int2 '*'s . YOU MUST USE NESTED FOR LOOPS HERE (see test runs)
5. In the function writes a right-triangle (half-square), write to the output file
(parameter) a right-triangle of int1 '*'s in the first row, (int1-1) '*'s in the 2nd row,
..., 2 '*'s in the next to last row, 1 '* in the last row. YOU MUST USE NESTED FOR
LOOPS HERE (see test runs)
Hints: The output file (ofstream) opened in main MUST be a reference parameter to
functions 2, 3, 4, and 5, along with the needed value parameters!
DO NOT USE ANY EXTERNAL VARIABLES (i.e., variables MUST be declared inside of main
or inside of functions). (External const is OK, because they're not variables)
Include in your programs:
 nested for loops where indicated above
 while loop or do-while loop for the main loop

The real issue I'm having is not the actual computation of making the shapes.
I can't seem to figure out the integration of input and output files in the program. "1. In the input function, read from the input file a char. If the char is 'P' or 'R', read 2" is particularly confusing.

If that is explained I think I might be able to figure the rest out.

I've opened an input file and tested it, shown below.
1
2
3
4
5
6
inputFile.open("test.txt");
    if (!inputFile.is_open())
    {
        cout << "Error, file did not open; the program will now close.";
        return 0;
    }


I've also made a right triangle, shown below.
1
2
3
4
5
6
7
8
9
10
11
{
   for(int tri=0;tri<=5;tri++){

        for(int angle=0;angle<=i;angle++)
            {
                cout<<"*";
            }
       cout<<endl;
    }
 return 0;
}


Any help and advice is extremely appreciated!


Topic archived. No new replies allowed.