DeVry COMP 122 Week 7 Homework Latest

$25

Description

DeVry COMP 122 Week 7 Homework Latest

Week 7 Homework

Part 1: Complete the following problems.

  1. 1.Answer the questions that follow given these lines of code.

string str1, str2;

cin >> str1 >> str2;

if(str1 == str2)

{

cout << str1 << ” == ” << str2 << endl;

}

else if (str1 > str2)

{

cout << str1 << ” > ” << str2 << endl;

}

else

{

cout << str1 << ” < ” str2 << endl;

}

  1. a.What do these lines output if the input is “diamond diamond”?
  2. b.What do these lines output if the input is “diamond gold”?
  3. c.What do these lines output if the input is “silver gold”?
  4. 2.What is the output of the following program fragment?

string s1 = “Ball Park”;

string s2 = “Going to”;

string s3 = “the”;

string str;

cout << s2 << ” ” << s3 << ” ” << s1 << endl;

cout << s1.length() << endl;

cout << s1.find(‘P’) << endl;

cout << s1.substr(0, 4) << endl;

str = “abcdefghijk”;

cout << str << endl;

cout << str.length() << endl;

str[0] = ‘A’;

str[3] = ‘D’;

cout << str << endl;

  1. 3.What is output from each of the following statements? Assume each statement is independent of all the others.

string str = “Now is the time for the party!”;

  1. a.cout << str.size() << endl;
  2. b.cout << str.substr(7, 8) << endl;
  3. c.cout << str.insert(11, “best “) << endl;
  4. d.str.erase(16, 14);

str.insert(16, “to study for the exam!”);

cout << str << endl;

Part 2: Complete the following problems.

  1. 4.Given the following declaration: char str[16];

mark the following statements as valid or invalid and if invalid, explain why.

  1. a.strcpy(str, “Hello there”);
  2. b.strlen(str);
  3. c.str = “Jacksonville”;
  4. d.cin >> str;
  5. e.cout << str;
  6. f.if ( str >= “Nice guy”)

cout << str;

  1. g.str[6] = ‘t’;
  2. 5.Given the following declarations:

char s1[15];

char s2[15] = “Good Day!”;

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

  1. a.Copy s2 to s1.
  2. b.Check if s1 and s2 contain the same string and output a message if they are equal.
  3. c.If s1 is less than s2, output s1.Otherwise output s2.
  4. d.Store the string “Sunny Day” into s1.
  5. e.Store the length of s2 into an int variable named length.
  6. 6.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.

  1. a.cin >> name;
  2. b.cout << studentName;
  3. c.yourName[0] = ‘’;
  4. d.yourName = studentName;
  5. e.if (yourName == name)

studentName = name;

  1. f.int x = strcmp(yourName, studentName);
  2. g.strcpy(studentName, name);

DeVry Courses helps in providing the best essay writing service. If you need 100% original papers for DeVry COMP 122 Week 7 Homework Latest, then contact us through call or live chat.

DeVry COMP 122 Week 7 Homework Latest

Best DeVry COMP 122 Week 7 Homework Latest
DeVry COMP 122 Week 7 Homework Latest

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Add to cart