Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class vektor {
- int n;
- float *x;
- public:
- vektor () {
- cout<<"Default object."<<endl;
- }
- vektor (vektor & src) {
- cout<<"Copied object:"<<endl;
- n = src.n;
- x = new float[n];
- int i;
- for (i = 0; i < n; i++) {
- x[i] = src.x[i];
- }
- }
- void input(int n, string s) {
- int i;
- x = new float[n];
- cout<<"Enter new elements of the array "<<s<<":"<<endl;
- for (i = 0; i < n; i++) {
- cin>>x[i];
- }
- }
- void set (int number) {
- n = number;
- }
- float maximum () {
- int i;
- float max = x[0];
- for (i = 1; i < n; i++) {
- if (x[i] > max) {
- max = x[i];
- }
- }
- return max;
- }
- void output(string s);
- };
- void vektor::output(string s) {
- int i;
- cout<<n<<endl;
- cout<<"Array "<<s<<":"<<endl;
- for (i = 0; i < n; i++) {
- cout<<x[i]<<" ";
- }
- }
- int main () {
- vektor vec1;
- int n;
- cout<<"Enter the amount of elements of the array: ";
- cin>>n;
- vec1.input(n, "vec1");
- vec1.set(n);
- cout<<"The maximal element of the array in vektor vec1 is equal to "<<vec1.maximum()<<"."<<endl;
- vektor vec2(vec1);
- vec2.output("vec2");
- return 0;
- }
Add Comment
Please, Sign In to add comment