QuestionQuestion

Transcribed TextTranscribed Text

This project is meant to display animation on the screen based upon commands provided by an input file. It will read in a command file and perform each action, line by line. In this way, the program will act as an "animation engine". Input The command file is a file containing keyword followed by arguments. It may also contain blank lines and/or comments. Both are optional but your program must be able to support them. Also, the command input file will be provided via a "command line parameter". The following commands are the minimal set your program must support: Command Args Description clear* Clears the screen setms n Sets the pause milliseconds to n. setfg n Sets the text color to n (should only be 30-39) setbg n Sets the background color to n (should only be 40-49) pause Pauses the processing for whatever time last setms value was. slow Pause afer every line of command input (not including blanks and comments) fast Pause only when the pause command is encountered (i.e. turns off pause after every command) plot* row col char Places the cursor at (row, col) and prints char hplot* row col char ent Places the cursor at (row, col) and prints cnt /char/s to the right. vplot* row col char ent Places the cursor at (row, col) and prints ent /char/s down. text* row col string Places the cursor at (row, col) and prints string move* row col h w Dr Moves the contents of the box at (row, col), with height h and width w, Dr and Dc spaces Dc copy* row col h w Dr Copies the box at (row, col), with height h and width w. to (row + Dr. col + Dc) De // {comment} Comment line; entire line is ignored by program quit Notifies the program to stop reading input * After any cursor involved action, put the cursor back at (0,0). It will improve the visual. Output The output of your program is two-fold. On screen, the user will see your beautiful animated artwork. Additionally, you will output information to a log file. The log file shall be named project2.log and will contain information of any erroneous commands encountered. For example, consider the following input file: clear setms 250 plo 10 10 - pause cop 10 20 5 5 20 10 quit The output log file should contain something like: $ cat project2.log Error: Line 4 - bad command "plo*, skipping. Error: Line 6 - bad command "cop", skipping. $ The log file should be re-created/overwritten for every execution of the program. Trimming If the command file input results in output going "off screen" (beyond the 80x25), trim the results. i.e. only display the content that would show within the 80x25 area. This applies to copy, move, hplot. etc. Execution I will be running your programs in one of the following two ways: $ /project2 input. txt or $ -/project2 imput.txt > output.ext Input File as Command-Line Parameter To get the input file as a command-line parameter, we need to now add parameters to the main () and use those like so: int main ( int ent, char* argst 1 ) { string command file - argvt 1 1, 11 continue as bormal ) Don't worry about what the params mean, we'll learn those next week (but would have been too close to the due date). WARNING: if you don't put a filename as the command line parameter, the program will crash. Don't worry about this, you are not currently responsible for handling that: $ /project2 input.dat 11 program runs as normal $ ,/project.2 terminate called after throwing an instance of 'stdr:logie_error' what(): basic_string::_S_construet null not valid Aborted 4 Assumptions You may assume the following: The sereen is 80 characters across by 25 lines down. The commands in the command file are all lower-case. The row and col arguments to the commands are within valid ranges (i.e. no "negative" rows or cols) Any char argument is in fact only 1 character

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
* File:   
* Author:
*
*
*/

#include <cstdlib>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

const int COL = 80;
const int ROW = 25;
const char EMPTY = ' '; //
const long NANO_MILLI = 1000000; // convert from millisecond to nanosecond

// I use this struct to reduce number of function parameter

struct Infor {
    char buffer[ROW][COL]; // terminal buffer
    bool slow;
    string line; // current processed line
    int lineNum; // number of line
    long pause; // pause time
    bool quit;
};

// I use this struct to reduce number of function parameter

struct Clipboard {
    char ** data; // the rectangular that is cut oof the buffer
    int h;
    int w;
};

/**
* turn number to string
* @param num
* @return
*/
template <typename T>
string number2string(T num);

/**
* clear the terminal buffer
* @param infor
*/
void clearBuffer(Infor & infor);

/**
* initialize all features
* @param infor
*/
void initInfor(Infor & infor);

/**
* print the buffer to screen
* @param infor
*/
void printInfor(const Infor & infor);

/**
* all required functions
* @param infor
*/
void setms(Infor & infor);
void setfg(Infor & infor);
void setbg(Infor & infor);

/**
* move cursor to the right place
* @param row
* @param col
*/
void moveCursorTo(int row, int col);

/**
* other required functions
* @param infor
*/
void plot(Infor & infor);
void hplot(Infor & infor);
void vplot(Infor & infor);
void text(Infor & infor);

/**
* paste clipboard to the buffer
* @param clipboard
* @param infor
* @return
*/
bool paste(Clipboard &clipboard, Infor & infor);

/**
* copy a part of the buffer and put in the clipboard
* @param clipboard
* @param infor
*/
void crop(Clipboard...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$60.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats