C++ homework/project help

leishi85leishi85 Grand Rapids, MI Icrontian
edited September 2004 in Internet & Media
i am in my dorm doing my hw for engineering 101 that is due tomorrow.

here is the project/hw detail

https://sitka.engin.umich.edu/EngineeringEducation/Eng101/Fall2004/Assignments/assignment2

below is what i got so far.
i'm having trouble to code it to calculate the angle i need to find. any help would be apperciated.
#include <iostream>

#include <cmath>

using namespace std;


double aimingAngle(double A, double T, double D);


void determineTrajectory(double x1, double y1, double x2, double y2, double D, double & A, double & T)


int main()

{
  
	cout << "Input an x y pair for the first point on the trajectory :> ";
  
	cin >> x1 >> y1;

  
	
	cout << "Input an x y pair for the second point on the trajectory :> ";
  
	cin >> x2 >> y2;

  

	cout << "Input the distance for the mortar :> ";
  
	cin >> D;
}

void determineTrajectory(double x1, double y1, double x2, double y2, double D, double & A, double & T)

{
  
	double C;

  
	C = (y2 * (x1 - D)) / (y1 * (x2 - D));
 
  
	T = (x1 * C - x2) / (C - 1);

  
	A = y1 / ((x1 - T) * (x1 - D));

}

double aimingAngle(double A, double T, double D)

}

Comments

  • a2jfreaka2jfreak Houston, TX Member
    edited September 2004
    I fixed some of the errors in your code.

    [php]
    #include <iostream>
    #include <cmath>

    using namespace std;

    double aimingAngle(double A, double T, double D);

    void determineTrajectory(double x1, double y1, double x2, double y2, double D, double& A, double& T);


    int main()
    {
    cout << "Input an x y pair for the first point on the trajectory :> ";
    cin >> x1 >> y1;

    cout << "Input an x y pair for the second point on the trajectory :> ";
    cin >> x2 >> y2;

    cout << "Input the distance for the mortar :> ";
    cin >> D;

    return 0;
    }

    void determineTrajectory(double x1, double y1, double x2, double y2, double D, double& A, double& T)
    {
    double C;

    C = (y2 * (x1 - D)) / (y1 * (x2 - D));

    T = (x1 * C - x2) / (C - 1);

    A = y1 / ((x1 - T) * (x1 - D));
    }

    double aimingAngle(double A, double T, double D)
    {
    }
    [/php]
  • leishi85leishi85 Grand Rapids, MI Icrontian
    edited September 2004
    what did u change exactly??

    this code is far from done, i still haven't calculate for the aimingAngle, and i still need to out the answer to the user.

    i'm just stuck on the part to calculate the aimingAngle
  • leishi85leishi85 Grand Rapids, MI Icrontian
    edited September 2004
    finally got my code figured out, and finished my hw

    here is the final version

    [PHP]
    #include <iostream>

    #include <cmath>

    using namespace std;

    double aimingAngle(double A, double T, double D);

    void determineTrajectory(double x1, double y1, double x2, double y2, double D, double & A, double & T);

    int main()
    {
    double x1, y1, x2, y2, D, A, T;

    cout << "Input an x y pair for the first point on the trajectory :> ";
    cin >> x1 >> y1;

    cout << "Input an x y pair for the second point on the trajectory :> ";
    cin >> x2 >> y2;

    cout << "Input the distance for the mortar :> ";
    cin >> D;

    determineTrajectory(x1, y1, x2, y2, D, A, T);

    double angle = aimingAngle(A, T, D);

    cout << "The trajectory is " << A << "(x - " << T << ")(x - " << D << ") " << endl;
    cout << " The aiming angle is: " << angle << " radians" << endl;
    return 0;
    }

    void determineTrajectory(double x1, double y1, double x2, double y2, double D, double & A, double & T)
    {

    double C;

    C = (y2 * (x1 - D)) / (y1 * (x2 - D));

    T = (x1 * C - x2) / (C - 1.0);

    A = y1 / ((x1 - T) * (x1 - D));
    }

    double aimingAngle(double A, double T, double D)
    {
    double X = ( D - T ) / 2.0 + T;
    double Y = A * ( X - T ) * ( X - D );
    double aimingAngle = atan2(Y,X);

    return aimingAngle;

    }
    [/PHP]
  • mmonninmmonnin Centreville, VA
    edited September 2004
    Yeah atan2. I used it in my C++ Polar<->Rectabgular class. A lot better than atan. No need to worry about which quadrant it was in.
  • leishi85leishi85 Grand Rapids, MI Icrontian
    edited September 2004
    yeah, took a while and then after i figured it out, it's so easy.
  • entropyentropy Yah-Der-Hey (Wisconsin)
    edited September 2004
    Crapweasel! I've decided to get back into teaching myself C++, and I cannot for the life of me get Dev-C++ to run! It just gives some retarded error when trying to compile, and here's what it says...
    (Note: leishi, I copied your final program directly (cuz I wanted to see it :)) so this isn't a structure problem) sorry to thread crap, btw, just extremely frustrated lol. Oh, and I have no idea why it's saying that .... 1) there's no such dir 2) \C++ projects isn't where either the files are saved nor the program installed :-/
  • leishi85leishi85 Grand Rapids, MI Icrontian
    edited September 2004
    hmm, i can compile my code fine, maybe try to reinstall the program.

    i uploaded the code as txt file, and u can try open the file with your program and then try to compile it.
  • mmonninmmonnin Centreville, VA
    edited September 2004
    It compiled correctly for me with VS.Net 2003.

    I am thinking from what you said about the files arent in the same directory is that your project folder is in the above folder your program mentioned and your files are in another.

    Make a new project/solution/etc and copy the code in. Just make sure the program knows what to compile.
  • EMTEMT Seattle, WA Icrontian
    edited September 2004
    Although I've come across some weird errors, I've never seen that one in Dev-C++...

    You could try compiling, running, maybe linking in separate steps.
  • entropyentropy Yah-Der-Hey (Wisconsin)
    edited September 2004
    Mmonin - that's what I did, just in case. So I don't get it, either :-/ . And EMT - I tried doing just compile, but it would give me that error...run won't work because it isn't compiled, etc. Bleh.
  • mmonninmmonnin Centreville, VA
    edited September 2004
    Do you have cmath in your MSDN Library?
  • entropyentropy Yah-Der-Hey (Wisconsin)
    edited September 2004
    Ok, 1) no I don't, so that may be bad later on. 2) The directory it whines about happens to be wherever I put the file, so I don't know what's going on. Anyway, I'll stop thread crapping and start my own :p
Sign In or Register to comment.