Question
Programming Language: C++ For this assignment, you will write a program that reads from one file, interprets what it reads and writes to a second
Programming Language: C++
For this assignment, you will write a program that reads from one file, interprets what it reads and writes to a second file.
The program will use a number of functions as listed below.
This program will be a review of loops, menus, and function calls. It will also introduce the use of stringstream for writing to a string and ifstream and ofstream for reading and writing files. There is an example input file inputfile.txt. You will need to place that file onto your computer in the appropriate location for your program to read it.
Main
Your main function should have the following functionality:
-Open inputfile.txt for reading.
- Open outfile.txt for writing.
- Read the information on input.txt, one line at a time, until the file is at EOF or an E is read.
- Read a code and select the proper function for that code 2.
-Read the remaining input values, based on that function code
-Call the appropriate function, passing in the input values
-Save the returned string
-Call writeShape, passing in the string and a reference to your ofstream object
-Close both files.
Interpreting inputfile.txt
Each line of inputfile.txt will have the following format.
- code char value1 value2 (optional) except for any records starting with E
-The code will be a single character from this list: D, R, E
-The char will also be a single character, this will be used to make the output shape
-For the codes D, there will be a single integer value that is the dimension
-For the code R, there will be two integer values that are the dimensions
-For the code E, there will be nothing to read after the E
Required Functions
rectangleMaker
- three parameters, symbol, length, width
-uses stringstream to create a rectangle shaped string of symbols
-returns the string
diamondMaker
-two parameters, symbol and width
-uses stringstream to create a diamond shaped string of symbols
-returns the string
For the intput line D ! 3
You should create a diamond that looks like this:
!
!!!
!
Diamonds should always have an odd number for their dimension. If you happen to get a diamond with an even dimension, increase it by one.
writeShape
- two parameters, a shapeString and a reference parameter outfile
-writes the shapeString to outfile
-no return values
Inside of inputfile.txt
D - 5
D * 4
R ! 5 4
R * 3 6
E
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started