Skip to content

Commit 09d6e19

Browse files
29-APR
1 parent 67eb87b commit 09d6e19

21 files changed

+615
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode/c_cpp_properties.json
2+
.vscode/launch.json
3+
.vscode/settings.json

.vscode/tasks.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build hello world",
6+
"type": "shell",
7+
"command": "g++",
8+
"args": [
9+
"${relativeFile}"
10+
],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
}
15+
}
16+
]
17+
}

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,23 @@
33
> This repo contains all the C++ programs that are made as part of Object Oriented Programming subject.
44
55
[Read More about __Standard Template Library(STL)__](https://www.geeksforgeeks.org/the-c-standard-template-library-stl/)
6+
7+
68
[Read More about __Templates__](https://www.geeksforgeeks.org/templates-cpp/)
79

810
______
11+
29-APR
12+
------
13+
##Standard tempelate library (STL)
14+
15+
1. [__Vectors__ in detail](../master/stlvector.cpp)
16+
1. [__List__ in detail](../master/stllist.cpp)
17+
1. [__Map__ in detail](../master/stlmap.cpp)
18+
1. [__Multimap__ in detail](../master/stlmultimap.cpp)
19+
1. [__Dequeue__ in detail](../master/stldequeue.cpp)
20+
1. [__Set__ in detail](../master/stlset.cpp)
21+
1. [__Multiset__ in detail](../master/stlmultiset.cpp)
22+
923
4-APR
1024
------
1125
1. [__Map__ (STL) example](../master/map.cpp)

cincout.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include<iostream>
2+
#include<cstring>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
char ch;
8+
int count=0;
9+
// do {
10+
// ch = cin.get();
11+
// cout.put(ch);
12+
// count++;
13+
// cout << "No. of char: " << count << endl;
14+
// } while(ch!='0');
15+
// cout << "Out of loop" << endl;
16+
17+
// char *str1 = "C++";
18+
// char *str2 = "Programming";
19+
// int m = strlen(str1);
20+
// int n = strlen(str2);
21+
// for(int i=1;i<=n;i++)
22+
// {
23+
// cout.write(str2,i);
24+
// cout << endl;
25+
// }
26+
// for(int i=n;i>0;i--)
27+
// {
28+
// cout.write(str2,i);
29+
// cout << endl;
30+
// }
31+
// cout.write(str1,m).write(str2,n);
32+
// cout << endl;
33+
// cout.write(str1,10);
34+
35+
int x = 155;
36+
int y = 50;
37+
38+
cout.width(5);
39+
cout << x ;
40+
cout.width(10);
41+
cout << y << endl;
42+
43+
return 0;
44+
}

map.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using namespace std;
55

66
typedef map<string, int> phonemap;
7+
typedef pair<string,int> pairing;
78
int main()
89
{
910
string name;
@@ -18,7 +19,8 @@ int main()
1819
}
1920

2021
phone["abc"] = 1111;
21-
phone.insert(pair<string,int>("Bose", 5555));
22+
phone.insert(pairing("Bose", 5555));
23+
phone["hello"] = 4343;
2224

2325
int n = phone.size();
2426
cout << n << endl;

ques14.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <vector>
3+
using namespace std;
4+
5+
template <class T>
6+
class object
7+
{
8+
vector <T> arr;
9+
public:
10+
void get(int n);
11+
void sort();
12+
void put();
13+
};
14+
15+
template <class T>
16+
void object<T>::get(int n)
17+
{
18+
T temp;
19+
for(int i=0;i<n;i++)
20+
{
21+
cin >> temp;
22+
arr.push_back(temp);
23+
}
24+
}
25+
26+
template <class T>
27+
void object<T>::sort()
28+
{
29+
int n = arr.size();
30+
T temp;
31+
for(int i=0;i<n;i++)
32+
for(int j=0;j<n-i-1;j++)
33+
if(arr[j] > arr[j+1])
34+
{
35+
temp = arr[j];
36+
arr[j] = arr[j+1];
37+
arr[j+1] = temp;
38+
}
39+
}
40+
41+
template <class T>
42+
void object<T>::put()
43+
{
44+
int n = arr.size();
45+
for(int i=0;i<n;i++)
46+
cout << arr.at(i) << endl;
47+
}
48+
49+
int main()
50+
{
51+
object<float> i;
52+
i.get(6);
53+
i.sort();
54+
i.put();
55+
56+
return 0;
57+
}

ques15.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <string>
4+
using namespace std;
5+
class person
6+
{
7+
private:
8+
string lastName;
9+
string firstName;
10+
long phoneNumber;
11+
public:
12+
person() : lastName("blank"), firstName("blank"), phoneNumber(0L)
13+
{ }
14+
person(string lname, string fname, long pho) : lastName(lname), firstName(fname), phoneNumber(pho)
15+
{ }
16+
friend bool operator<(const person&, const person&);
17+
void display()
18+
{
19+
cout << endl << lastName << "\t" << firstName
20+
<< "\tPhone: " << phoneNumber;
21+
}
22+
long get_phone() const { return phoneNumber; }
23+
};
24+
25+
bool operator < (const person& p1, const person& p2)
26+
{
27+
if(p1.lastName == p2.lastName)
28+
return (p1.firstName < p2.firstName) ? true : false;
29+
return (p1.lastName < p2.lastName) ? true : false;
30+
}
31+
32+
class comparePersons
33+
{
34+
public:
35+
bool operator() (const person* ptrP1,
36+
const person* ptrP2) const { return *ptrP1 < *ptrP2; }
37+
};
38+
int main()
39+
{
40+
multiset<person*, comparePersons> setPtrsPers;
41+
multiset<person*, comparePersons>::iterator iter;
42+
43+
person* ptrP1 = new person("DEF", "ghi", 4157300);
44+
person* ptrP2 = new person("ABC", "def", 3327563);
45+
person* ptrP3 = new person("GHI", "jkl", 8435150);
46+
person* ptrP4 = new person("JKL", "mno", 9207404);
47+
person* ptrP5 = new person("MNO", "pqr", 6946473);
48+
person* ptrP6 = new person("ABC", "abc", 8435150);
49+
setPtrsPers.insert(ptrP1);
50+
setPtrsPers.insert(ptrP2);
51+
setPtrsPers.insert(ptrP3);
52+
setPtrsPers.insert(ptrP4);
53+
setPtrsPers.insert(ptrP5);
54+
setPtrsPers.insert(ptrP6);
55+
cout << "Set sorted when created:";
56+
for(iter=setPtrsPers.begin(); iter != setPtrsPers.end(); iter++ )
57+
(**iter).display();
58+
iter = setPtrsPers.begin();
59+
while( iter != setPtrsPers.end() )
60+
{
61+
delete *iter;
62+
setPtrsPers.erase(iter++);
63+
}
64+
cout << endl;
65+
66+
return 0;
67+
}

ques16.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <list>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int main(){
7+
int n;
8+
cout << "Enter no. of elements: ";
9+
cin >> n;
10+
list<int> l;
11+
cout << "Enter the integer elements: ";
12+
int a;
13+
for (int i = 0; i < n; ++i) {
14+
cin >> a;
15+
l.push_back(a);
16+
}
17+
18+
list<int>::iterator i1 = l.begin();
19+
list<int>::iterator i2 = l.end();
20+
i2--;
21+
22+
a = 0;
23+
while (a <= n / 2)
24+
{
25+
swap(*i1, *i2);
26+
i1++;
27+
i2--;
28+
a++;
29+
}
30+
31+
for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++)
32+
cout << *itr << " ";
33+
34+
return 0;
35+
}

ques17.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include<iostream>
2+
#include<vector>
3+
#include<string>
4+
#include<list>
5+
using namespace std;
6+
7+
// class data
8+
// {
9+
// public:
10+
// string name, address, carN, carM, date;
11+
// void get()
12+
// {
13+
// cin.ignore();
14+
// getline(cin,name);
15+
// getline(cin,address);
16+
// getline(cin,carN);
17+
// getline(cin,carM);
18+
// getline(cin,date);
19+
// }
20+
// void put()
21+
// {
22+
// cout << "Name: " << name << endl;
23+
// cout << "Address: " << address << endl;
24+
// cout << "Car Name: " << carN << endl;
25+
// cout << "Car Model: " << carM << endl;
26+
// cout << "Date: " << date << endl;
27+
// }
28+
// };
29+
30+
// void sameCar(vector<data*> objs,int n)
31+
// {
32+
// cout << "Same car in same year employees: " << endl;
33+
// for(int i=0;i<n;i++)
34+
// for(int j=0;j<n;j++)
35+
// if(objs[j]->carN==objs[i]->carN && objs[i]->date==objs[j]->date && i!=j)
36+
// cout << "Name: " << objs[j]->name << endl;
37+
// }
38+
39+
// int main()
40+
// {
41+
// vector<data*> arr;
42+
// int n;
43+
// cin >> n;
44+
// for(int i=0;i<n;i++)
45+
// arr.push_back(new data);
46+
// for(int i=0;i<n;i++)
47+
// arr.at(i)->get();
48+
// for(int i=0;i<n;i++)
49+
// arr.at(i)->put();
50+
51+
// sameCar(arr,n);
52+
53+
// return 0;
54+
// }
55+
56+
class Student
57+
{
58+
public:
59+
int roll;
60+
string name;
61+
};
62+
63+
64+
int main(){
65+
66+
vector <Student> l2;
67+
68+
Student obj1,obj2;
69+
l2.push_back(obj1);
70+
l2.push_back(obj2);
71+
l2[0].roll = 1243;
72+
l2[1].roll = 243;
73+
l2[0].name = "sdhjf";
74+
l2[1].name = "sdjfkh";
75+
76+
for(int i=0;i<2;i++){
77+
cout << l2[i].roll << l2[i].name << endl;
78+
}
79+
return 0;
80+
}

ques18a.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
#include <stdlib.h>
5+
6+
using namespace std;
7+
8+
int main(){
9+
vector<int> vec;
10+
int n;
11+
cout << "Enter number of elements: ";
12+
cin >> n;
13+
for (int i = 0; i < n; ++i) {
14+
int x;
15+
cin >> x;
16+
vec.push_back(x);
17+
}
18+
19+
int first1, last1, first2;
20+
cout << "Enter first1, last1 and first2: ";
21+
cin >> first1 >> last1 >> first2;
22+
23+
if (first2 > first1 || first2 > last1){
24+
cout << "Error! Can\'t shift to the right!" << endl;
25+
exit(0);
26+
}
27+
vector<int>::iterator f1 = vec.begin() + first1;
28+
vector<int>::iterator l1 = vec.begin() + last1;
29+
vector<int>::iterator f2 = vec.begin() + first2;
30+
31+
copy(f1, l1, f2);
32+
33+
cout << "After copy()" << endl;
34+
35+
for (vector<int>::iterator itr = vec.begin(); itr != vec.end(); itr++) {
36+
cout << *itr << " ";
37+
}
38+
cout << endl;
39+
}

0 commit comments

Comments
 (0)