Answer to Question #257208 in C++ for george

Question #257208

Write a program to create a dynamic array of user defined size. Array should be of character type. Write a function ChangeCase() that should convert all the small alphabets to capital and vice versa. All array operations should be done using pointers


1
Expert's answer
2021-10-27T00:26:00-0400
#include<iostream>
using namespace std;
void ChangeCase(char str[], int n)
{
    
 
    
    for (int i = 0; i < n; i++) {
        if (str[i] >= 'a' && str[i] <= 'z')
            
            str[i] = str[i] - 32;
        else if (str[i] >= 'A' && str[i] <= 'Z')
            
            str[i] = str[i] + 32;
    }
}


int main(){
	cout<<"Enter the size of the array:\n";
	int n;
	cin>>n;
	char letters[n];
	cout<<"Enter the string\n";
	cin>>letters;
	ChangeCase(letters,n);
	cout<<letters<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS