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

1. Write a function power that takes two parameters: x (double) and y (int), and

ID: 3709533 • Letter: 1

Question

1. Write a function power that takes two parameters: x (double) and y (int), and returns the value xy for integer y. Make sure that your function works correctly for both positive and negative values of y

2. Write a void function named CountUpper that counts the number of uppercase letters on one line of input. The function should return this number to the calling code in a parameter named upCount. Given that the Ascii code of ‘A’ is 65, and ‘Z’ is 90.

1. Write a function power that takes two parameters: x (double) and y (int), and returns the value xfor integer y. Make sure that your function works correctly for both positive and negative values of y. 2. Write a void function named CountUpper that counts the number of uppercase letters on one line of input. The function should return this number to the calling code in a

Explanation / Answer

#include <iostream>
using namespace std;
double power (double x, int y) {
double p =1;
int n;
if(y<0) {
n = -y;
}
for(int i=1;i<=n;i++) {
p = p * x;
}
if(y<0) {
return 1/p;
}
return p;
}
void CountUpper (string s, int &upCount) {
for(int i=0;i<s.length();i++) {
if(s[i]>=65 && s[i]<=90) {
upCount++;
}
}
}
int main()
{
cout<<power (5,4)<<endl;
cout<<power (5,-4)<<endl;
int upCount = 0;
string s = "hkjhkjhkhkJHkkjkKKhkhkjgk";
CountUpper(s, upCount);
cout<<upCount<<endl;
return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote