Skip to content

Commit aaee7d9

Browse files
authored
Add files via upload
1 parent ceda4cc commit aaee7d9

File tree

3 files changed

+190
-0
lines changed

3 files changed

+190
-0
lines changed

Pair.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Pair in STL c++
3+
pair<ti,t2> pair1;
4+
eg:
5+
pair<string, int>p1
6+
*/
7+
#include<iostream>
8+
using namespace std;
9+
class student{
10+
private:
11+
string name;
12+
int age;
13+
public:
14+
void setStudent(string s,int a)
15+
{
16+
name=s;
17+
age=a;
18+
}
19+
void showStudent()
20+
{
21+
cout<<"\nName : "<<name;
22+
cout<<"\nAge : "<<age;
23+
}
24+
};
25+
int main()
26+
{
27+
pair <string,int>p1;
28+
pair <string,string>p2;
29+
pair <string,float>p3;
30+
pair <int,student>p4; // class student
31+
// to insert a value in pair
32+
p1=make_pair("Priyanshu",16);
33+
p2=make_pair("India","New delhi");
34+
p3=make_pair("Drilling C++",345.5f);
35+
student ob;
36+
ob.setStudent("Priyanshu",20);
37+
p4=make_pair(1,ob);
38+
//cout<<p1.first ; to print first element
39+
//cout<<p1.second; to print second element
40+
cout<<"Pair 1 : "<<p1.first<<" "<<p1.second;
41+
cout<<"\nPair 2 : "<<p2.first<<" "<<p2.second;
42+
cout<<"\nPair 3 : "<<p3.first<<" "<<p3.second;
43+
cout<<"\nPair 4 : "<<p4.first<<" ";
44+
student ob1=p4.second;
45+
ob1.showStudent();
46+
47+
48+
}
49+

Tuple.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Tuple in c++
3+
tuple<t1,t2,t3> tuple1;
4+
tuple<string,int,int>t1;
5+
you need to include tuple
6+
*/
7+
#include<iostream>
8+
#include<tuple>
9+
using namespace std;
10+
int main()
11+
{
12+
tuple <string,int,int>t1;
13+
// to insert value call make_tuple
14+
t1=make_tuple("Priyanshu",20,56);
15+
cout<<"Name "<<" "<<"Age"<<" "<<"Marks "<<endl;
16+
cout<<get<0>(t1)<<" "<<get<1>(t1)<<" "<<get<2>(t1); // angular bracket show it position
17+
18+
}
19+

Vector.cpp

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
Vector in c++
3+
Vector is a type of container
4+
It is used when we don't know how much data we enter we
5+
don't know it support dynamic array(means have some capacity)
6+
Vecotor increase it size according to it requirement
7+
it increase the size according to multiply with 2
8+
means if two value inserted and inserting third will increment according to 4
9+
you need to include a vector
10+
to create a blank vecotr use this command
11+
vector <int>v1;
12+
*/
13+
#include<iostream>
14+
#include<vector>
15+
using namespace std;
16+
int main()
17+
{
18+
// vector <int>v1;
19+
// to initile it to the point use this command
20+
vector <int>v1 { 10,20,30};
21+
// while declaring initilization capacity will be 3
22+
// it will not follow by default value 1
23+
// now it will increment 3 than 6 so on
24+
// to initilize it size
25+
26+
vector <char> v2(5);
27+
28+
// to initilize the value and also size
29+
// here 5 is the size and 10 is the value
30+
31+
vector <int> v3(5,10);
32+
vector <string> v4(3,"hello");
33+
vector <int> v5;
34+
35+
// square bracket
36+
37+
cout<<v4[0]<<" "<<v4[1]<<" "<<v4[2]<<"\n";
38+
39+
// loop
40+
41+
for(int i=0;i<4;i++)
42+
{
43+
cout<<v1[i]<<" ";
44+
}
45+
cout<<endl;
46+
47+
// push_back to insert a value
48+
49+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
50+
// v5.push_back(10);
51+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
52+
// v5.push_back(20);
53+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
54+
// v5.push_back(30);
55+
56+
// // you can see here capacity increase by multiple of 2
57+
58+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
59+
// v5.push_back(30);
60+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
61+
62+
// by loop
63+
64+
cout<<"Current Capacity : "<<v5.capacity()<<"\n";
65+
for(int i=0;i<=9;i++)
66+
{
67+
v5.push_back(10*(i+1));
68+
}
69+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
70+
// cout<<"Size : "<<v5.size()<<"\n";
71+
72+
// // pop_back to delete last value
73+
74+
// v1.pop_back();
75+
// cout<<"After pop : "<<endl;
76+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
77+
// cout<<"Size : "<<v5.size()<<"\n";
78+
79+
// // size return number of element
80+
81+
// v1.pop_back();
82+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
83+
// v1.pop_back();
84+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
85+
// v1.pop_back();
86+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
87+
// v1.pop_back();
88+
// cout<<"Current Capacity : "<<v5.capacity()<<"\n";
89+
// cout<<"Size : "<<v5.size()<<"\n";
90+
91+
// to print
92+
93+
for(int i=0;i<v5.size();i++)
94+
{
95+
cout<<v5[i]<<" ";
96+
}
97+
cout<<endl;
98+
99+
// to clear
100+
101+
//v5.clear();
102+
//cout<<"Current Capacity : "<<v5.capacity()<<"\n";
103+
//cout<<"Total element : "<<v5.size()<<endl;
104+
105+
// at to return index
106+
cout<<"Value at index 4 is : "<<v5.at(4)<<endl;
107+
108+
// front and back
109+
110+
cout<<"First value is : "<<v5.front()<<"\n";
111+
cout<<"Last value is : "<<v5.back()<<"\n";
112+
113+
// to insert a value at mid use iterator
114+
115+
vector <int>:: iterator it=v5.begin();
116+
v5.insert(it+3,35); // here it is beggining position +2 show 3 rd position ,35 is value we insert
117+
for(int i=0;i<v5.size();i++)
118+
{
119+
cout<<v5[i]<<" ";
120+
}
121+
cout<<endl;
122+
}

0 commit comments

Comments
 (0)