Chat with us, powered by LiveChat devry comp122 week 7 homework | Writedemy

devry comp122 week 7 homework

devry comp122 week 7 homework

Question

COMP122

Week 7 Homework

Part 1: Complete the following problems.

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;

}

a. What do these lines output if the input is “diamond diamond”?

b. What do these lines output if the input is “diamond gold”?

c. What do these lines output if the input is “silver gold”?

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;

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!”;

a. cout << str.size() << endl;

b. cout << str.substr(7, 8) << endl;

c. cout << str.insert(11, “best “) << endl;

d. str.erase(16, 14);

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

cout << str << endl;

Part 2: Complete the following problems.

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

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

a. strcpy(str, “Hello there”);

b. strlen(str);

c. str = “Jacksonville”;

d. cin >> str;

e. cout << str;

f. if ( str >= “Nice guy”)

cout << str;

g. str[6] = ‘t’;

5. 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.

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.

a. cin >> name;

b. cout << studentName;

c. yourName[0] = ‘\0’;

d. yourName = studentName;

e. if (yourName == name)

studentName = name;

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

g. strcpy(studentName, name);

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order