Question

In: Computer Science

Please answer the following questions 1) Suppose the user inputs “Good Morning!” in the console when...

Please answer the following questions

1) Suppose the user inputs “Good Morning!” in the console when running the following code.

What will be printed to the console?

char word[100] ;

cout << “Type a word: “;

cin >> word;

cout << word << endl;

2) What is the value of myStr[5] after the following code?

char myStr[100] = “Good!”;

3) Suppose we have a string variable that contains a string with a length of N, what is the index of

the third to the last character in this string?

4) Please fill the two inputs to the substr function so that it will print “morning” to the console.

string myStr = “Good morning Friday!”;

cout<<myStr.substr( ___, ___ )<<endl;

5) I am trying to initialize a c-style string to “chen”. What is the problem of the following code?

char myStr[5] = {‘c’, ‘h’, ‘e’, ‘n’ };

cout<<myStr;

Solutions

Expert Solution

1) When you are using the above code only the first word "Good" will be printed. Cause the cin method will read the letters untill it find a white space(cause char is used as the type). You can view the following images for clarification;

OUTPUT ( when using whitespace):

OUTPUT (without whitespace):

2.The value of mystr[5] will be empty. Cause the string index starting with 0. Hence, there is nothing in the index value 5 in the given string. View the code for the clarity;

OUTPUT:

3. Since the string index ranges from 0 to N-1 if N is the total length of the string. therefor the index of the third to the last character in this string: [2, N-1]

4.myStr.substr(4,9) can be used to print "morning" on screen. See the below code;

OUTPUT:

5.I think there is no problem with the code except you used the quatation style (‘c’) which is not permitted in C++ try using normal ('c'). See the code below;

OUTPUT:


Related Solutions

In Java please. Prompt the user for two string inputs. Perform the following actions on these...
In Java please. Prompt the user for two string inputs. Perform the following actions on these inputs, and print the result of each action: Part I: Concatenate the two strings into one. Compare the two strings and check whether they are the same (ignore the case). Look up the method equalsIgnoreCase() from Java API Convert all the characters in a string to uppercase Look up the method toUpperCase() from Java API Part II: Replace all the 'd' characters with ‘e'...
In reference to Nintendo as a competitor in the game console category please answer the following...
In reference to Nintendo as a competitor in the game console category please answer the following quesitons: What is the company strategy used today? What is the companys business model? What is the distinctive attribute of the company ?
Please answer ALL of the following questions! 1. Suppose China is rich in unskilled labor relatively...
Please answer ALL of the following questions! 1. Suppose China is rich in unskilled labor relatively to Japan. Then, according to the Heckscher=Ohlin model, China tends to export (a. high-tech goods/ b. low-tech goods) to Japan and a trade with China benefits (a. unskilled labor/ b. skilled labor/ c. capital owner) of Japan. 2. Wage rates across countries tend (a. to be equalized only if/ b. to be equalized whether or not) trade barriers and technology gaps are absent. When...
Please answer the following questions(true/false) 1. When Barack Obama was sworn in as the president of...
Please answer the following questions(true/false) 1. When Barack Obama was sworn in as the president of the United States, he inherited a situation that had confounded his predecessors for half a century. America's complex relationship with Cuba illustrates the impact the political, legal, and regulatory environments can have on international trade and global marketing activities 2. Bribery payments are considered a deductible business expense in many European countries 3. Globalization is presenting significant marketing opportunities for professional sports organizations such...
Assume user will enter letters or numbers that are out of range. When user inputs invalid...
Assume user will enter letters or numbers that are out of range. When user inputs invalid values, show an alert message and ask user to enter a valid value again. Validate first and then proceed with the program. isNaN() method may be useful. Must validate user input. 1. Suggested Filename: fortune.html & fortune.js Write a program that simulates a fortune cookie. The program should display one of five unique fortunes, depending on user input. The user must enter a number...
Please answer the following questions: 1) What's make good supervisor? 2) How do you go about...
Please answer the following questions: 1) What's make good supervisor? 2) How do you go about solving conflict between team members? 3) How do you encourage your team as a supervision? 4) How do you go about dealing with bad employees?
Part 1- Capital Budgeting Questions Please use the following information to answer questions 1- 6 (PLEASE...
Part 1- Capital Budgeting Questions Please use the following information to answer questions 1- 6 (PLEASE SHOW CALCULATIONS) Bob makes wooden tables and is creating his 2017 capital budget. He expects to sell 40 tables in 2017 at $150 per table. Additional Information for 2017: DM per table: 6 board feet (b.f.) per table at $2.00 per b.f. DL per table: 2 DLH per table at $25 per DLH O/H is applied at a rate of $4 per DLH (and...
Please give genus and species for each answer. 51. When you left for work this morning...
Please give genus and species for each answer. 51. When you left for work this morning your 3-month old daughter was wheezing a bit and she had a slight fever of 99.8 F. Your mother is watching her while you work. Your cell phone rings, the baby&#39;s fever is rising and she is having difficulty breathing. Your mom is taking her to the hospital. When you get to the hospital the doctor is signing papers to admit the baby into...
Answer the Following Three Questions Please, 56. Suppose that the firm's cost function is given in...
Answer the Following Three Questions Please, 56. Suppose that the firm's cost function is given in the following schedule (where Q is the level of output): Output Total Q (units) Cost 0   7 1 25 2 37 3 45 4 50 5 53 6 58 7 66 8 78 9 96 10   124   Determine the (a) marginal cost and (b) average total cost schedules 57. Complete the following table. Total Marginal Average Output Profit Profit Profit 0 ?48             0 ______...
Please answer the following two questions. What are the keys steps that should be undertaken when...
Please answer the following two questions. What are the keys steps that should be undertaken when procuring a subcontractor? Who are the parties that might be involved?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT