-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalvect.cpp
More file actions
40 lines (36 loc) · 885 Bytes
/
Copy pathvalvect.cpp
File metadata and controls
40 lines (36 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Created by 赵健 on 2021/8/17.
//
#include "valvect.h"
#include <iostream>
#include <valarray>
#include <vector>
#include <algorithm>
void valvect::test() {
using namespace std;
vector<double> data;
double temp;
cout << "Enter numbers (<=0 to quit):\n";
while (cin >> temp && temp > 0) {
data.push_back(temp);
}
sort(data.begin(), data.end());
int size = data.size();
valarray<double> numbers(size);
int i;
for (i = 0; i < size; i++) {
numbers[i] = data[i];
}
valarray<double> sq_rts(size);
sq_rts = sqrt(numbers);
valarray<double> results(size);
results = numbers + 2.0 * sq_rts;
cout.setf(ios_base::fixed);
for (i = 0; i < size; i++) {
cout.width(8);
cout << numbers[i] << ": ";
cout.width(8);
cout << results[i] << endl;
}
cout << "done\n";
}