c++ Screensaver-like Program 2D array HELP

Hello! I have a coding project that I can't seem to start properly. The instructions are:

You are to write a program that randomly fills the entire screen with a character, like an asterisk, with certain foreground/background colors. After you've filled the entire screen with the character, you'll shift foreground/background colors and do it again and again, shifting foreground/background colors for a hypnotic effect! The program will do this endlessly in an infinite loop, until the user either stops it with a Ctrl+c keystroke, or simply forgets to breathe and expires.

cscreen.h -- This header file contains the declaration for the CScreen class. This class has two data members -- one that stores the character to display, and another which stores the sleep interval that can be used as an argument to the usleep function. These data members will get their values from an external file called config.dat, which is read by the class constructor. The constructor will also be responsible for performing any initialization needed by the curses library. The CScreen class only has one other member function, Scatter, which is responsible for the random drawing of characters. It will use a local 2D array of bools to keep track of what's drawn to the screen, as well as cycle the foreground/background colors for display.

main.cpp -- Obviously, this is the main module that drives the whole program. It creates an instance of the CScreen class, then calls that object's Scatter function, which takes it from there to randomly fill the screen.

config.dat -- This is the configuration file that the program reads before it begins. If you open it up with a text editor, you'll see that it contains two items: the character to display, and the sleep interval to use when the usleep function is called. Look in the main module and you'll see the name of this file is passed to the CScreen constructor; if you look in the private section of that class, you'll see how the class stores the items in config.dat in its private data members.

I'm supposed to create the scatter program in cscreen.cpp but I do not know how to begin. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//main.cpp
 
#include    "cscreen.h"


// ==== main ==================================================================
//
// ============================================================================

int     main()
{
    // create a screen object
    CScreen         screen("config.dat");

    // have the object randomly fill the screen with a colored character
    screen.Scatter();
    return 0;

}  // end of "main"

//cscreen.h

#ifndef CSCREEN_H
#define CSCREEN_H

#include    <iostream>
#include    <fstream>
using namespace std;

class   CScreen
{
public:
        CScreen(const char  fname[]);

    // member functions
        void            Scatter();

private:
        char            m_dispChar;
        int             m_sleep;
};

#endif  // CSCREEN_H
Last edited on
Topic archived. No new replies allowed.