Using C++ programming Tasks: i) Start with a template as follows: int main( int
ID: 3866326 • Letter: U
Question
Using C++ programming
Tasks: i) Start with a template as follows: int main( int nInputs, char * inputs[] ) { TextWriter *w = new TextWriter; cout << *(w->get_filename()) << endl; // accessor function } where TextWriter is a class that you will define whose private member variable filename is a string pointer type. ii) Define at least 3 overloaded constructors for TextWriter and define a member function set_filename so that the following can be added to the above main function: w->set_filename( filename ); std::string str= "f.txt"; TextWriter w3( str ); where filename isset to the value of the first input argument to the above main function.
iii) Add member function to TextWriter so that it would create an output stream and write “Hello world” to the file specified by its member variable filename. iv) Add try-catch statements (Chapter 16) to handle inaccessible locations for writing files (a simplified example is shown on the next page): e.g. if the file location is not writable, a prompt would be shown instead of invoking a run-time error.
1) Write a TextWriter class that allows one to write text to any input file as laid out in class for Part 1 (see next slide). 2) Modify your TextWriter so that it has the following functions: – void write( string some_text ); – a destructor function that automatically closes the file output stream – Add a statement, e.g., printf("TextWriter destructor called "); when you run your program, observe when this output is printed.
1) Derive an SVGWriter class from TextWriter so that it has the following functions:
string get_header(int w, int h, Colour c ) /* this function generates header string to be inserted into an SVG file */
{ string text = "{C} " " " " ";
// write code below so that input arguments will be used to replace WIDTH and HEIGHT
return text; }
SVGWriter::~SVGWriter(); { Write(" ");
// redefined function that writes input argument string to stream
cout << " SVG stream closed "; // for debugging purpose
fstream.close();
}
2) Write another program called generateSVG.exe that will generate an SVG file.
The SVG file will contain a header, which can be generated using the above function as a start.
The width, height, and color in the above string will be set based on user’s input, i.e. the below generates a canvas of W x H in dimensions, with background colour set as rgba(0,0,256,0.5):
Note:
rgba() is a CSS (cascading style sheet) function where: -
1 st argument is the intensity given to the red color channel -
2 nd argument is the intensity given to the green color channel -
3 rd argument is the intensity given to the blue color channel -
4 th argument is the intensity given to the transparency (0.5 means half transparent) $ generateSVG.exe test.svg 100 200 0 0 256 0.5
Part 3. Shape classes and SVG generation:
1) Write a base class named Shape that will contain at least the following attributes (member variables): – Colour (4 channels to encode intensity for each of red, blue, green and transparency info) – Coordinates for the central position of the shape
2) Derive at least 3 of the following shapes from the Shape class (member private variables noted): –
Circle (radius)
– Ellipse (major and minor axes)
– Rectangle (width, height)
– : polyline, polygon, text , or another one listed here: https://www.w3.org/TR/SVG/shapes.html
3) Implement necessary functions that will generate the SVG tags needed to represent/encode each derived shape class.
4) Using the rand() function provided from stdlib, create at least two samples of each shape class using random colours and positional coordinates that would fall within a canvas of size W x H. Random values are also used to set the member variables (one idea: you may set these random values within an overloaded default constructor).
5) Using your derived SVGWriter, output the necessary SVG tags that would represent the randomly instantiated shape classes.
1 Derive an HTMLWriter class from TextWriter such that it has the following functions:
void create_header_str( string a_title );
{ string text=" " " n ";
/* write code here so that the input ATITLE replaces the ATITLE in the string variable text. */
}
void create_close_str( )
{
string text=" ";
// write more code below
}
2) Create another program so that an HTML file is created whose name is set as the first input argument. An HTML file will be generated with the above header strings such that the ATITLE is set to the second input argument, e.g. “The webpage of Ada Lovelace”:
$ gen_html.exe test.html "The webpage of Ada Lovelace"
3) Use everything you wrote in A6 to generate an HTML file containing a “random” SVG graphics file, using the code that you developed from part 3 of this assignment.
$ cool_svg_webpage.exe test.html "Cool svg" 100 200 0 0 256 .5
Explanation / Answer
ANSWER::
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.