CANNOT use array, string, or voids.
Design a C++ program that will draw a series of geometric objects. Each drawing must be appropriately labeled. The program must be designed to run in batch mode using Linux redirection. (Do not prompt for input.) The list of objects to be drawn is provided below. If the object code is invalid (not L, R, or T) the program should display an error message that includes the code and states that it was invalid. The program should continue processing data until the end of file is encountered.
The objects the program should be able to draw are:
Line - The data set for drawing a line will consist of 4 values: an object code (L), a direction code will indicate whether the line should be horizontal (H), vertical (V) or diagonal (D), the length of the line will be an integer, and the character used to draw the line. The diagonal line MUST be oriented as shown in the example.
sample data set: L H 10 z
Horizontal Line
zzzzzzzzzz
sample data set: L V 3 P
Vertical Line
P
P
P
sample data set: L D 4 #
Diagonal Line
#
#
#
#
Rectangle - The data set for drawing a rectangle will consist of 5 values: an object code (R ), an integer representing the length (vertical size) of the rectangle, an integer representing the width (horizontal size) of the rectangle, the character used to draw the outside of the rectangle, and the character used to fill the inside of the rectangle.Note: if the length and/or width is < 3, the fill character will not be part of the drawing.
sample data set: R 4 3 $
Rectangle
$$$
$$$
$$$
$$$
Rectangle - The data set for drawing a rectangle will consist of 5 values: an object code (R ), an integer representing the length (vertical size) of the rectangle, an integer representing the width (horizontal size) of the rectangle, the character used to draw the outside of the rectangle, and the character used to fill the inside of the rectangle.Note: if the length and/or width is < 3, the fill character will not be part of the drawing.
sample data set: R 4 3 $ +
Rectangle
$$+$$+$
$
Triangle - The data set for drawing a triangle will begin with an object code (T) followed by a triangle type (E for equilateral, R for right). If the type is E, an integer representing the height of the triangle, the character used to draw the outside of the triangle, and the character used to fill the inside of the triangle will be given. If the type is R, an integer representing the height of the triangle and a character used to draw the triangle will be given. The drawing MUST be oriented as shown in the examples.
sample data set: T E 4 & #
Equilateral Triangle
&
&#&
&###&
&&&&&&&
sample data set: T R 5 O
Right Triangle
OOOOO
OOOO
OOO
OO
O
Input File Assumptions
The input for the program will be stored in a data file.
Each line of the file will start with a character.
If the character at the start of the line not a valid object code, there WILL NOT be anything else on the line. Only capital letters should be accepted for object codes.
If the character at the start of the line is a valid object code, then the remaining input values will be present, in the correct order, valid, and separated by at least 1 blank space.
Line direction and triangle types will be capital letters. (No error checking is necessary.)
All lengths, widths, and heights in the file will be between 1 and 50, inclusive.
Program Requirements
Display your name, section #, and assignment # before the first object is drawn.
Include a label above each drawing that indicates the type of figure drawn.
Leave at least 1 blank line between each drawing.
The only "error" the program must check for is an invalid object code.
No string type variables or arrays can be used in the program. (Automatic 60% of total point value deduction.)
Sample terminal session:
[name@bobby keys_fa11]$ more assign07data
L H 13 $
t
L V 3 +
L D 5 @
R 4 13 $ +
&
T R 5 Z
T E 6 O I
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char data; // stores data file
char datatype; // type of geometric shape (Line, Rectangle, Triangle)
int n; // number in file to determine how my char must be drawn
char symbol; // type of char withing the file to draw
int horizontal; // determine how many chars going accross for the rectangle
int vertical; // determine how many chars going down for the the rectangle
char datadirect; // the direction of the line
int i=0;
char ttype; // triangle type
cout<< "Sansanee Intraweat Sec #1001 Assign #9"<< endl;
cin>> data;
while (cin)
{
cin>> data;
if (data=='L' || data=='R' || data=='T')
{
cin>> data;
if (datatype=='L')
{
cin>> datatype>> datadirect>> n>> symbol;
if (datadirect=='H')
{
cout<< "Horizontal line"<< endl;
cin>> datadirect>> n>> symbol;
cout<< setw(n)<< setfill(symbol);
cout<< endl;
}
else
if (datadirect=='V')
{
cout<< "Vertical Line"<< endl;
cin>> datatype>> datadirect>>n >> symbol;
for (i=0;i<n;i++)
cout<< symbol<< endl;
cout<< endl;
}
else
if (datadirect=='D')
{
cout<< "Diagonal line"<< endl;
cin>> datatype>> datadirect>>n >> symbol;
for (i=0; i<n; i++)
cout<< endl;
}
}
if (datatype=='R')
{
cin>> datatype>> horizontal>> vertical>> symbol;
for (i=0; i<horizontal; i++)
cout<< endl;
for (i=0; i<vertical; i++)
cout<< endl;
}
if (datatype=='T')
{
cin>> datatype>> ttype>> n>> symbol;
if (ttype=='R')
{
cin>> datatype>> ttype>> n>> symbol;
if (ttype=='I')
{
cin>> datatype>> ttype>> n>> symbol;
//
//
}
else
if (datadirect=='I')
{
cin>> n;
// add more
// finish
}
}
}
else
if (data!='L' || data!='R' || data!='T')
cout<< data<< cin.ignore(100,'\n');
}
cin>> data;
} // while
return 0;
}
|
I am confused about what to put after the
if (data=='L' || data=='R' || data=='T')
{
// do i just put data++;? for when i dont have anything for it to execute cause it has to read the next char in the line to determine if its horizontal or vertical or diagonal.