code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

// Graph Table.cpp : Defines the entry p

//     oint for the console application.

//takes in linear equation in two forms 

//     and prints 10 ordered

//pairs. Menu application

#include "stdafx.h"

#include 

int intboolfalsetrue;

int const slope = 1, intercept = 2, quit = 3;

//menu functions

int DoMenu();

void DoSlope();

void DoGeneral();

int main(int argc, char* argv[])

    {

     int choice = 1;

     int fQuit = false;

     while (!fQuit)

         {

         choice=DoMenu();

         if (choice < slope || choice > quit)

             {

             cout << "Invalid choice.\n";

             break;

             }

             switch (choice)

                 {

                 case slope:

                 DoSlope();

                 break;

                 case intercept:

                 DoGeneral();

                 break;

                 case quit:

                 fQuit = true;

                 cout << "Exiting...";

                 break;

                 }//end switch

                 }//end loop

                 return 0;

            }//end program

            int DoMenu()

                {

                 //main menu

                 int choice;

                 cout << "\n*** Menu ***\n";

                 cout << "(1) y-intercept form\n";

                 cout << "(2) General Linear form\n";

                 cout << "(3) Quit\n";

                 cin >> choice;

                 return choice;

            }

            //do the table with slope intercept form

            //     

            void DoSlope()

                {

                 int slope, intercept, y;

                 cout << "Enter m and b from the equation y = mx + b:\n";

                 cout << "m: ";

                 cin >> slope;

                 cout << "b: ";

                 cin >> intercept;

                 cout << "\nY: ";

                 for (int x=-5; x<6; x++)

                     {

                     y = (slope * x) + intercept;

                     cout << "(" << x << "," << y << ") ";

                     }

                }

                //do the table with general linear form

                void DoGeneral()

                    {

                     int a, b, c, ax, cdiv, y;

                     cout << "\nEnter A, B, and C from the equation Ax + By = C:\n";

                     cout << "A: ";

                     cin >> a;

                     cout << "B: ";

                     cin >> b;

                     cout << "C: ";

                     cin >> c;

                     cout << "Y: ";

                     // change to y = (-ax + c) / b

                     // / -ax + c by b

                     ax = (-a) / b;

                     c = c / b;

                     for (int x = -5; x < 6; x++)

                         {

                         y = (ax * x) + c;

                         cout << "(" << x << "," << y << ") ";

                         }

                    }