This is a C programming language Question Actual Program Err

This is a C++ programming language.

Question:

Actual Program:

Errors:

// Compiling this program generates a number of compiler errors. // After compiling the program, run it to confirm that it behaves according // to the following description. // This program is intended to accept two strings from the terminal // and check to see if one is a case-reversed version of the other. // That is, if corresponding characters are the opposite case. // The following commands indicate the desired operation. The Makefile // has these examples built in. / ./a.out abcDEF XYzmno // abcDEF and XYzmno have opposite case. / ./a.out abCDEF XYzmno // abCDEF XYZmno have the same case in position 2. /./a.out abCDE XYZmno . // abCDE XYZmno have different lengths

Solution

#include<iostream>
using namespace std;

int isUpper(char c)
{
return c >= 65 && c <= 91;
}

int isLower(char c)
{
return c >= 97 && c <= 122;
}

int main(int argc, char** argv)
{
char* str1 = argv[1];
char* str2 = argv[2];
size_t length = strlen(str1);
if(length != strlen(str2))
cout<< str1 << \" and \" << str2 << \" have different lengths.\" << endl;
else
{
int i = 0;
while(i < length)
{
char ch1 = str1[i];
char ch2 = str2[i];
if((isUpper(ch1) && isUpper(ch2)) ||
(isLower(ch1) && isLower(ch2)))
break;
i++;
}
if(i < length)
cout << str1 << \" and \" << str2 <<
\" have the same case in position \" << i << \".\" << endl;
else
cout << str1 << \" and \" << str2 <<
\" have opposite case.\" << endl;
}
return 0;
}

This is a C++ programming language. Question: Actual Program: Errors: // Compiling this program generates a number of compiler errors. // After compiling the pr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site