CS 144 Advanced C++ Programming April 9 Class Meeting

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

CS 174: Web Programming April 28 Class Meeting
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
CS 160: Software Engineering October 8 Class Meeting
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
CS 151: Object-Oriented Design October 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 160: Software Engineering September 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Cohesion and Coupling CS 4311
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design September 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Android Security Model that Provide a Base Operating System Presented: Hayder Abdulhameed.
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Frameworks CompSci 230 S Software Construction.
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
CS 151: Object-Oriented Design November 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 160 and CMPE/SE 131 Software Engineering February 25 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
CS 151: Object-Oriented Design December 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Advance Computer Programming Market for Java ME The Java ME Platform – Java 2 Micro Edition (J2ME) combines a resource- constrained JVM and a set of Java.
Software Reuse. Objectives l To explain the benefits of software reuse and some reuse problems l To discuss several different ways to implement software.
CSC 222: Object-Oriented Programming
CMPE 135: Object-Oriented Analysis and Design August 31 Class Meeting
Software Design Refinement Using Design Patterns
OPERATING SYSTEM CONCEPT AND PRACTISE
CS 325: Software Engineering
IS301 – Software Engineering V:
Working in the Forms Developer Environment
CMPE 280 Web UI Design and Development August 29 Class Meeting
Topics Graphical User Interfaces Using the tkinter Module
CompSci 230 S Software Construction
Introduction to Programming and Visual Basic
CMPE 135: Object-Oriented Analysis and Design September 26 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CS 153: Concepts of Compiler Design August 29 Class Meeting
SOFTWARE DESIGN AND ARCHITECTURE
Java Beans Sagun Dhakhwa.
CS 153: Concepts of Compiler Design October 5 Class Meeting
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
MVC and other n-tier Architectures
Event Driven Programming Dick Steflik
CMPE 280 Web UI Design and Development October 24 Class Meeting
CS 153: Concepts of Compiler Design November 30 Class Meeting
Chap 7. Building Java Graphical User Interfaces
CSCI/CMPE 3334 Systems Programming
Graphical User Interfaces -- Introduction
Programmable Logic Controllers (PLCs) An Overview.
VISUAL BASIC FINAL PROGRAMMING PROJECT
CMPE 280 Web UI Design and Development January 30 Class Meeting
CMPE 152: Compiler Design August 23 Class Meeting
Software models - Software Architecture Design Patterns
CMPE 280 Web UI Design and Development January 29 Class Meeting
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design March 19 Class Meeting
CMPE 152: Compiler Design February 28 / March 5 Lab
CS 144 Advanced C++ Programming January 31 Class Meeting
CMPE 135: Object-Oriented Analysis and Design February 28 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor:
CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
CS 144 Advanced C++ Programming April 11 Class Meeting
CMPE 152: Compiler Design March 7/12 Lab
CMPE/SE 131 Software Engineering March 7 Class Meeting
CMPE 280 Web UI Design and Development August 27 Class Meeting
Brown Bag Seminar Summer 2007
CMPE 152: Compiler Design August 27 Class Meeting
CMPE/SE 131 Software Engineering February 22 Class Meeting
Presentation transcript:

CS 144 Advanced C++ Programming April 9 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Model-View-Controller Architecture (MVC) Design goal: Identify which application components are model, view, or controller. A user cannot directly modify the model.

MVC Implementation: Loose Coupling Keep the implementations of the three objects types separate. Each type of objects does not depend on how the other types are implemented. Your application is easier to develop and maintain faster to develop more robust (resilient to runtime errors)

MVC Model Objects Represent the persistent information maintained by your application. The information can be kept in a database.

MVC View Objects View objects represent user interface components. Input components such as text fields and checkboxes. In each use case, users interact with at least one view object. A view object collects information from users in a form that the model and controller objects can use.

MVC Controller Objects Coordinate the model and view objects. Often have no physical counterpart in the real world. Collect information from view objects for dispatch to model objects. This is how user-entered data can update the model.

Software Frameworks A software framework consists of a set of cooperating classes. These classes implement the essential mechanisms for a particular problem domain. Example: wxWidgets is a C++ software framework for multi-platform GUI programming. A framework imposes a structure on the design and development of applications. It has classes and API that implement the structure. It is more than simply a library.

Software Frameworks, cont’d An programmer builds an application by: Subclassing framework classes. Adding new classes that provide custom functionality. Inversion of control The framework controls the execution flow. The programmer registers callback functions, mostly as event handlers, with the framework. The framework invokes the callback functions at the appropriate times, such as in response to events.

Button Demo

Button Demo, cont’d ButtonPanel.h class ButtonPanel : public wxPanel {     ButtonPanel(wxFrame *parent) : wxPanel(parent, wxID_ANY)     {         init();     } // Event handlers     void on_rock(wxCommandEvent& event);     void on_paper(wxCommandEvent& event);     void on_scissors(wxCommandEvent& event); private:     wxStaticText *button_chosen_text;     void init();     void update_button_choice_text(const Choice choice); };

Button Demo, cont’d ButtonPanel.cpp #include "ButtonPanel.h" void ButtonPanel::init() {     wxSizer *sizer = new wxBoxSizer(wxVERTICAL);     wxPanel *button_panel = new wxPanel(this, wxID_ANY);     wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);     wxStaticText *choose_text = new wxStaticText(button_panel, wxID_ANY,                                                  "Choose:");     wxButton *rock_button     = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(ROCK));     wxButton *paper_button    = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(PAPER));     wxButton *scissors_button = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(SCISSORS)); ...

Button Demo, cont’d ...     rock_button->Bind    (wxEVT_BUTTON, &ButtonPanel::on_rock, this);     paper_button->Bind   (wxEVT_BUTTON, &ButtonPanel::on_paper, this);     scissors_button->Bind(wxEVT_BUTTON, &ButtonPanel::on_scissors, this);     button_sizer->Add(choose_text, 0, 0, 0);     button_sizer->AddSpacer(5);     button_sizer->Add(rock_button, 0, 0, 0);     button_sizer->Add(paper_button, 0, 0, 0);     button_sizer->Add(scissors_button, 0, 0, 0);     button_panel->SetSizer(button_sizer);     wxPanel *chosen_panel = new wxPanel(this, wxID_ANY);     wxSizer *chosen_sizer = new wxGridSizer(2, 0, 5);

Button Demo, cont’d ...     wxStaticText *chosen_text = new wxStaticText(chosen_panel, wxID_ANY,                                                  "Chosen object:");     button_chosen_text = new wxStaticText(chosen_panel, wxID_ANY, "");     button_chosen_text->SetFont(button_chosen_text->GetFont().Larger());     chosen_sizer->Add(chosen_text, 0, wxALIGN_RIGHT, 0);     chosen_sizer->Add(button_chosen_text, 0, 0, 0);     chosen_panel->SetSizer(chosen_sizer);     sizer->Add(button_panel, 0, wxALIGN_CENTER, 0);     sizer->AddSpacer(20);     sizer->Add(chosen_panel, 0, wxALIGN_CENTER, 0);     SetSizer(sizer); }

Button Demo, cont’d void ButtonPanel::on_rock(wxCommandEvent& event) {     update_button_choice_text(ROCK); } void ButtonPanel::on_paper(wxCommandEvent& event)     update_button_choice_text(PAPER); void ButtonPanel::on_scissors(wxCommandEvent& event)     update_button_choice_text(SCISSORS); void ButtonPanel::update_button_choice_text(const Choice choice)     button_chosen_text->SetLabelText(choice_to_wxString(choice));

Assignment #9. GUI-Based RPS Game Develop a GUI-based version of a Rock-Paper-Scissors game.

Assignment #9: Required Features Display which round it is. For each round, there is a way for the human player to choose rock, paper, or scissors. The computer makes a random choice. Display the human’s and the computer’s choices. Display who won each round (or was it a tie). Display a running count of human wins, computer wins, and ties. The default is 20 rounds per game. Provide an interactive way to change that number.

Assignment #9, cont’d Required menu commands Due Tuesday, April 16. About Exit Start a new game Due Tuesday, April 16. 100 points

Assignment #9 Extra Credit Add some basic machine learning to the program. Make the computer’s choices smarter rather than simply random. ML makes it increasingly difficult for a human to beat the computer. In the long run, the computer will win more rounds than a human player.

Simple Machine Learning for RPS Human players of the Rock Paper Scissors game try to develop strategies to beat the opponent. Therefore, humans generally do not make random choices. Human choices exhibit patterns that a computer can discover and exploit.

Simple Machine Learning for RPS, cont’d Continuously record the last N choices between the human and the computer player. Throw out the oldest choice in order to add a new one. For example, suppose N = 5 and during the game, the recorded choices are (the human’s choices are underlined): The last choice was made by the human, and it was paper. PSRSP

Simple Machine Learning for RPS, cont’d For each recorded sequence that ends with the human’s choice, the computer should store how many times that sequence has occurred (each sequence’s frequency). For example, for N = 5, the stored sequences and their frequencies may be (in no particular order, human choices are underlined): RSPSR:1, SPRPP:3, RSPRS:2, RSPSS:4, RSPSP:3, SSRPP:2

Simple Machine Learning for RPS, cont’d Stored frequencies: RSPSR:1, SPRPP:3, RSPRS:2, RSPSS:4, RSPSP:3, SSRPP:2 Suppose that in the previous round, the human chose rock and the computer chose scissors. Then in the current round, the human chose paper and the computer chose scissors. Therefore, the last four choices were RSPS.

Simple Machine Learning for RPS, cont’d Stored frequencies: RSPSR:1, SPRPP:3, RSPRS:2, RSPSS:4, RSPSP:3, SSRPP:2 Last four choices: RSPS The computer can predict that the human will most likely next choose scissors, since RSPSS appears more times than RSPSR and RSPSP in the stored frequencies. Therefore, in the next round, the computer should choose rock to beat the human’s predicted choice of scissors. Update the stored frequencies with the round’s choices.

Simple Machine Learning for RPS, cont’d When a game ends, write the frequency data to a file, so that when a new game begins, these frequencies can be read back in. As the computer plays more games and stores more frequency data, it becomes increasingly more capable of predicting the human’s next choice. In the long run, the computer will become very difficult for humans to beat.

Assignment #9 Extra Credit, cont’d If the computer uses ML, also display what the computer predicted the human will choose. Extra credit: up to 50 points

wx-RPS: Linux