Professional Documents
Culture Documents
Class: BEE-14CD
Fall 2023
Lab12: STL
Instructor: Mehreen
Tahir
Section: BEE-14-C
Introduction: STLs are a software reuse. Data structures and algorithms commonly used by C++
programmers and are a part of C++ Standard Library.
Tasks:
Code
#include <iostream>
using namespace std;
int index = 0;
for (int i = 1; i < size; ++i) {
if (arr[i] != arr[index]) {
arr[++index] = arr[i];
}
}
size = index + 1;
}
int main()
{
int arr[] = { 7,7, 33, 33,44, 44, 44,56, 56 };
int size = sizeof(arr) / sizeof(arr[0]);
remove_duplicates(arr, size);
cout << endl;
cout << "List after removing consecutive duplicates: ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
return 0;
}
2. Create template function display that displays all the items of the vector.
Code
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> intVector = { 7, 8, 9, 10, 11 };
vector<double> doubleVector = { 1.1, 2.2, 3.3, 4.4, 5.5 };
vector<string> stringVector = { "Strawberry", "Pear", "Pineapple", "Grape" };
return 0;
}
3. Create a template function remove_multiples () that takes a list and a number (int) as an
argument and removes all the multiples of the number from list
Code
#include <iostream>
using namespace std;
int main() {
int intArray[] = { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 };
int numberToRemove = 2;
IMPORTANT
• You are encouraged to use good programming conventions by entering appropriate
comments, using indentations, and using descriptive variable names in your programs.
Deliverables: Complete lab manual by performing all tasks. Copy paste your code and screen
shot of console window as a solution of each task. You are required to upload the lab tasks on
LMS and the name of the task must be in this format YourFullName_reg#.