I am in my first semester of computer program and this my third project. I am taking this class online so I do not have the in-class benefit of working with others. I have completed all of the code and the program works the way I believe it should. I would just like some more experienced eyes to glance over and offer any advice, either conceptual or functional, or point out any code that may cause some issues, thanks in advanced. (Also, I know from other threads "using namespace std;" is not the preferred way, but my professor prefers it.)
//Algorithm:
// 1. Prompt user and get problem selection using choice function
// 2. If case 1, get x-y coordinates from points one and two using reference
// function
// 3. Display two-point line formula from reference function
// 4. Perform two-point line equation using formula and reference functions
// 5. Display Slope-Intercept line form using formula function from reference
// functions
// 6. If case 2, get line slope and x-y coordinates using reference function
// 7. Display Point-Slope line form from reference function
// 8. Perform point-slope line equation using value returning formula function
// and reference functions
// 9. Display Slope-Intercept line form using formula function from reference
// function
//10. Prompt user to determine if they want to continue program
//11. If yes, repeat functions. If no, terminate program
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void getProblem ();//non-value returning function
void get2Pt (double& u1, double& u2, double& u3, double& u4);//non-value returning function
void display2Pt (double u1, double u2, double u3, double u4);//non-value returning function
void slpIntForm2Pt (double s1, double s2, double s3, double s4, double& m,
double& b); //non-value returning function
void getPtSlp (double& m, double& t1, double& t2);//non-value returning function
void displayPtSlp (double m, double t1, double t2);//non-value returning function
double slpIntFromPtSlp (double m, double t1, double t2);//value returning function
void displaySlpInt (double m, double b);//non-value returning function
int main ()
{
double x1, y1;//Set variables
double x2, y2;
double m, b;
int choice;
char ans;
cout << fixed << showpoint << setprecision (2);//Set precision
do//Program menus
{
getProblem ();//Call menu function
cin >> choice;//Input choices
cout << endl;
switch (choice)
{
case 1://Selection one from menu function
get2Pt (x1, y1, x2, y2);//Function call
display2Pt (x1, y1, x2, y2);//Function call
slpIntForm2Pt (x1, y1, x2, y2, m, b);//Function call
displaySlpInt (m, b);//Function call
break;
case 2://Selection two from menu function
getPtSlp (m, x1, y1);//Function call
displayPtSlp (m, x1, y1);//Function call
b = slpIntFromPtSlp (m, x1, y1);//Function call
displaySlpInt (m, b);//Function call
break;
default:
cout << "Invalid input, please try again.\n" << endl;
}
cout << "Do you want to do another conversion? Enter Y for yes "
<< "or N for no: ";
cin >> ans;
cout << endl;
}
while (ans == 'y' || ans == 'Y');
{
cout << "Have a great day!" << endl;
}
return 0;
}
void getProblem ()//Starting menu function
{
cout << "Select the form that you would like to convert to "
<< "slope-intercept form:" << "\n" << endl;
cout << "1: Two-Point form (Must know two points of the line)" << endl;
cout << "2: Point-Slope form (Must know the line's slope and on point "
<< "on the line)" << endl;
}
void get2Pt (double& u1, double& u2, double& u3, double& u4)//Reference function
{
cout << "Enter x-y coordinates for point one separated by a space: ";
cin >> u1 >> u2;
cout << endl;
cout << "Enter x-y coordinates for point two separated by a space: ";
cin >> u3 >> u4;
cout << endl;
}
void display2Pt (double u1, double u2, double u3, double u4)//Display function for get2Pt
{
cout << "Two-Point Form" << endl;
cout << "m = ";
if (u2 < 0)
{
cout << "(" << u4 << " + " << abs(u2) << ")/";
}
else
cout << "(" << u4 << " - " << u2 << ")/";
if (u1 < 0)
{
cout << "(" << u3 << " + " << abs(u1) << ")\n" << endl;
}
else
cout << "(" << u3 << " - " << u1 << ")\n" << endl;
}
void slpIntForm2Pt (double s1, double s2, double s3, double s4, double& m,
double& b)//Formula Function for get2Pt
{
m = (s4 - s2)/(s3 - s1);
b = s2 - (m * s1);
}
void displaySlpInt (double m, double b)//Display function for both formula functions
{
cout << "Slope-Intercept Form" << endl;
if (b > 0)
{
cout << "y = " << m << "x + " << b << "\n" << endl;
}
else
cout << "y = " << m << "x " << b << "\n" << endl;
}
void getPtSlp (double& m1, double& t1, double& t2)//Reference Function
{
cout << "Enter the Slope of the Line: ";
cin >> m1;
cout << endl;
cout << "Enter the x-y coordinates: ";
cin >> t1 >> t2;
cout << endl;
}
void displayPtSlp (double m, double t1, double t2)//Display Function from getPtSlp
{
cout << "Point-Slope Form" << endl;
if (t1 < 0 && t2 < 0)
{
cout << "y + " << abs(t2) << " = " << m << "(x + " << abs(t1) << ")\n"
<< endl;
}
else if (t1 < 0)
{
cout << "y - " << t2 << " = " << m << "(x + " << abs(t1) << ")\n"
<< endl;
}
else if (t2 < 0)
{
cout << "y + " << abs(t2) << " = " << m << "(x - " << t1 << ")\n"
<< endl;
}
else
cout << "y - " << t2 << " = " << m << "(x - " << t1 << ")\n" << endl;
}
double slpIntFromPtSlp (double m, double t1, double t2)//Value function for getPtSlp
{
double b;
b = t2 - (m * t1);
return (b);
}