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

. Given the following declarations: char s1[15]; char s2[15] = \"Good Day!\"; Wr

ID: 3627918 • Letter: #

Question

. Given the following declarations:

char s1[15];
char s2[15] = "Good Day!";

Write C++ statements to do the following. Note: No loops allowed!

a. Copy s2 to s1.

b. Check if s1 and s2 contain the same string and output a message if they are equal.

c. If s1 is less than s2, output s1. Otherwise output s2.

d. Store the string "Sunny Day" into s1.

e. Store the length of s2 into an int variable named length.


Given the following declarations:
char name[21] = "Bob";
char yourName[21] = "Joe";
char studentName[31] = "Joe Bob";

Mark each of the following as valid or invalid. If invalid, explain why.

a. cin >> name;

b. cout << studentName;

c. yourName[0] = '';

d. yourName = studentName;

e. if (yourName == name)
studentName = name;

f. int x = strcmp(yourName, studentName);

g. strcpy(studentName, name);

Explanation / Answer

please rate - thanks

char s1[15];
char s2[15] = "Good Day!";

Write C++ statements to do the following. Note: No loops allowed!

a. Copy s2 to s1.                 strcpy(s1,s2);

b. Check if s1 and s2 contain the same string and output a message if they are equal.

if(strcmp(s1,s2)==0)
    cout<<"s1 and s2 are the same";


c. If s1 is less than s2, output s1. Otherwise output s2.

if(strcmp(s1,s2)<0)
    cout<<"s1 < s2";
else
    cout<<s2;

d. Store the string "Sunny Day" into s1.         char s1[15]="Sunny Day";

e. Store the length of s2 into an int variable named length.    int len=strlen(s2);


Given the following declarations:
char name[21] = "Bob";
char yourName[21] = "Joe";
char studentName[31] = "Joe Bob";

Mark each of the following as valid or invalid. If invalid, explain why.

a. cin >> name;          valid

b. cout << studentName;            valid

c. yourName[0] = '';                   valid

d. yourName = studentName;             invalid string are different sizes

e. if (yourName == name)                          invalid string are different sizes
studentName = name;

f. int x = strcmp(yourName, studentName);              valid

g. strcpy(studentName, name);                             valid