Using CodeBlocks or similar Problem: Write a C++ program to write to an output f
ID: 3675583 • Letter: U
Question
Using CodeBlocks or similar
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 (MAKE SURE THE OUTPUT FILE HAS A DIFFERENT NAME FROM THE INPUT FILENAME, AND A DIFFERENT NAME FOR EACH DIFFERENT INPUT FILE). 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 into main variables from an input file (see 1. below)
-Function to process one set of input values (see 2. below)
1. In the input function, read from the input file a char. If you can't read the char (see hint in Class Notes), then return false. If you were able to read a char, CHANGE IT TO UPPER CASE (hints given in class, so see Class Notes under Topic 6). 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. Return true. You MUST use reference parameters for the input values 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). Your function names (as with your variable and parameter names) MUST INDICATE WHAT THE FUNCTION DOES or points will be deducted (DON’T give names like function1, function2, etc., but names like readFileInput or processInput)!!!
Include in your programs:
- nested for loops where indicated above
- while loop or do-while loop for the main loop
- functions (as specified above, WITH REFERENCE PARAMETERS ONLY WHERE NEEDED, value parameters if you’re NOT CHANGING the parameter!)
Testrun Result:
Invalid shape specified in the file: Z
Process returned 0 (0x0) execution time : 0.075 s
Press any key to continue.
Hw5-Input.txt R 7 9 T 6 S 7 P 6 5 t 10 W 4 R 6 4Explanation / Answer
#include <iostream>