| | |
Vector Addition Using OOP?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2009
Posts: 1
Reputation:
Solved Threads: 0
I want to create a program that asks the user to enter two vector (size and direction), and calculates its addition through turning it into components (using OOP).
here's what I've got so far (I don't know how to fix the errors), I'm not sure what's wrong/ to do next (vector 1 has a magnitude of 1 and 60 degrees while vector 2 has 2 and 50 degrees):
Thanks a lot for the help!
here's what I've got so far (I don't know how to fix the errors), I'm not sure what's wrong/ to do next (vector 1 has a magnitude of 1 and 60 degrees while vector 2 has 2 and 50 degrees):
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<cmath> using namespace std; // A class declaration for class Complex // This class creates complex number objects z = x + i*y, // where x is the real and y the imaginary part class Vector { Public: Vector(); void assign (double x, double y); void convert (double x, double y); Vector modulus(); Vector operator+(const Vector &z); Vector operator-(double xsize, double ysize); void Vector::assign(double x, double y){ double size = x; double degree = y; } void Vector::convert(double x, double y){ double xsize = size*cos(degree/180.0); double ysize = size*sin(degree/180.0); } Vector Vector::operator(const Vector &z){ Vector temp; Vector xsize=(*this).xsize+z.xsize; Vector ysize=(*this).ysize+z.ysize; return Temp; ) Vector Vector::modulus(){ resultantvec= sqrt(xsize*xsize + ysize*ysize); return resultantvec; } Vector Vector::operator-(double xsize, double ysize){ resultantrad=atan2(ysize/xsize); resultantdeg=resultantrad*180; return resultantdeg; } //Below, the main() int main(){ Vector num1; Vector num2; num1.assign(1,60); num2.assign(2,50); cout<<"the resultant vector is"<<resultantvec<<"at an angle of" resultantdeg<<endl; return 0; }
Thanks a lot for the help!
Last edited by everydaybh; Apr 8th, 2009 at 11:44 pm.
•
•
Join Date: Jan 2009
Posts: 46
Reputation:
Solved Threads: 7
Other than that, in function assign , you are using local variables, which make it meaningless.
Where are the Data members?
I appreciate that you have modified complex number class to work here. This is a good example of code re-usability. But a Private inheritance in this matter would have been more eye-catching.
Well, The program has several typographical and syntactical errors.
Correct it!!.
I appreciate that you have modified complex number class to work here. This is a good example of code re-usability. But a Private inheritance in this matter would have been more eye-catching.
Well, The program has several typographical and syntactical errors.
Correct it!!.
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Agreed with all above ...
To the OP: Please remember that every C++ keyword is written in lowercase, this was introduced to keep everything simple, so actually you don't have to hesitate whether you've to enter an uppercase letter or a lowercase one, it's just always in lowercase ...
To the OP: Please remember that every C++ keyword is written in lowercase, this was introduced to keep everything simple, so actually you don't have to hesitate whether you've to enter an uppercase letter or a lowercase one, it's just always in lowercase ...
Last edited by tux4life; Apr 9th, 2009 at 5:34 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Other Threads in the C++ Forum
- Previous Thread: in over my head...pointers/variables
- Next Thread: Why Doesnt this simple Cout statement work??
Views: 433 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






