-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstl_sequence_containers_ticpp.cpp
138 lines (106 loc) · 2.57 KB
/
stl_sequence_containers_ticpp.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "stl_sequence_containers_ticpp.h"
void set_simple_int_test(){
set<int> intset;
for (int i = 0; i < 25; i++){
for (int j = 0; j < 10; j++){
intset.insert(j);
}
}
copy(intset.begin(), intset.end(), ostream_iterator<int> (cout, "\n"));
}
void set_simple_string_test(){
ifstream source("/home/dell/Downloads/DSA/cpp/text.txt");
if (source.is_open())
cout << "file is opened" << endl;
else{
cout << "file is not opened" << endl;
}
string word;
set<string> words;
while (source >> word)
words.insert(word);
copy(words.begin(), words.end(), ostream_iterator<string> (cout, "\n"));
cout << "Number of unique words:" << words.size() << endl;
}
//shape class and derived classes implementations
shape::~shape(){
cout << "virtual destructor" << endl;
}
void circle::draw(){
cout << "in circle draw function" << endl;
}
circle::~circle(){
cout <<"in circle destructor"<<endl;
}
void traingle::draw(){
cout <<"in traingle draw function" << endl;
}
traingle::~traingle(){
cout << "in traingle destructor" << endl;
}
void square::draw(){
cout << "in square draw function" << endl;
}
square::~square(){
cout <<"in square destructor" << endl;
}
void shape_classes_test(){
typedef vector<shape*> container;
typedef container::iterator itr;
container shapes;
shapes.push_back(new circle);
shapes.push_back(new traingle);
shapes.push_back(new square);
for (itr i = shapes.begin(); i != shapes.end(); i++)
(*i)->draw();
for (itr i = shapes.begin(); i!= shapes.end(); i++)
delete *i;
}
void string_container_test(){
ifstream in("/home/dell/Downloads/DSA/cpp/text.txt");
if (in.is_open())
cout<<"file is opened" << endl;
else
cout << "file is not opened" << endl;
typedef vector<string> container;
string line;
container strings;
while(getline(in, line)){
strings.push_back(line);
}
int i = 1;
container::iterator w;
for (w=strings.begin(); w!= strings.end(); w++){
ostringstream ss;
ss << i++;
*w = ss.str()+": "+*w;
}
copy(strings.begin(), strings.end(), ostream_iterator<string>(cout, "\n"));
}
long Noisy::create = 0;
long Noisy::copycons = 0;
long Noisy::assign = 0;
Noisy::Noisy():id(create++){
cout << "d[" << id << "]";
}
Noisy::Noisy(const Noisy& rv):id(rv.id){
cout << "c[" << id << "]";
copycons++;
}
Noisy& Noisy::operator=(const Noisy& rv){
cout << "(" << id << ")=[" << rv.id << "]";
id = rv.id;
assign++;
return *this;
}
/*
bool Noisy::operator<(const Noisy& lv){
return lv.id < this->id;
}*/
int main(){
set_simple_int_test();
set_simple_string_test();
shape_classes_test();
string_container_test();
return 0;
}