CS135 Assignment 7 Purpose: Become familiar with basic C++ syntax, input/output, if statements, C++ looping structures, nested loops, and file I/O. Assignment: Mr. Slate, owner of Slate Rock and...

1 answer below »
i need help pls


CS135 Assignment 7 Purpose: Become familiar with basic C++ syntax, input/output, if statements, C++ looping structures, nested loops, and file I/O. Assignment: Mr. Slate, owner of Slate Rock and Gravel, has ask you to write a program that can produce different size shapes for use as labels and signs. The shapes are different and have scalable sizes. A file contains the specifications for the shapes. The program should prompt the user for the name of the specification file. Open the file and verify that it opened, read a line of specifications, create the filename for the shape, generate the data for the shape, and close the file. This should be repeated until all specifications in the input file have been processed. Process to end of file. Image: xkcd.com Input File Prompt the user for the input file name, opened it for read operations, and verify that it opened correctly. If the file did not open, an error message should be printed and the user should be prompted again. This should continue until the user supplies a valid filename. Implementation Requirements Each shape must be implemented with single character outputs to the file. You may not use strings and/or string functions, iomanip features like setfill, or any other methods except single character outputs to the file to output the shapes, Programs that do not follow this provision will receive a zero. Output Filenames Output filenames are generated automatically by the program and contain the shape name an underscore shapeSize and .txt . String functions may be used for filename generation. Examples: rightArrow 11 B –> filename would be rightArrow_11.txt File Data Format: The input data file contains the following data ShapeType size character All fields are space delimited. Example: zero 25 0 Field Data Type Value from Example Above Label Type string zero Size int 25 Character char 0 Shapes There are three shapes for the labels. Each shape is made up of a combination of the shape character and spaces. Each shape is size characters wide and size characters high. The symbol may be thought of as a grid. Below is an example of “zero 7 C”. 1 2 3 4 5 6 7 1 C C C C C C C 2 C C C 3 C C C 4 C C C 5 C C C 6 C C C 7 C C C C C C C Zero– for loops Zero must be implemented using for loops. Below is a zero of size 12. The zero has twelve lines of characters and the width is twelve characters. CCCCCCCCCCCC C CC C C C C C C C C C C C C C C C C C C C C C C C C CC C CCCCCCCCCCCC zero 12 C Zero labels, unlike the other shapes, have no requirements for the size to be odd or even. A zero label specified smaller than 5 doesn’t make much sense, but should not crash your program. Up Arrow – while loops Up Arrow must be implemented using while loops. Up Arrow requires that the size be an even number. If the size is not even, it should be incremented to make it even. All calculations for the scaling should use the even number. The head of the arrow is one half of the size high. The bottom of the arrow, the shaft, is the other half. The shaft is always two characters wide. CC CCCC CCCCCC CCCCCCCC CCCCCCCCCC CCCCCCCCCCCC CC CC CC CC CC CC upArrow 12 C Right Arrow – do while loops Right Arrow must be implemented with do while loops. Right Arrow requires that the size be an even number. If the size is not even, it should be incremented to make it even. All calculations for the scaling should use the even number. The head of the arrow is one half of the size wide. The bottom of the arrow, the shaft, is the other half. The shaft is always two characters wide. B BB BBB BBBB BBBBB BBBBBBBBBBBB BBBBBBBBBBBB BBBBB BBBB BBB BB B rightArrow 11 B Notice that the arrow has 12 rows and is 12 wide. The label was specified as 11, but the program changed it to the next even number, 12. Output File Format: The output file has an header at the top with specifications for the shape in the file. A note if the size was modified, a column list, and the shape generated. See examples for specific formatting. Input Data File: The data file is on sally in the /home/djShare/AS7Data.txt in addition to on the class Canvas website. To copy the file from the shared directory to your directory on sally use the following command. yourname@sally:~$ cp /home/djShare/AS7Data.txt data.txt This will copy AS7Data.txt to a file called data.txt in you directory. Notes: 1. Compile your program as follows g++ main.cpp -Wall -pedantic 2. Submission – submit only the main.cpp file. Examples dj@schroeder:~/.../AS7$ g++ main.cpp -pedantic -Wall dj@schroeder:~/.../AS7$ ./a.out Enter input file name: data.txt Shape Created: upArrow_3.txt Shape Created: upArrow_4.txt Shape Created: upArrow_5.txt Shape Created: upArrow_6.txt Shape Created: upArrow_11.txt Shape Created: upArrow_12.txt Shape Created: upArrow_25.txt Shape Created: upArrow_100.txt Shape Created: upArrow_101.txt Shape Created: rightArrow_3.txt Shape Created: rightArrow_4.txt Shape Created: rightArrow_5.txt Shape Created: rightArrow_6.txt Shape Created: rightArrow_11.txt Shape Created: rightArrow_12.txt Shape Created: rightArrow_25.txt Shape Created: rightArrow_100.txt Shape Created: rightArrow_101.txt Shape Created: zero_5.txt Shape Created: zero_6.txt Shape Created: zero_11.txt Shape Created: zero_12.txt Shape Created: zero_25.txt Shape Created: zero_100.txt Shape Created: zero_101.txt Finished processing input file 25 Shapes Created dj@schroeder:~/.../AS7$ Examples rightArrow Filename: rightArrow_11.txt Specification: rightArrow 11 B Symbol: Right Arrow Size: 11 Character: 'B' Note: Right Arrow must have an even size. Shape created with size: 12 123456789012 B BB BBB BBBB BBBBB BBBBBBBBBBBB BBBBBBBBBBBB BBBBB BBBB BBB BB B Filename: rightArrow_12.txt Specification: rightArrow 12 C Symbol: Right Arrow Size: 12 Character: 'C' 123456789012 C CC CCC CCCC CCCCC CCCCCCCCCCCC CCCCCCCCCCCC CCCCC CCCC CCC CC C Filename: rightArrow_25.txt Specification: rightArrow 25 > Symbol: Right Arrow Size: 25 Character: '>' Note: Right Arrow must have an even size. Shape created with size: 26 12345678901234567890123456 > >> >>> >>>> >>>>> >>>>>> >>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> > UpArrow Examples Filename: upArrow_11.txt Specification: upArrow 11 B Symbol: Up Arrow Size: 11 Character: 'B' Note: Up Arrow must have an even size. Shape created with size: 12 123456789012 BB BBBB BBBBBB BBBBBBBB BBBBBBBBBB BBBBBBBBBBBB BB BB BB BB BB BB Filename: upArrow_12.txt Specification: upArrow 12 C Symbol: Up Arrow Size: 12 Character: 'C' 123456789012 CC CCCC CCCCCC CCCCCCCC CCCCCCCCCC CCCCCCCCCCCC
Answered Same DayOct 29, 2021

Answer To: CS135 Assignment 7 Purpose: Become familiar with basic C++ syntax, input/output, if statements, C++...

Arun Shankar answered on Oct 31 2021
151 Votes
#include
#include
#include
#include
#include
#include
using namesp
ace std;
void draw_up_arrow(int size, char c)
{
// Generate the output file's name
stringstream ss;
ss< string s;
ss>>s;
string output_file = "upArrow_"+s+".txt";
// Create the output file
ofstream outfile;
outfile.open(output_file.c_str(), ios::out);
// Write the header
outfile<<"Symbol: Up Arrow Size: "<
if(size%2==1) ++size;
outfile<<"Note: Up Arrow must have an even size. Shape created with size: "< // Draw the pattern
for(int i=0;i<=size/2;i++)
{
for(int j=0;j<(size/2)-i;++j)
outfile<<" ";
for(int j=0;j<(2*i);j++)
outfile< outfile<<"\n";
}
for(int i=0;i {
for(int j=0;j<(size/2)-1;j++)
outfile<<" ";
outfile< }
// Close the file pointer to write to the output file
outfile.close();
cout<<"\nShape Created: "<}
void draw_right_arrow(int size, char c)
{
// Generate the output file's name
stringstream ss;
ss< string s;
ss>>s;
string output_file = "rightArrow_"+s+".txt";
// Create the output file
ofstream outfile;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here