
Добавил:
FuwaFuwa
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:2.4 / main
.cpp#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
class vector
{
public:
double xx;
double yy;
vector() { xx=yy=0; }
vector(double x, double y)
{
xx=x; yy=y;
}
vector operator+=(const vector &op2)
{
xx=xx+op2.xx;
yy=yy+op2.yy;
vector s(xx, yy);
return s;
}
friend vector operator+(const vector &op1, const vector &op2);
friend vector operator-(const vector &op1, const vector &op2);
friend istream &operator>>(istream &in, vector &A);
friend ostream &operator<<(ostream &out, vector &A);
};
vector operator+(const vector &op1, const vector &op2)
{
vector s;
s.xx=op1.xx + op2.xx;
s.yy=op1.yy + op2.yy;
return s;
}
vector operator+(const vector &op1, const int &op2)
{
vector s;
s.xx=op1.xx + op2;
s.yy=op1.yy + 0;
return s;
}
vector operator*(const vector &op1, const vector &op2)
{
vector s;
s.xx=op1.xx*op2.xx + op1.yy*op2.yy;
s.yy=0;
return s;
}
istream &operator>>(istream &in, vector &A)
{
cout <<"\nВведите х ->";
in >> A.xx;
cout <<"\nВведите у ->";
in >> A.yy;
return in;
}
ostream& operator<<(ostream &out, vector &A)
{
out << A.xx << " ; " << A.yy ;
return out;
}
////////////////////////////////////////////////////////////////
int main(int argc, char** argv) {
//.............................................
int choice=0;
vector v1, v2, v3;
double a;
setlocale(0,"");
while(1)
{
cout<<"\n\n1. Enter number\n2. Out number \n3. Sum 2 Vect \n4. Mul 2 vect \n5. Exit";
choice=getch();
switch(choice)
{
case '1':
cout<<"\nEnter-> ";
cin>>v1;
break;
case '2':
cout<<"\nC="<<v1;
break;
case '3':
{
cout<<"\nEnter v1-> ";
cin>>v1;
cout<<"\nEnter v2-> ";
cin>>v2;
v3=v1+v2;
cout<<"\nv1+v2 = " << v3;
break;}
case '4':
{
cout<<"\nEnter v1-> ";
cin>>v1;
cout<<"\nEnter v2-> ";
cin>>v2;
v3=v1*v2;
cout<<"\nv1*v2 = " << v3;
break;}
default:
goto mEnd;
break;
} // end swtch
}// end while
mEnd:
return 0;
}