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

Revision as of 23:33, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 2002 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. Perm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  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_02.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<int> a_0(2,
 28                    9);
 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<int> a_1(4,
 38                    1);
 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);
 58
 59  vector<int> 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;
 71  cout << "a_1[2] /";
 72  cout << endl;
 73  cout << a_1[2];
 74  cout << endl;
 75
 76  cout << "a_1 :";
 77  cout << endl;
 78  cout << a_1;
 79  cout << endl;
 80
 81  vector_e<int> a_2(a_1);
 82
 83  cout << "initial values after copy construction /";
 84  cout << endl;
 85  cout << "a_2 :";
 86  cout << endl;
 87  cout << a_2;
 88  cout << endl;
 89
 90  a_2 = a_0;
 91
 92  cout << "initial values after a_2=a_0 /";
 93  cout << endl;
 94  cout << "a_2 :";
 95  cout << endl;
 96  cout << a_2;
 97  cout << endl;
 98
 99  vector_e<double> b_0(2,
100                       9.1);
101
102  cout << "initial values after construction /";
103  cout << endl;
104  cout << "b_0 :";
105  cout << endl;
106  cout << b_0;
107  cout << endl;
108
109  vector_e<double> b_1(4,
110                       1.5);
111
112  cout << "initial values after construction /";
113  cout << endl;
114  cout << "b_1 :";
115  cout << endl;
116  cout << b_1;
117  cout << endl;
118
119  n = b_1.get_size();
120
121  cout << "b_1.get_element(i) /";
122  cout << endl;
123
124  for(int i=0; i<n; i++)  
125    cout << b_1.get_element(i) << endl;
126  cout << endl;
127
128  b_1.set_element(0,
129                  6.2);
130
131  vector<double> b = b_1.get_element(0,2);
132
133  n = b.size();
134
135  cout << "b_1.get_element(0,2) /";
136  cout << endl;
137
138  for(int i=0; i<n; i++)  
139    cout << b[i] << endl;
140  cout << endl;
141
142  b_1[2] = 7.8;
143
144  cout << "b_1[2] /";
145  cout << endl;
146  cout << b_1[2];
147  cout << endl;
148
149  cout << "b_1 :";
150  cout << endl;
151  cout << b_1;
152  cout << endl;
153
154  vector_e<double> b_2(b_1);
155
156  cout << "initial values after copy construction /";
157  cout << endl;
158  cout << "b_2 :";
159  cout << endl;
160  cout << b_2;
161  cout << endl;
162
163  b_2 = b_0;
164
165  cout << "initial values after b_2=b_0 /";
166  cout << endl;
167  cout << "b_2 :";
168  cout << endl;
169  cout << b_2;
170  cout << endl;
171
172}