I write a program in C++ that asks the user for names of students and their cooresponding midterm scores ...

Q

I write a program in C++ that asks the user for names of students and their cooresponding midterm scores ...

✍: Guest

A
I write a program in C++ that asks the user 
for names of students and their cooresponding
midterm scores, at the end, it displays each
person, their average, gpa, class ave, total
a's, b's, etc.  I make the exe and it works
fine, how do I make it run in something other
than the command prompt, I mean, make it so 
that it is like a page where you can just
enter the info in and hit enter and it 
display the calculates in say, a box 
that was empty at the bottom of the page?




--------------------------------------------
I. Event Driven Programming, Part #1
-------------------------------------------

The most challenging hurdle that most new
programmers face when moving from the command 
line to a graphical user interface is getting 
their head around event-driven programming. 
While there are some rare exceptions--I worked 
on a couple of PlayStation2 games that had menu
systems that were only semi-event driven--
practically ALL graphical applications use 
an event-driven architecture.

In a typical command line application,
you get some input from the user at startup,
immediately do some work based on the input 
and then exit. If you need more input from 
the user you display a prompt and wait there
until the user enters something. [KEY POINT:
The *program* controls the flow of execution.]

In an event driven application, the program 
starts up and then waits there for "something"
to happen. "Something" might be a keystroke,
mouse click, tick from a timer or any number 
of other things. Most often, it's related to
 some sort of input from the user. When
"something" happens, the program then 
responds and does some work. 
This "something" is called an EVENT. 
Events are the core of event-driven programming. 
Events tell the program when the user does
something that the program needs to respond to.
 [KEY POINT: The *user*
controls the flow of execution.]

Here is some pseudo-code for a typical 
command line program:

void main()
{
     getKeystroke();
     doSomeWork();
     exit();
}


Here is the same pseudo-code converted into
 a home-brew event-driven
program:

void main()
{
//do forever (this loop is also called the "pump")
     while(true) { 
 // every time "something" happens, call 
 // the function that goes along with it
          if ( getKeystroke() ) {
               onKeyPress();
          }         
          if ( exitKeyPressed) {
                exit();
          }
     }
}

void onKeyPress() {
    doSomeWork();
}


Cheesy as that sounds, that is exactly how 
most event-driven applications work... 
including large Windows applications. I am
over-simplifying a bit, but not by much. 
In addition to events, Windows adds an extra
layer called MESSAGES to make its job easier.
Messages are just bits of data 
(a UINT to be exact) with some
parameters attached that get passed around 
in order to tell a program what event just 
happened. Each MESSAGE passes a number, which
represents a specific EVENT. Then the program's 
EVENT HANDLER is called with that message number.
An event handler is a function in your program
that handles an event; or in other words, 
a function that does "something" 
when "something" happens.

In our pseudo-code listing, this concept 
could be written like so:

void main()
{
    // do forever ("MESSAGE PUMP")
     while(true) { 

// "translate" the events... every time 
//"something" happens,
// set the variable "message" 
//to the number that corresponds
          int message;
          if ( getKeystroke() ) {
               message = 1;
          }         
          if ( exitKeyPressed) {
                message = 2;
          }

// "dispatch" the events... call a main
// event handler to
// figure out which sub-event handler to call
          doEvent(message);
     }
}

// MAIN EVENT HANDLER
void doEvent(int message)
{
     switch(message) {

           case 1:
                onKeyPress();
                break;

           case 2:
      

2012-03-14, 2663👍, 0💬