C++ Help

a. Write a function to judge two lines in the coordinate system being parallel,
perpendicular, or regularly intersected. Use the slopes of the two lines as the
parameters. If the two slope values are equal, the lines are in parallel. If the
product of the two slope values are equal to -1, they are perpendicular. Otherwise,
they are regularly intersected. You have the freedom to choose to print out the
relationship of the lines (i.e., parallel, perpendicular, or regularly intersected) in
this function, or simply return a code so that the printout operations will be done in
the main function.
b. In your main function, prompt the user to input slope values for two lines, then call
the above function to judge the relations of these two lines.


a. Create a function to find the position of the max value in an array.
b. In your main function, create and initialize an array, then call this findMax
function to display the position of the maximum value in the array and display this
value based on the position information.

Design your program so that it can compute the duration between the start date and end
date that one input. Use functions as much as possible. Hint: You can create a leap year
function to determine one year has 366 or 365 days. Also you can use arrays to represent
the number of days in each month of a year (you should also differentiate leap year from
regular year).

I am not sure where to go with any of these. Does anyone have a starting point or idea for me?
Read through the assignment and figure out what functions you need to write:
a. Write a function to judge two lines in the coordinate system being parallel,
perpendicular, or regularly intersected. Use the slopes of the two lines as the
parameters
.

So checkLines(double slope1, double slope2); I'm not sure what this should return yet.
If the two slope values are equal, the lines are in parallel. If the
product of the two slope values are equal to -1, they are perpendicular. Otherwise,
they are regularly intersected.

This tells you what code to put in checkLines()
You have the freedom to choose to print out the
relationship of the lines (i.e., parallel, perpendicular, or regularly intersected) in
this function, or simply return a code so that the printout operations will be done in
the main function.

It's always a good idea to separate output from computation so I'd return a code:
1
2
enum LineRelation {Parallel, Perpendicular, Intersecting};
enum LineRelation checkLines(double slope1, double slope2);

b. In your main function, prompt the user to input slope values for two lines, then call
the above function to judge the relations of these two lines.

So your main program must do this.
a. Create a function to find the position of the max value in an array.

So the function should return the position (the index) of the maximum value in the array. To search an array, you need the array itself and the array's size. So this will be
size_t findMax(int array[], size_t arraySize);

Design your program so that it can compute the duration between the start date and end
date that one input.

This is harder than the other 2. Leave it for last. One question: how should the duration be represented? Days? Seconds?
#include <iostream>
using namespace std;
int checkLines(double slope1, double slope2)
{
if (slope1 = slope2)
{
cout << "\n Your slopes are parallel." << endl;
}
if (slope1*slope2 = -1)
{
cout << "Your slopes are perpendicular." << endl;
}
else
cout << "Your slopes are regularly intersected." << endl;
}
int main()
{
int slope1, slope2;
cout << "\n Please input two slopes of two different lines."<<endl;
cin >> slope1;
cin >> slope2;
checkLines(slope1,slope2);



}

Sorry to get back so late, is this acceptable? I seem to get a problem with slope1 in the main checkLines function.
that code won't work, use:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;
double slope1, slope2, slopemul;
void checkLines()
{
if (slope1 == slope2)
{
cout << "\n Your slopes are parallel." << endl;
}
slopemul=slope1*slope2;
if (slopemul==-1)
{
cout << "Your slopes are perpendicular." << endl;
}
else
cout << "Your slopes are regularly intersected." << endl;
}
int main()
{
cout << "\n Please input two slopes of two different lines."<<endl;
cin >> slope1;
cin >> slope2;
checkLines();
}
The only problem seems to be when the lines are parallel it also prints out the else parameter.
The three cases need to be a 3-way if/then/else. Note that I've also changed checkLines() to take the slopes as parameters since that was specifically required in the assignment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
void checkLines(double slope1, double slope2)
{
    if (slope1 == slope2) {
        cout << "\n Your slopes are parallel." << endl;
    } else if (slope1*slope2 == -1) {
        cout << "Your slopes are perpendicular." << endl;
    } else {
        cout << "Your slopes are regularly intersected." << endl;
    }
}

int main()
{
    double slope1, slope2;
    cout << "\n Please input two slopes of two different lines."<<endl;
    cin >> slope1;
    cin >> slope2;
    checkLines(slope1, slope2);
}

Topic archived. No new replies allowed.