Shapes

I am trying to draw shapes by receiving instructions from a file and then draw the shapes and output them into a separate file. The shapes I need to draw are box (filled), a diagonal line, and an isosceles triangle of the users user's choice and their choice of size. The shapes also can be either a *, ?, &, or#. I have gotten it to where I can import a file but I do not understand how to read it and execute the shapes.

Here's what I have thus far.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
ofstream outClientFile;
string nameFile;

cout << "Enter the name of the file that contains the instructions of the shapes and their sizes: ";
cin >> nameFile;

outClientFile.open(nameFile.c_str());

//check for file
if (!outClientFile)
{
cerr << "File could not be opened." << endl;
exit(1);
}



return 0;
}

any and all help will be greatly appreciated!
Last edited on
How are you "drawing" the shapes? Example?
I am not entirely sure. I missed the class period where they discussed this topic due to food poisoning and the notes the teacher posts online don't exactly explain things well. If my thought process is correct, I was thinking it would have to be a while loop, or an if/then statement. The instructions say this though,

For example, if the input file has the following:

B 5 *
D 4 ?
T 5 &
B 4 #

Then, the output file should have the following results:

Box of size 5 made out of *

*****
*****
*****
*****
*****

Diagonal line of size 4 made out of ?

?
?
?
?

Triangle of size 5 made out of &

&
&&&
&&&&&
&&&&&&&
&&&&&&&&&

Box of size 4 made out of #

####
####
####
####

The line wont post diagonally on here though.
Last edited on
You need to read a char first then an int and a char again.
Also you need an ifstream to read from files.
1
2
3
4
5
6
7
8
9
char shapeType, int size, char symbol;
ifstream src("your filename");
// handle possible error
while (src >> shapeType >> size >> symbol)
{
   // depending on shapeType draw the shape
   // create a function for each shape  
}
Topic archived. No new replies allowed.