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

Given the declaration: char str1[ 21]; char str2[ 21]; a. Write a C++ statement

ID: 644731 • Letter: G

Question

Given the declaration:

char str1[ 21];

char str2[ 21];

a. Write a C++ statement that stores " Sunny Day" in str1.

b. Write a C++ statement that stores the length of str1 into the int variable length.

c. Write a C++ statement that copies your name into str2.

d. Write C++ code that outputs str1 if str1 is less than or equal to str2, and otherwise outputs str2.

Hint: You should to use the utility functions that comes in the <cstring> library;
unless you want to write your own C-string functions or code J

include comments to clearly show which part of code is answering which part above.

Explanation / Answer

// a. Write a C++ statement that stores " Sunny Day" in str1.
   char str1[21] = "Sunny Day";

   // b. Write a C++ statement that stores the length of str1 into the int variable length.
   int arrLength = strlen(str1);


   // c. Write a C++ statement that copies your name into str2.
   char str2[21];
   strcpy(str2, str1);


// d. Write C++ code that outputs str1 if str1 is less than or equal to str2, and otherwise outputs str2.
if (strlen(str1) <= strlen(str2))
cout << str1 << endl;
else
cout << str2 << endl;

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