Objective: This assignment is a grab bag of practice problems with an emphasis o
ID: 3852108 • Letter: O
Question
Objective: This assignment is a grab bag of practice problems with an emphasis on strings, vectors, and File Input/Output and more practice with functions. Specification: Write functions to perform the indicated task. Most of the functions are short and can be written in a handful of lines. Each function should use the most optimal solution. Please test your functions within main). Leave all your test code active in main) so it can be reviewed in a hanful of lines. Each function should use the most optimal solution. Please test yourExplanation / Answer
#include <iostream>
#include <vector>
using namespace std;
int maxInt(vector<int> &v)
{
int size = v.size();
int max = v[0];
for (int i = 0; i < size; i++)
{
if (v[i] > max)
{
max = v[i];
}
}
return max;
}
int minInt(vector<int> &v)
{
int size = v.size();
int min = v[0];
for (int i = 0; i < size; i++)
{
if (v[i] < min)
{
min = v[i];
}
}
return min;
}
int containsDups(vector<int> &v)
{
int size = v.size();
for (int i = 0; i < size; i++)
{
int element = v[i];
for (int j = 0; i < size; i++)
{
if (element == v[j] && i != j)
{
return true;
}
}
}
return false;
}
int isSorted(vector<int> &v)
{
int size = v.size();
for (int i = 1; i < size; i++)
{
if (v[i] < v[i-1])
{
return false;
}
}
return true;
}
int main()
{
vector<int> v;
v.push_back(5);
v.push_back(15);
v.push_back(25);
v.push_back(35);
v.push_back(45);
v.push_back(55);
v.push_back(55);
int max = maxInt(v);
int min = minInt(v);
cout << "The maximum value is " << max << endl;
cout << "the minimum value is " << min << endl;
if (containsDups(v) == true)
{
cout << "There are duplicates in this vector" << endl;
}
else
{
cout << "There are no duplicates in this vector" << endl;
}
if (isSorted(v) == true)
{
cout << "The vector is sorted in proper order." << endl;
}
else
{
cout << "The vector is not sorted in proper order." << endl;
}
return 0;
}
OUTPUT:
The maximum value is 55
the minimum value is 5
There are duplicates in this vector
The vector is sorted in proper order.
Please ask rest in another post. Thank you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.