Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication6.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <fstream>
- #include <vector>
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <functional>
- using namespace std;
- void show(double x);
- double fn01(double x);
- double fn02(double x);
- int _tmain(int argc, _TCHAR* argv[])
- {
- vector <double> *vect_a;
- vector <double>::iterator p;
- ifstream ifs("numbers.txt");
- int n;
- if (ifs.bad())
- {
- cerr << "File open error";
- }
- ifs >> n;
- vect_a = new vector<double>(n);
- p = vect_a->begin();
- while (!ifs.eof())
- {
- double x;
- ifs >> x;
- *p = x;
- p++;
- }
- for_each(vect_a->begin(), vect_a->end(), show);
- p = find_if(vect_a->begin(), vect_a->end(), bind2nd(less<double>(), -3));
- if (p == vect_a->end())
- {
- // не знайшли
- // в іншому випадку помножити всі члени на 0,1
- transform(vect_a->begin(), vect_a->end(), vect_a->begin(), fn02);
- }
- else
- {
- //всі від’ємні члени замінити їх квадратами, залишивши решту членів без змін
- transform(vect_a->begin(), vect_a->end(), vect_a->begin(), fn01);
- }
- for_each(vect_a->begin(), vect_a->end(), show);
- return 0;
- }
- void show(double x)
- {
- cout << setw(8) << x << endl;
- }
- double fn01(double x)
- {
- if (x < 0)
- return x*x;
- else
- return x;
- }
- double fn02(double x)
- {
- return 0.1*x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement