Programming Assignment 3Date Posted: November 5
|
||||
Background Information | ||||
Programming assignment 3 adds some new functionality to the
Genetics Simulator written for programming assignment 2, but the
primary addition is that it adds a Graphical User Interface (GUI).
The exact layout of the GUI is left up to the programmer. The
image below shows the layout of the GUI in the demonstration
program. All functionality represented by the demonstration
GUI must be implemented.![]() |
||||
Your Assignment | ||||
You are to modify programming assignment 2 to add a Graphical User Interface
to the Genetics Simulation. All requirements from programming assignments 1 and 2 are to be followed unless modified in the following list of requirements for this simulation.
|
||||
Deliverables | ||||
These products as specified below shall be delivered
electronically via e-mail to the instructor. Since Programming Assignment 3 is for extra credit no documentation is required and no extra credit will be given for documentation. This assignment is worth 15 extra credit points added to your final total. Note: the application must meet the basic requirements to receive any extra credit. There will be no credit given for a GUI that is non-functional. Final Project -- The entire software project (compatible with Microsoft Visual Studio 2012 or 2015) shall be compressed into a zip file and submitted for instructor approval NLT Tuesday, December 3. Just turning in your source files is not acceptable. |
||||
To download a sample executable as well as a data file and a parser for the data file click here. |
Hints This information should guide you through creating the project and setting up things like the timer. Remember that some versions of Visual Studio cannot work on a project stored on your thumb drive. You will have to create the project on the hard drive, work on it there, and then copy it onto your thumb drive for safe keeping. |
Creating the Project and Adding the Genetics Sim Classes |
|
Editing the Dialog Resource |
|
Resizing the Window Programmatically |
You can resize the window dynamically while the program is running with the
following function call which must be in programNameDlg.cpp.
A good place to do this is in the OnInitDialog() function. Which, by the
way is also a good place to instantiate the Genetics Sim object, read and parse
the data file, etc. this->SetWindowPos(NULL, xPos, yPos, width, height, 0); Where: xPos = On screen X coordinate of the upper left corner of the dialog. yPos = On screen Y coordinate of the upper left corner of the dialog. width = Width in pixels of the dialog. height = Height in pixels of the dialog. Buttons, comboboxes, text fields, etc. can also be moved using the variables defined for them. |
Getting/Setting text in an Edit Control (text box) |
The following code will copy the text in a GUI Edit Control into the
defined character array. Assume that m_DataFileName is a variable
defined for the edit control.char datafile[64]; m_DataFileName.GetWindowText(datafile, 63); The following code will set the text in a GUI Edit Control using the defined character array. Assume that m_DataFileName is a variable defined for the edit control. m_DataFileName.SetWindowText(datafile); |
Run Simulation Event Handlers |
The Event Handler function (called OnBnClickedRunSim in the demo) is where you
get name of the data file from the dialog widgets.
Below is the code for the demo function. Note: m_NumOffspringTF was the variable
assigned to the text field object holding the number of offspring.void CProg3Dlg::OnBnClickedRunSim() { char line[32]; m_NumOffspringTF.GetWindowText(line, 31); int numOffspring = atoi(line); if(numOffspring <= 0) { MessageBoxA("You must enter the number of offspring (1-1000).", "Invalid Offspring Count", MB_OK | MB_ICONWARNING); return; } m_TheSim = MendelianSim::getInstance(); m_TheSim->generateOffspring(numOffspring); // Display the results in the list box m_TheSim->printResults(&m_ExpResultsListBox); } |
Below is the code for the demo function handling button clicks on the
initialize simuation button. YOU WILL NOT BE ABLE TO JUST COPY AND PASTE THIS CODE INTO YOUR PROGRAM AND HAVE IT WORK CORRECTLY. YOU MUST STUDY THE CODE TO SEE WHAT IT IS DOING AND THEN ADAPT IT TO WORK IN YOUR PROGRAM.//------------------------------------------------------------- // Handle clicks on the Initialize Simulation button //------------------------------------------------------------- void CProg3Dlg::OnBnClickedButton1() { char fileName[64]; // Data file name char line[64]; int count; Organism *org; MasterGene *mGene; count = 1; vector |