Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I already know which library to include in my cpp file. I also know I have to write a cpp file that includes the int

I already know which library to include in my cpp file. I also know I have to write a cpp file that includes the int main function with parameters that allow for command line arguments. I also know that my message such as "Goodbye" or "Hello" is going to be a vector string. However, I do not know how the helper function fits into this puzzle. I do know the helper function is going to read the provided font from a file. How do integrate the provided.cpp file into the int main cpp file?

The helper function

void ReadFont(const std::string &font_file, int &width, int &height, std::vector > &bitmap_letters) 

is in the provided.cpp file, a file that is already completed but does NOT contain an int main function. Is there a way to use the provided.cpp file in my own source code file called ascii_font_art.cpp. Or can I use the provided.cpp file and rename it as ascii_font_art.cpp but this time the main function is included.

#include  #include  #include  #include  #include  #include  #include  #include  // ====================================================================================== // Helper function to read the provided font from a file. The format // of the font file is described in comments below. The width, // height, and bitmap_letters variables are set by this function. void ReadFont(const std::string &font_file, int &width, int &height, std::vector > &bitmap_letters) { // open the font file for reading std::ifstream istr(font_file.c_str()); if (!istr) { std::cerr << "ERROR: cannot open font file " << font_file << std::endl; exit(0); } // read in the width & height for every character in the file istr >> width >> height; assert (width >= 1); assert (height >= 1); // Create a vector to store all 256 ASCII characters of the // characters. Each character is represented as a vector of //  strings that are each  wide. Initially the // characters are unknown (represented with the '?' character). bitmap_letters = std::vector > ( 256, std::vector ( height, std::string(width, '?'))); // read in all the characters // first is the ascii integer representation of the character int ascii; while (istr >> ascii) { assert (ascii >= 0 && ascii < 256); // next the character is printed in single quotes char c; istr >> c; assert (c == '\''); // use std::noskipws to make sure we can read the space character correctly istr >> std::noskipws >> c; // verify that the ascii code matches the character assert (c == (char)ascii); // switch back to std::skipws mode istr >> std::skipws >> c; assert (c == '\''); // read in the letter std::vector bitmap; std::string tmp; for (int i = 0; i < height; i++) { istr >> tmp; assert ((int)tmp.size() == width); // make sure the letter uses only '#' and '.' characters for (unsigned int j = 0; j < tmp.size(); j++) { assert (tmp[j] == '.' || tmp[j] == '#'); } bitmap.push_back(tmp); } // overwrite the initially unknown letter in the vector bitmap_letters[ascii] = bitmap; } } 

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 Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions