

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include
answer=new vector[num+1] ; for(int i=0;i<num;i++)//this loop takes input from the user { cout<<"enter magnitude\n"; cin>>mag; operation[i].set_magnitude(mag);//this function sets value of private data member magnitude cout<<"enter angle\n"; cin>>ang; operation[i].set_angle(ang);//this function sets value of private data member angle } answer[num].set_magnitude(0);//last element of answer array should be zero which is necesary in this logic if(num==2 && operation[0].get_magnitude()==operation[1].get_magnitude() && operation[0].get_angle()==operation[1].get_angle())//if two vectors are same then their difference is zero.this caculation can not be done that's why it s printed { cout<<answer[num];//here >> is over loaded exit(1); } for(int j=num-1;j>=0;j--)//this loop subtracts last vector from second last then subtracts answer of firs subtraction from third last vector entered by the user and so on.. { answer[j]=operation[j]-answer[j+1];//here - and = are over loaded } cout<<answer[0];//answer is stored in this first member of array answer.here >> is over loaded break;//all other cases will not be performed due to this break case 3://this case performs dot product operation=new vector[2];//in this case only 2 vectors will be taken so array size is fixed float dot;//this variable will store answer of dot product for(int i=0;i<2;i++)//this loop takes input from the user { cout<<"enter magnitude\n"; cin>>mag; operation[i].set_magnitude(mag);//this function sets value of private data member magnitude cout<<"enter angle\n"; cin>>ang; operation[i].set_angle(ang);//this function sets value of private data member angle } dot=operation[0]*operation[1];//here * is overloaded cout<<dot<<endl;//here answer will be displayed break;//all other cases will not be performed due to this break case 4://this case performs cross product