Download the starter code main.cpp, hw6.h, and hw6.cpp. You will only turn in hw
ID: 3840146 • Letter: D
Question
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.
Explanation / Answer
//hw6.cpp
#include"hw6.h"
#include<cmath>
int ipow(int base, int exp)
{
int prod = 1;
for (int i = 0; i < exp; i++)
{
prod *= base;
}
return prod;
}
double my_min(double *arr, int len)
{
double min = arr[0];
for (int i = 0; i < len; i++)
{
//min > arr[i] change min value to arr[i]
if (min > arr[i])
{
min = arr[i];
}
}
return min;
}
double angle(double x, double y)
{
const double PI = 3.14159265;
double result ,degrees;
if (x == 0 && y > 0)
return 90;
result =atan(y / x);
degrees = (result * 180) / PI;
if (x < 0)
return 180 + degrees;
if (y < 0)
return 360 + degrees;
else
return degrees;
}
char *my_strcpy(char *destination, const char * source)
{
int count = 0;
//count how many chars in source
for (int i = 0; source[i] != ''; i++)
count++;
for (int i = 0; i < count; i++)
{
destination[i] = source[i];
}
return destination;
}
//return 0 if strings are equal , 1 if str1 > str2, -1 if str1 < str2
int my_strcmp(const char *str1, const char * str2)
{
int count1 = 0 , count2 = 0;
//count how many chars in source
for (int i = 0; str2[i] != ''; i++)
count1++;
for (int i = 0; str1[i] != ''; i++)
count2++;
if (count1 > count1)
return 1;
if (count1 < count2)
return -1;
else
{
while ((*str1 == *str2) && (*str1 != ''))
{
str1++;
str2++;
}
if (*str1 > *str2)
return 1;
if (*str1 < *str2)
return -1;
return 0;
}
}
-----------------------------------------------------
//main.cpp
remains same.
-------------------------------------------
//output for the degrees same as given
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.