Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Simulate movement of text object across the screen using sleep(1) ; and cout < < 033[2J033[1;1H //to clear screen These are non-negotiable. Have to

C++

Simulate movement of text object across the screen using sleep(1); and cout << "\033[2J\033[1;1H" //to clear screen These are non-negotiable. Have to use sleep(1) and make it work, per instructor instruction.

The code I have written (below) clears the screen but does not show the movement of the object. Please help! It is supposed to show the object moving horizontally or vertically.

#include #include #include #include using namespace std;

int main() { enum Direction {Horizontal = 'H', Vertical = 'V'}; char usr_direction; char response; string triangle; string down; string right; const int move = 12; //will indicate how many to move int height; //number of lines of object int b = 1; do { cout << "Enter the height of the structure: "; cin >> height; cout << "Which direction? H for Horizontal or V for vertical: "; cin >> usr_direction; usr_direction = toupper(usr_direction); for (int i = 1; i <= height; i++) //triangle { for(int j = 0; j<= height-i; j++) { triangle += " "; } for(int k = 0; k != 2*i-1; k++) { triangle +='*'; } triangle += ' '; } cout << triangle << endl; while( b <= move) { sleep(1); // wait for one second before clearing cout << "\033[2J\033[1;1H"; //clear screen switch (usr_direction) { case 'H': right = "/t"; // Horizontal cout << right << triangle; b++; break; case 'V': down = " "; // Vertical cout << down << triangle;

b++; break; default: cout << "Inappropriate response."; }

} cout << "Do you want to replay? Y/N: "; cin >> response; }while(response == 'Y' || response == 'y'); return 0; }

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

More Books

Students also viewed these Databases questions