Yurttas/PL/OOL/Cplusplus/F/04/03/00/vector e 01.cpp

From ZCubes Wiki
Jump to navigation Jump to search
  1/*
  2   Copyright(C) 2002
  3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4
  5   Permission to use, copy, modify, and distribute this
  6   software and its documentation for EDUCATIONAL purposes
  7   and without fee is hereby granted provided that this
  8   copyright notice appears in all copies.
  9
 10   date   : June 1, 2002.
 11   author : Salih Yurttas.
 12
 13   vector_e_01.cpp
 14*/
 15
 16
 17#include <iostream>
 18
 19#include <vector>
 20
 21using namespace std;
 22
 23#include "vector_e.cpp"
 24
 25int main(int argc, char* argv[]) {
 26
 27  vector_e<double> a_0(2,
 28                       9.1);
 29
 30  cout << "initial values after construction /";
 31  cout << endl;
 32  cout << "a_0 :";
 33  cout << endl;
 34  cout << a_0;
 35  cout << endl;
 36
 37  vector_e<double> a_1(4,
 38                       1.5);
 39
 40  cout << "initial values after construction /";
 41  cout << endl;
 42  cout << "a_1 :";
 43  cout << endl;
 44  cout << a_1;
 45  cout << endl;
 46
 47  int n = a_1.get_size();
 48
 49  cout << "a_1.get_element(i) /";
 50  cout << endl;
 51
 52  for(int i=0; i<n; i++)  
 53    cout << a_1.get_element(i) << endl;
 54  cout << endl;
 55
 56  a_1.set_element(0,
 57                  6.2);
 58
 59  vector<double> a = a_1.get_element(0,2);
 60
 61  n = a.size();
 62
 63  cout << "a_1.get_element(0,2) /";
 64  cout << endl;
 65
 66  for(int i=0; i<n; i++)  
 67    cout << a[i] << endl;
 68  cout << endl;
 69
 70  a_1[2] = 7.8;
 71
 72  cout << "a_1[2] /";
 73  cout << endl;
 74  cout << a_1[2];
 75  cout << endl;
 76
 77  cout << "a_1 :";
 78  cout << endl;
 79  cout << a_1;
 80  cout << endl;
 81
 82  vector_e<double> a_2(a_1);
 83
 84  cout << "initial values after copy construction /";
 85  cout << endl;
 86  cout << "a_2 :";
 87  cout << endl;
 88  cout << a_2;
 89  cout << endl;
 90
 91  a_2 = a_0;
 92
 93  cout << "initial values after a_2=a_0 /";
 94  cout << endl;
 95  cout << "a_2 :";
 96  cout << endl;
 97  cout << a_2;
 98  cout << endl;
 99
100}