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

in c++ how do I get this to run // hwk_01_main.cpp #include \"window.h\" // Use

ID: 3750775 • Letter: I

Question

in c++ how do I get this to run

// hwk_01_main.cpp

#include "window.h"

// Use standard main to have console background:
int main()
{
    Window window( "Demo" );
    window.show();
    window.run();

    char ch;
    std::cout << "Enter x and press Enter to exit: ";
    std::cin >> ch;

}

________________________________

// window.cpp

#include "window.h"

//-----------------------------
// Window implementation
//-----------------------------
Window::Window( char* title_ )
    :
    inp_box ( new Input),
    out_box ( new Output),
    btn_set_text ( new Button)
{
    title = title_;

    //inp_box = new Input;
    //out_box = new Output;
    //btn_set_text = new button;
   
    inp_box.value( "12345" );
    out_box.value( "67890" );

}

void Window::click_btn_set_text() {
    char* text = inp_box.value();
    out_box.value( text );
}

void Window::show()
{
    std::cout << "Window: " << title << ' ';
    std::cout << inp_box.value() << ' ';
    std::cout << out_box.value() << ' ';
    std::cout << ' ';
}

void Window::run()
{
    click_btn_set_text(); // user clicks the button
    show();               // display changes
}


//-----------------------------
// Input implementation
//-----------------------------
char* Input::value()
{
    return text;
}

void Input::value( char* text_ )
{
    text = text_;
}

//-----------------------------
// Input implementation
//-----------------------------
char* Output::value()
{
    return text;
}

void Output::value( char* text_ )
{
    text = text_;
}
___________________________________

// window.h
// ...
#include <iostream>
#include <memory> // for unique_ptr
// ...
class Window {
    char* title;
    std::unique_ptr< Input > inp_box;
    std::unique_ptr< Output > out_box;
    std::unique_ptr< Button > btn_set_text;

public:
    // constructor
    Window(char* title_);
    // operations
    void click_btn_set_text();
    void show();
    void run();
}; // class Window
_________________________________

Explanation / Answer

At frst change #include "window.h" in your main.cpp to #include "window.cpp" and in your window.cpp file change #include "window.h" to #include<windows.h>.

It's windows.h not window.h and since it's a standard library file you need to use (<>) instead of (" ") (double inverted commas).

If you are working on windows environment then you need to download this file externally, if this file doesn't exist in the standard library and include it with (" ") (double inverted commas).

But If you are using a g++ compiler in Linux environment then note that windows.h file does not come in handy for Linux operating systems. You need to provide the whole implementation of windows.h for Linux on your own then only you will be able to run this program,

or you can install the windows toolchain and cross-compile your code and then run it.