Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: This assignment is a grab bag of practice problems with an emphasis o

ID: 3852019 • 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 your

Explanation / Answer

#include<iostream>
using namespace std;
#include<vector>
#include<limits.h>
#include<stdlib.h>
#include<math.h>

int maxInt(vector<int> v)
{
int mx=0,i;
int s=v.size();
for(i=0;i<s;i++)
{
if(v[i]>mx)mx=v[i];
}
return mx;
}
int minInt(vector<int> v)
{
int mn=INT_MAX,i;
int s=v.size();
for(i=0;i<s;i++)
{
if(v[i]<mn)mn=v[i];
}
return mn;
}

bool containsDups(vector<int> v)
{
int i,j;
int s=v.size();
for(i=0;i<s-1;i++)
{
for(j=i+1;j<s;j++)
{
if(v[i]==v[j])return true;
}
}
return false;
}

bool isSorted(vector<int> v)
{
int i;
int s=v.size();
for(i=1;i<s;i++)
{
if(v[i]<v[i-1])
return false;
}
return true;
}

void histogram(vector<int> v)
{
int mx=maxInt(v);
int i,j;
int s=v.size();
for(i=0;i<s;i++)
{
cout<<v[i]<<" - ";
int k=100*v[i];
int a=round((float)((float)k/(float)mx));
for(j=0;j<a;j++)
cout<<"*";
cout<<endl;
}
}

double degreesToRadians(double k)
{
int r,i;
int d=k;
if(d>=360)
{
d=d%360;
//cout<<d;
}
else if(d<=-360)
{
d=-1*d;
d=d%360;
d=-1*d;
}
r=(double)((double)((double)6.28*(double)d)/(double)360);
return r;
}

struct coordinate
{
double x;
double y;
};

double slope(coordinate p,coordinate q)
{
double d=(p.y-q.y)/(p.x-q.x);
return d;
}
double intercept(coordinate p,coordinate q)
{
double m=slope(p,q);
double b=p.y-m*p.x;
return b;
}
void rectangle(coordinate p,coordinate q)
{
int width=abs(p.x-q.x);
int height=abs(p.y-q.y);
int area=height*width;
cout<<"width = "<<width<<endl;
cout<<"height = "<<height<<endl;
cout<<"area = "<<area<<endl;
}

int main()
{
vector<int> vec;
vec.push_back(1);
vec.push_back(67);
vec.push_back(23);
vec.push_back(34);
vec.push_back(100);
cout<<minInt(vec)<<endl;
cout<<maxInt(vec)<<endl;
cout<<containsDups(vec)<<endl;
cout<<isSorted(vec)<<endl;
histogram(vec);
coordinate p,q;
p.x=0;p.y=0;q.x=5;q.y=5;
cout<<slope(p,q)<<endl;
cout<<intercept(p,q)<<endl;
rectangle(p,q);
return 1;
}