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

This is a C++ programming language. YOU JUST HAVE TO RECTIFY ALL THE ERRORS FROM

ID: 3934222 • Letter: T

Question

This is a C++ programming language. YOU JUST HAVE TO RECTIFY ALL THE ERRORS FROM THE PROGRAM WHICH ARE SHOWN BELOW, DO NOT CHANGE THE WHOLE PROGRAM PLEASE.

Question:

Actual Program:

// 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

Explanation / Answer

#include <iostream>
#include <cstring>
using namespace std;

int main(int argc,char *argv[]) //changed line
{
   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) //changed line
       {
           char ch1 = str1[i];
           char ch2 = str2[i];
           if( (isupper(ch1) && isupper(ch2)) || (islower(ch1) && islower(ch2))) //changed line
               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;
}

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