Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program to print white lowercase \'o\'s on a black background across

ID: 3783526 • Letter: W

Question

Write a C++ program to print white lowercase 'o's on a black background across the middle of the screen. Next, have a captial 'O' move from left to right, and back, on top of the lower-case 'o's using each of the colors specified by the ANSI escape sequences. After you've "bounced" a white 'O', go to the next line and end your program. You may assume a screen size of 80x25 (80 chars across by 25 lines)

Basic animation is a simple 3-step process: Draw something Pause so the eye can see it. Erase the old and go to #1. To do this, you'll need a pause function. Since we have not discussed this you'll need to use the following code in your program:

Here is an example:

The capital O moves from left to right then right to left and changes color every time it gets back to the leftmost lower-case o.

ANSI Escape Codes:

All sequences begin with the ESC char (ASCII value 27):

Text colors:

Foreground = F + 30
Background = B + 40

Edit: Updated the include statements to show properly. In response to the question, I do not know what OpenGL is, so I am going to say no. This is an introductory C++ class, so the code should be relatively simple without the use of any particularly advanced libraries.

"[2J" Clear Screen "[R;Cf" Move cursor to row R and column C "[F;Bm" Set colors (see below) Eile Edit View Ierminal Tabs Help 00000000000000000000000000000000000000000000000000000000000000000000000000000000

Explanation / Answer

// color setter inline void SetColor(WORD color){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); } // helper class class color { public: color(WORD val) : m_val(val) { } void set() const { SetColor(m_val); } private: WORD m_val; }; // instances of helper class to avoid need to remember 4 is red, etc static const color red(4); static const color green(2); static const color blue(1); static const color white(7); // etc // overload operator
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote