Vector Addition Using OOP?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 1
Reputation: everydaybh is an unknown quantity at this point 
Solved Threads: 0
everydaybh everydaybh is offline Offline
Newbie Poster

Vector Addition Using OOP?

 
0
  #1
Apr 8th, 2009
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):
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. // A class declaration for class Complex
  6. // This class creates complex number objects z = x + i*y,
  7. // where x is the real and y the imaginary part
  8. class Vector
  9. {
  10.  
  11. Public:
  12. Vector();
  13. void assign (double x, double y);
  14. void convert (double x, double y);
  15. Vector modulus();
  16. Vector operator+(const Vector &z);
  17. Vector operator-(double xsize, double ysize);
  18.  
  19. void Vector::assign(double x, double y){
  20. double size = x;
  21. double degree = y;
  22. }
  23. void Vector::convert(double x, double y){
  24. double xsize = size*cos(degree/180.0);
  25. double ysize = size*sin(degree/180.0);
  26. }
  27.  
  28.  
  29.  
  30. Vector Vector::operator(const Vector &z){
  31. Vector temp;
  32. Vector xsize=(*this).xsize+z.xsize;
  33. Vector ysize=(*this).ysize+z.ysize;
  34. return Temp;
  35. )
  36.  
  37. Vector Vector::modulus(){
  38. resultantvec= sqrt(xsize*xsize + ysize*ysize);
  39. return resultantvec;
  40. }
  41.  
  42. Vector Vector::operator-(double xsize, double ysize){
  43. resultantrad=atan2(ysize/xsize);
  44. resultantdeg=resultantrad*180;
  45. return resultantdeg;
  46. }
  47.  
  48.  
  49. //Below, the main()
  50. int main(){
  51.  
  52. Vector num1;
  53. Vector num2;
  54.  
  55. num1.assign(1,60);
  56. num2.assign(2,50);
  57.  
  58. cout<<"the resultant vector is"<<resultantvec<<"at an angle of" resultantdeg<<endl;
  59. return 0;
  60. }

Thanks a lot for the help!
Last edited by everydaybh; Apr 8th, 2009 at 11:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Vector Addition Using OOP?

 
0
  #2
Apr 9th, 2009
Your program has too many errors to enumerate. You need to learn the basics (like you can't say Public instead of public; capitalization counts). Get a decent book and work through the examples.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 46
Reputation: kbshibukumar is an unknown quantity at this point 
Solved Threads: 7
kbshibukumar kbshibukumar is offline Offline
Light Poster

Re: Vector Addition Using OOP?

 
0
  #3
Apr 9th, 2009
Other than that, in function assign , you are using local variables, which make it meaningless.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Vector Addition Using OOP?

 
0
  #4
Apr 9th, 2009
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!!.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Vector Addition Using OOP?

 
0
  #5
Apr 9th, 2009
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 ...
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."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC