Please provide full answer with comments better to understand it is just beginni
ID: 3840865 • Letter: P
Question
Please provide full answer with comments better to understand it is just beginning of c++ so please don't use advances teqniques. I will add screenshots off main.cpp,hw6.h.cpp and hw6.cpp.Download the starter code main.cpp, hw6.h, and hw6.cpp. You will only turn in hw6.cpp. Do not modify hw6.h, as you have no reason to. We have provided main.cpp to give you an idea of how we intend to use the functions. You are free to do whatever you want with main.cpp (and you'll want to make changes to it for debugging) but you won't submit it. hw6.cpp must not contain a main function. You may not use global variables. We may take off up to 20% of the total marks for poor style; make sure to name your variables reasonably, indent properly, and comment sufficiently. Submit hw6.cpp. Problem 1: (Integer power) Write the implementation of int i pow int base int exp) which returns base to the exp power. Assume exp is nonnegative. Note that 00 1. You may not use any libraries aside from cassert. Remark. If you were to use the cmath library, you could do int ipow int base int exp) return static-cast kint (pow double (base double (exp))) Remark. You could consider exp -0 an edge case. Sometimes edge cases must be handled separately with, say, an if-statement. However, you can sometimes avoid additional control structures by being mindful of how you write your loops and how you initialize your variables. Avoid additional control structures if you can.
Explanation / Answer
hw6.h
int ipow(int base,int exp);
double my_min(double *arr,int len);
double angle(double x,double y);
char *mystrcpy(char *destination,const char* str2);
int my_strcmp(const char *str1, const char *str2);
hw6.cpp
#include"hw6.h"
#include<cmath>
#include<iostream>
using namespace std;
int ipow(int base,int exp)
{
int res = 1;
while (exp)
{
res=res*base;
exp--;
}
return res;
}
double my_min(double *arr,int len)
{
double minim=9999999;
for(int k=0;k<len;k++)
{
cout<<"hh"<<endl;
if(arr[k]<minim)
minim=arr[k];
}
cout<<minim<<endl;
return minim;
}
double angle(double x,double y)
{
double res;
res=atan(y/x);
return res;
}
char *my_strcpy(char *destination, char * source)
{
int length=sizeof(source)/sizeof(char);
for(int k=0;k<length;k++)
{
destination[k]=source[k];
}
return destination;
}
int my_strcmp(const char *str1, const char *str2)
{
int length1=sizeof(str1)/sizeof(char);
int length2=sizeof(str1)/sizeof(char);
if(length1!=length2)
return 0;
int flag=0;
for(int j=0;j<length1;j++)
{
if( str1[j]!=str2[j])
return 0;
}
return 1;
}
Main.cpp
#include<iostream>
#include "hw6.h"
using namespace std;
int main()
{
int a,b;
cout<<"Input two integers: ";
cin>>a;
cin>>b;
cout<<"a^b="<<ipow(a,b)<<". ";
int n;
cout<<"Input array length";
cin>>n;
double *d_array=new double(n);
for(int i=0;i<n;i++)
{
cout<<"Input number( count "<<(i+1)<<"): ";
cin>>d_array[i];
}
cout<<"The minimum among all input is "<<my_min(d_array,n)<<". ";
//delete[] d_array;
double x,y;
cout<<"Input the x and y coordinates ";
cin>>x;
cin>>y;
cout<<"the angle x and y makes the origin is "<<angle(x,y)<<". ";
system("pause");
}
Output:
Input two integers:
2
3
a^b=8.
Input array length3
Input number( count 1):
11
Input number( count 2):
12
Input number( count 3):
13
hh
hh
hh
11
The minimum among all input is 11.
Input the x and y coordinates
12
13
the angle x and y makes the origin is 0.825377.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.