Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ 1) Create a source and a header file for the functions and name them screen.cpp and screen.h, respectively. You can find a file main.cpp

C++

1) Create a source and a header file for the functions and name them screen.cpp and screen.h, respectively. You can find a file main.cpp with this post. Make sure to use the names exactly as typed, otherwise the TAs may return the files to you.

a) Define a function printScreen that accept the two-dimensional array for the screen by reference. Notice that you need to define global variables g_width and g_height in your header file for screen. I have used g_width = 40 and g_height = 20 in my example but different values could be used. Notice further that as we pass the fixed-sized array by reference we do not need to pass dimensions. The function printScreen is to print the array line-by-line to the console.

b) Define a function clearScreen that accept the two-dimensional array for the screen by reference and sets all the characters in the 2D array to the empty space ' .

c) Define a function gridScreen that accept the two-dimensional array for the screen by reference and two parameters for the horizontal and vertical lines in the grid, respectively. The number of vertical lines is optional and if the number is not specified, your function should use the same number of vertical than horizontal lines. Your function is to degrade gracefully if the number of lines exceeds the number of rows or columns available. Also inputs of 0 lines have to work and negative numbers should be treated as 0.

The main.cpp file:

#include

#include "screen.h"

using std::cout;

using std::cin;

using std::endl;

int main() {

char screen[g_height][g_width]{};

clearScreen( screen );

int hLines, vLines;

cout << "No. of Horizontal and Vertical Lines: "; cin >> hLines; cout << endl;

gridScreen( screen, hLines );

printScreen( screen );

// No clear screen

cout << "Drawing new grid over old grid:" << endl;

cout << "No. of Horizontal Lines: "; cin >> hLines;

cout << "No. of Vertical Lines: "; cin >> vLines; cout << endl;

gridScreen( screen, hLines, vLines );

printScreen( screen );

clearScreen( screen );

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

Students also viewed these Databases questions