Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: How to write a program, that parses a script written in ASCII and draws characters on a canvas? ******Project.h starter ********* #pragma once #include

C++: How to write a program, that parses a script written in ASCII and draws characters on a canvas?

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed******Project.h starter *********

#pragma once

#include #include #include

// the type that you must provide class Painter {

public: // You must porovide these functions with exactly this signature // Painter Constructor Painter(const std::string &fname); // this function parses the file, draws the canvas, and logs errors void CreateCanvas();

std::vector<:string> GetCanvas() const { // return the canvas // return canvas_; }

std::vector<:string> GetErrorLog() const { // return the error log // return error_log_; }

private: // the private stuff that we won't be testing directly // All of these are optional, but are guides to how you can build the class

// directions (can be represented by ints, but an enum class is cleaner) // enum class direction { up, down, left, right }; // store the direction // direction dir_ = direction::right;

// number of rows in the canvas // int rows_ {10};

// number of columns in the canvas // int columns_{10};

// the current pen_symbol // char pen_symbol_{'#'};

// pen position can be represented by a pair or 2 different ints, etc // std::pair pen_position_{0,0};

// the actual canvas // std::vector<:string> canvas_ = std::vector<:string>(rows_,std::string(columns_,' '));

// the error log // std::vector<:string> error_log_;

// the lines of the .pf file (with line numbers). A vector of strings, where // the position represents the line number is also reasonable // std::map lines_;

// These are functions that you will probably find useful to write // Note that these functions are up to you; change the names, signature, etc. // add functions if you want, of course // Whatever works for you

// Parse a single line. (A good place to record a line error to the log // void Parse(int line_num,const std::string& line);

// reset the dimensions of the canvas // void SetDim(int line_num, int x_dim, int y_dim);

// Set the position of the pen // void SetPenPosition(int line_num, int x_pos, int y_pos);

// Set the pen symbol // void SetPenSymbol(int line_num, int pen_symbol);

// Draw the current symbol at the current position // void Draw();

// Move the pen in the direction it is facing n steps // void Move(int n);

// Turn the pen 90 degrees clockwise n times // void Turn(int n);

// Repeat a range of commands the specified number of times // void Repeat(int line_num,int n, int start, int end); };

****Main.cpp****

#include "proj08.h" #include

int main(int, char**args) {

Painter painter(args[1]); painter.CreateCanvas();

auto result = painter.GetErrorLog().empty() ? painter.GetCanvas() : painter.GetErrorLog();

for (auto &line : result) std::cout KTurtle (https://en.wikipedia.org/wiki/KTurtle) is a cool graphics-drawing application that has its own mini-programming-language. For this project, we will be writing a program (in C++), that parses a script written in a version of this mini-language and draws characters on a canvas. To make this simple, we will be drawing ASCII characters on regular output (std::cout). You might call this ASCII art. The programming language is pretty simple, e.g, we won't have colours, different sized cursors, etc. In particular, our mini-scripting-language won't be braced, so you don't have to recognize nested structures Still, our mini-language will be able to generate some interesting graphics A script consists of a set lines where each line is a command. The lines are implicitly numbered (the numbers are not part of the script) starting with Line number1 1. SetDim 10 12 2. Repeat 100 3-7 3. Draw 4. Move 1 5. Turn 1 6. Move 1 7. Turn 3 generates the following KTurtle (https://en.wikipedia.org/wiki/KTurtle) is a cool graphics-drawing application that has its own mini-programming-language. For this project, we will be writing a program (in C++), that parses a script written in a version of this mini-language and draws characters on a canvas. To make this simple, we will be drawing ASCII characters on regular output (std::cout). You might call this ASCII art. The programming language is pretty simple, e.g, we won't have colours, different sized cursors, etc. In particular, our mini-scripting-language won't be braced, so you don't have to recognize nested structures Still, our mini-language will be able to generate some interesting graphics A script consists of a set lines where each line is a command. The lines are implicitly numbered (the numbers are not part of the script) starting with Line number1 1. SetDim 10 12 2. Repeat 100 3-7 3. Draw 4. Move 1 5. Turn 1 6. Move 1 7. Turn 3 generates the following

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions