Need help with 2 pointer programs, c++. 1)Write a program that initializes an ar
ID: 3760918 • Letter: N
Question
Need help with 2 pointer programs, c++.
1)Write a program that initializes an array of characters with the phrase, “Take me to Clearwater Beach!”. Using pointers, scan the array to make each character upper case. The catch: you may NOT use the isupper(), islower(), toupper(), or tolower() functions. You must calculate whether a character is upper or lower case, and use the same logic to convert to upper case where applicable.
Hints:
*cptr >= ‘a’ && *cptr <= ‘z’
Assuming the ASCII value for ‘a’ is greater than ‘A’, how could you use an expression like, (‘a’ – ‘A’) to convert to upper case?
2)Write a function that swaps the values of two integers using pointers. Assume the following function prototype:
void SwapIntegers(int *p1, int *p2);
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
char arr[] = {'T','a','k','e',' ','m','e',' ','t','o',' ','C','l','e','a','r','w','a','t','e','r',' ','B','e','a','c','h','!',''};
int temp,i=0;
while(arr[i])
{
temp = arr[i];
if(temp>=97 && temp<=122)
temp = temp-32;
arr[i] = temp;
i++;
}
cout << arr;
return 0;
}
#include<iostream>
using namespace std;
void SwapIntegers(int *p1, int *p2)
{
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main()
{
int a=5,b=7;
SwapIntegers(&a,&b);
cout << a << " " << b;
return 0;
}