SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 26 Mar 2018 My Price 10.00

determines the number of rounds to play

IF YOU ARE ABLE TO COMPLETE THIS PROGRAM YOU CAN HAVE THE REST OF MY TUTOR CREDITS ($120.00)

I HAVE ATTACHED THE FILES NEEDED TO USE FLTK GRAPHICS FOR THE C++ PROGRAM.

 

1.    Start with an attractive splash screen showing (at least) the name of the game. Have a START button which then explains how to play the game.

2.    Ask for a difficulty level from 1 to 5; this determines the number of rounds to play, 32/64/128/256/512 respectively. Display the top 5 scores for that difficulty level (read in from the disk; the top scores file starts out empty).

3.    Ask for the player's initials and display them with a blank score below the top 5 scores.

4.    Instruct the player to make that many choices, attempting to be as random as possible, and show how many choices remain. For example, for difficulty level 1 the setup screen might say “You have 32 choices to go; click Heads or Tails.” Remember to redraw the screen each time you change a graphical object!

5.    After that, for each of the next 32 player choices (for difficulty level 1), the computer first makes a secret guess based on the percentage of heads for the most recent 32 choices. For example, if the program calculates that 75% of the most recent 32 choices were heads, then 75% of the time it will guess that the next choice will be heads and 25% of the time it will guess that the next choice will be tails. When the computer has made its secret guess, tell the player to choose and then have the computer say something like “I guessed right—no points for you!” or “You outsmarted me—10 points for you!”

6.    When all the guessing rounds are done, add the player’s score and initials to the scores list, sort the list of 6 scores, and write the top 5 out to disk with initials. Then the next time the game is played, that file will be read in and displayed in step 2 above.  Ask the player if they want to play another game or quit.

7. Add a countdown timer to limit the player to 5 seconds per move. If time expires then say “Time’s up! No points! Next move?” Display a digital clock with the time remaining. Hint: Check the online FLTK documentation for Fl::add_timeout. Note: A timeout just reduces the number of remaining choices in this guessing round (thereby reducing the maximum player score).   

 

/*   Window.h   Minimally revised for C++11 features of GCC 4.6.3 or later   Walter C. Daugherity June 10, 2012 and January 9, 2014*/
//// This is a GUI support code to the chapters 12-16 of the book// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup//
#ifndef WINDOW_GUARD#define WINDOW_GUARD
#include <FL/Fl.H>#include <FL/Fl_Window.H>#include "std_lib_facilities_4.h"#include "Point.h"
namespace Graph_lib{    class Shape;   // "forward declare" Shape    class Widget;
//------------------------------------------------------------------------------
    class Window : public Fl_Window {     public:        // let the system pick the location:        Window(int w, int h, const string& title);        // top left corner in xy        Window(Point xy, int w, int h, const string& title);    
        virtual ~Window() { }
        int x_max() const { return w; }        int y_max() const { return h; }
        void resize(int ww, int hh) { w=ww, h=hh; size(ww,hh); }
        void set_label(const string& s) { copy_label(s.c_str()); }
        void attach(Shape& s) { shapes.push_back(&s); }        void attach(Widget&);
        void detach(Shape& s);     // remove s from shapes         void detach(Widget& w);    // remove w from window (deactivates callbacks)
        void put_on_top(Shape& p); // put p on top of other shapes
    protected:        void draw();
    private:        vector<Shape*> shapes;     // shapes attached to window        int w,h;                   // window size
        void init();    };
//------------------------------------------------------------------------------
           int gui_main(); // invoke GUI library's main event loop    inline int x_max() { return Fl::w(); } // width of screen in pixels    inline int y_max() { return Fl::h(); } // height of screen in pixels
} // of namespace Graph_lib
#endif // WINDOW_GUARD

 

//

// This is a GUI support code to the chapters 12-16 of the book

// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup

//

 

#include "Window.h"

#include "Graph.h"

#include "GUI.h"

 

//------------------------------------------------------------------------------

 

namespace Graph_lib {

 

Window::Window(int ww, int hh, const string& title)

    :Fl_Window(ww,hh,title.c_str()),w(ww),h(hh)

{

    init();

}

 

//------------------------------------------------------------------------------

 

Window::Window(Point xy, int ww, int hh, const string& title)

    :Fl_Window(xy.x,xy.y,ww,hh,title.c_str()),w(ww),h(hh)

    init();

}

 

//------------------------------------------------------------------------------

 

void Window::init()

{

    resizable(this);

    show();

}

 

//------------------------------------------------------------------------------

 

void Window::draw()

{

    Fl_Window::draw();

    for (unsigned int i=0; i<shapes.size(); ++i) shapes[i]->draw();

}

 

//------------------------------------------------------------------------------

 

void Window::attach(Widget& w)

{

    begin();         // FTLK: begin attaching new Fl_Wigets to this window

    w.attach(*this); // let the Widget create its Fl_Wigits

    end();           // FTLK: stop attaching new Fl_Wigets to this window

}

 

//------------------------------------------------------------------------------

 

void Window::detach(Widget& b)

{

    b.hide();

}

 

//------------------------------------------------------------------------------

 

void Window::detach(Shape& s)

    // guess that the last attached will be first released

{

for (vector<Shape*>::size_type i = shapes.size(); 0<i; --i)    

        if (shapes[i-1]==&s)

            shapes.erase(shapes.begin()+(i-1));

}

 

//------------------------------------------------------------------------------

 

void Window::put_on_top(Shape& p) {

    for (int i=0; i<shapes.size(); ++i) {

        if (&p==shapes[i]) {

            for (++i; i<shapes.size(); ++i)

                shapes[i-1] = shapes[i];

            shapes[shapes.size()-1] = &p;

            return;

        }

    }

}

 

//------------------------------------------------------------------------------

 

int gui_main()

{

    return Fl::run();

}

 

//------------------------------------------------------------------------------

 

} // of namespace Graph_lib

#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS //temp

/*

   std_lib_facilities_4.h

   Minimally revised for C++11 features of GCC 4.6.3 or later

   Walter C. Daugherity June 10, 2012 and January 9, 2014

*/

 

/*

simple "Programming: Principles and Practice using C++" course header to

be used for the first few weeks.

It provides the most common standard headers (in the global namespace)

and minimal exception/error support.

 

Students: please don't try to understand the details of headers just yet.

All will be explained. This header is primarily used so that you don't have

to understand every concept all at once.

 

Revised April 25, 2010: simple_error() added

*/

 

#ifndef H112

#define H112 201401L

 

#define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)

 

#if GCC_VERSION >= 40603

//New C++11 headers in GCC 4.6.3 or later

#include <array>

#include <regex>

#include <thread>

#include <mutex>

#include <forward_list>

#include <ratio>

#include <tuple>

#include <chrono>

#include <random>

#endif

 

#include<iostream>

#include<fstream>

#include<sstream>

#include<cmath>

#include<cstdlib>

#include<string>

#include<list>

#include<vector>

#include<algorithm>

#include<stdexcept>

 

//------------------------------------------------------------------------------

 

#if GCC_VERSION >= 40603

#include <unordered_map>

#include <unordered_set>

#else

#define unordered_map hash_map

#ifdef _MSC_VER

#include <hash_map>

using stdext::hash_map;

#else

#include <ext/hash_map>

using __gnu_cxx::hash_map;

 

namespace __gnu_cxx {

 

    template<> struct hash<std::string>

    {

        size_t operator()(const std::string& s) const

        {

            return hash<char*>()(s.c_str());

        }

    };

 

} // of namespace __gnu_cxx

#endif //_MSC_VER

#endif //GCC_VERSION >= 40603

 

//------------------------------------------------------------------------------

 

typedef long Unicode;

 

//------------------------------------------------------------------------------

 

using namespace std;

 

template<class T> string to_string(const T& t)

{

ostringstream os;

os << t;

return os.str();

}

 

struct Range_error : out_of_range { // enhanced vector range error reporting

int index;

Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { }

};

 

 

// trivially range-checked vector (no iterator checking):

template< class T> struct Vector : public std::vector<T> {

typedef typename std::vector<T>::size_type size_type;

 

Vector() { }

explicit Vector(size_type n) :std::vector<T>(n) {}

Vector(size_type n, const T& v) :std::vector<T>(n,v) {}

template <class I>

Vector(I first, I last) :std::vector<T>(first,last) {}

#if GCC_VERSION >= 40603

Vector(initializer_list<T> list) :std::vector<T>(list) {}

#endif

 

T& operator[](unsigned int i) // rather than return at(i);

{

if (this->size()<=i) throw Range_error(i);

return std::vector<T>::operator[](i);

}

const T& operator[](unsigned int i) const

{

if (this->size()<=i) throw Range_error(i);

return std::vector<T>::operator[](i);

}

};

 

// disgusting macro hack to get a range checked vector:

#define vector Vector

 

// trivially range-checked string (no iterator checking):

struct String : std::string {

 

String() { }

String(const char* p) :std::string(p) {}

String(const string& s) :std::string(s) {}

template<class S> String(S s) :std::string(s) {}

String(int sz, char val) :std::string(sz,val) {}

template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { }

 

char& operator[](unsigned int i) // rather than return at(i);

{

if (size()<=i) throw Range_error(i);

return std::string::operator[](i);

}

 

const char& operator[](unsigned int i) const

{

if (size()<=i) throw Range_error(i);

return std::string::operator[](i);

}

};

 

#ifndef _MSC_VER

#if GCC_VERSION >= 40603

namespace std {

 

    template<> struct hash<String>

    {

        size_t operator()(const String& s) const

        {

            return hash<std::string>()(s);

        }

    };

 

} // of namespace std

#else

namespace __gnu_cxx {

 

    template<> struct hash<String>

    {

        size_t operator()(const String& s) const

        {

            return hash<std::string>()(s);

        }

    };

 

} // of namespace __gnu_cxx

#endif //GCC_VERSION >= 40603

#endif //_MSC_VER

 

 

struct Exit : runtime_error {

Exit(): runtime_error("Exit") {}

};

 

// error() simply disguises throws:

inline void error(const string& s)

{

throw runtime_error(s);

}

 

inline void error(const string& s, const string& s2)

{

error(s+s2);

}

 

inline void error(const string& s, int i)

{

ostringstream os;

os << s <<": " << i;

error(os.str());

}

 

#if _MSC_VER<1500

// disgusting macro hack to get a range checked string:

#define string String

// MS C++ 9.0 have a built-in assert for string range check

// and uses "std::string" in several places so that macro substitution fails

#endif

 

template<class T> char* as_bytes(T& i) // needed for binary I/O

{

void* addr = &i;// get the address of the first byte

// of memory used to store the object

return static_cast<char*>(addr); // treat that memory as bytes

}

 

 

inline void keep_window_open()

{

cin.clear();

cout << "Please enter a character to exit\n";

char ch;

cin >> ch;

return;

}

 

inline void keep_window_open(string s)

{

if (s=="") return;

cin.clear();

cin.ignore(120,'\n');

for (;;) {

cout << "Please enter " << s << " to exit\n";

string ss;

while (cin >> ss && ss!=s)

cout << "Please enter " << s << " to exit\n";

return;

}

}

 

 

 

// error function to be used (only) until error() is introduced in Chapter 5:

inline void simple_error(string s) // write ``error: s and exit program

{

cerr << "error: " << s << '\n';

keep_window_open();// for some Windows environments

exit(1);

}

 

// make std::min() and std::max() accessible:

#undef min

#undef max

 

#include<iomanip>

inline ios_base& general(ios_base& b) // to augment fixed and scientific

{

b.setf(ios_base::fmtflags(0),ios_base::floatfield);

return b;

}

 

// run-time checked narrowing cast (type conversion):

template<class R, class A> R narrow_cast(const A& a)

{

R r = R(a);

if (A(r)!=a) error(string("info loss"));

return r;

}

 

 

inline int randint(int max) { return rand()%max; }

 

inline int randint(int min, int max) { return randint(max-min)+min; }

 

inline double sqrt(int x) { return sqrt(double(x)); } // to match C++0x

 

#endif //H112

 

//

// This is a GUI support code to the chapters 12-16 of the book

// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup

//

 

#ifndef SIMPLE_WINDOW_GUARD

#define SIMPLE_WINDOW_GUARD 1

 

#include "GUI.h"    // for Simple_window only (doesn't really belong in Window.h)

#include "Graph.h"

 

using namespace Graph_lib;

 

//------------------------------------------------------------------------------

 

struct Simple_window : Graph_lib::Window {

    Simple_window(Point xy, int w, int h, const string& title );

 

    bool wait_for_button(); // simple event loop

 

private:

    Button next_button;     // the "next" button

    bool button_pushed;     // implementation detail

 

    static void cb_next(Address, Address); // callback for next_button

    void next();            // action to be done when next_button is pressed

 

};

 

//------------------------------------------------------------------------------

 

#endif // SIMPLE_WINDOW_GUARD

/*

   Simple_window.cpp

   Minimally revised for C++11 features of GCC 4.6.3 or later

   Walter C. Daugherity June 10, 2012

*/

 

//

// This is a GUI support code to the chapters 12-16 of the book

// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup

//

 

#include "Simple_window.h"

 

using namespace Graph_lib;

 

//------------------------------------------------------------------------------

 

Simple_window::Simple_window(Point xy, int w, int h, const string& title) :

    Window(xy,w,h,title),

    next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next),

    button_pushed(false)

{

    attach(next_button);

}

 

//------------------------------------------------------------------------------

 

bool Simple_window::wait_for_button()

// modified event loop:

// handle all events (as per default), quit when button_pushed becomes true

// this allows graphics without control inversion

{

    show();

    button_pushed = false;

#if 1

    // Simpler handler

    while (!button_pushed) Fl::wait();

    Fl::redraw();

#else

    // To handle the case where the user presses the X button in the window frame

    // to kill the application, change the condition to 0 to enable this branch.

    Fl::run();

#endif

    return button_pushed;

}

 

//------------------------------------------------------------------------------

 

void Simple_window::cb_next(Address, Address pw)

// call Simple_window::next() for the window located at pw

{  

    reference_to<Simple_window>(pw).next();    

}

 

//------------------------------------------------------------------------------

 

void Simple_window::next()

{

    button_pushed = true;

    hide();

}

 

//------------------------------------------------------------------------------

 

Answers

(5)
Status NEW Posted 26 Mar 2018 01:03 PM My Price 10.00

  ----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------  ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be-----------

Not Rated(0)