Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class res
- {
- public:
- void read_vec();
- res operator +( const res a);
- int vec[2];
- void vyvod_sum();
- };
- void res::read_vec(){
- for (int i=0; i<2; i++)
- {
- cout<<"Введите "<<i+1<<"-ю координату:" <<endl;
- cin>>vec[i];
- if(!cin.good())
- {
- cout << "Значение введено неверно."<<endl<<"Повторите ввод" << endl;
- cin.clear();
- cin.ignore();
- cin>>vec[i];
- }
- }
- };
- res res::operator+(const res a){
- res result;
- for (int i =0; i<2; i++){
- result.vec[i] = vec[i] + a.vec[i];
- }
- return result;
- };
- void res::vyvod_sum(){
- for (int i=0; i<2; i++)
- {
- cout<<vec[i]<<endl;
- }
- };
- int main(){
- setlocale(LC_ALL, "Russian");
- res A,B,C;
- cout<<"Первый двумерный вектор \n";
- A.read_vec();
- cout << "Второй двумерный вектор \n";
- B.read_vec();
- C = A + B;
- cout<<"Сумма векторов равна "<<endl;
- C.vyvod_sum();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement