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

ATTENTION!!!: This assignment is for a basic and introductory C++ course. As suc

ID: 3836535 • Letter: A

Question

ATTENTION!!!: This assignment is for a basic and introductory C++ course. As such, please do not use complex or obscure opperations and headers that would typically be used in advanced classes as we have not learned them yet. Use only very simple functions and headers. If you are unsure of whether a technique is too advanced, dont use it. If you can answer the question without using a function, please do so.

"C type" string is implied to mean an array of characters with an end of string mark following the last character.

Write a function with three arguments (the first two arguments are “C type” strings). The function will return a Boolean, true if the two strings are identical using a case sensitive comparison, false otherwise. The third argument is a reference to a boolen which is set to true if the two strings are the same using a case insensitive comparison, false otherwise.

Explanation / Answer

#include <iostream>
#include <cstring>
using namespace std;
bool getCompareResult(char a[], char b[], bool flag){
int i = 0;
if(strlen(a) != strlen(b)) {
return false;
}
while(a[i]!=''){
if(flag) {
if(toupper(a[i]) != toupper(b[i])) {
return false;
}
}
else{
if(a[i] != b[i]) {
return false;
}   
}
i++;
}
return true;
}
int main()
{
char a[] = "abcbdebdcbsbabc";
char b[] = "aBcbdebdcbsbabc";
cout<<getCompareResult(a,b,false)<<endl;;
cout<<getCompareResult(a,b,true)<<endl;;
return 0;
}

Output:

sh-4.2$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                                                                   

sh-4.2$ main                                                                                                                                                                                                                                                           

0                                                                                                                                                                                                                                                                      

1

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