Problem Solving With C++ (Looseleaf) - With Access
9th Edition
ISBN: 9780133835267
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8.2, Problem 17STE
Consider the following code:
string s1, s2 (“Hello”);
cout << “Enter a line of input: \n”;
cin >> s1;
if (s1 == s2)
cout << “Equal \n”;
else cout << “Not equal \n”;
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
Hello friend!
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)
Examples of strings that can be accepted:
Jill, Allen
Jill , Allen
Jill,Allen
Ex:
Enter input string:Jill, Allen
(2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)Ex:
Enter input string:Jill AllenError: No comma in string.
Enter input string:Jill, Allen
(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)Ex:
Enter input string:Jill, AllenFirst word: JillSecond word: Allen
(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)Ex:
Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input string: Golden , Monkey First word: Golden Second word:…
5.A)For the code segment below, what should be the values for q will result in kiwi being included in the output?
switch(q)
{
case 1:
cout << "apple";
break;
case 2:
cout << "orange";
break;
case 3:
cout << "banana";
break;
case 4:
cout << "pear";
case 5:
cout << "grapes";
default:
cout << "kiwi";
}
B)Evaluate the following segment of a program. Show the procedure to reach your answer.
int a = 3, b = 5, c = 2, d = 4;
find: !(a / b > 0) && (22 > b % c + d) || !(a * d >= b – d / c)
C) Write equivalent expressions for each of the following by using De Morgan’s Law.
!(c == ‘r’ || (( y > 2) && !found ))
In C++
Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.
Ex: If the input is:
n Monday
the output is:
1 n
Ex: If the input is:
z Today is Monday
the output is:
0 z's
Ex: If the input is:
n It's a sunny day
the output is:
2 n's
Case matters. n is different than N.
Ex: If the input is:
n Nobody
the output is:
0 n's
The program must define and call the following function that takes the input string and character as parameters, and returns the number of times the input character appears in the input string.int CalcNumCharacters(string userString, char userChar)
Chapter 8 Solutions
Problem Solving With C++ (Looseleaf) - With Access
Ch. 8.1 - Prob. 1STECh. 8.1 - What C string will be stored in singingString...Ch. 8.1 - What (if anything) is wrong with the following...Ch. 8.1 - Suppose the function strlen (which returns the...Ch. 8.1 - Prob. 5STECh. 8.1 - How many characters are in each of the following...Ch. 8.1 - Prob. 7STECh. 8.1 - Given the following declaration and initialization...Ch. 8.1 - Given the declaration of a C-string variable,...Ch. 8.1 - Write code using a library function to copy the...
Ch. 8.1 - What string will be output when this code is run?...Ch. 8.1 - Prob. 12STECh. 8.1 - Consider the following code (and assume it is...Ch. 8.1 - Consider the following code (and assume it is...Ch. 8.2 - Consider the following code (and assume that it is...Ch. 8.2 - Prob. 16STECh. 8.2 - Consider the following code: string s1, s2...Ch. 8.2 - What is the output produced by the following code?...Ch. 8.3 - Is the following program legal? If so, what is the...Ch. 8.3 - What is the difference between the size and the...Ch. 8 - Create a C-string variable that contains a name,...Ch. 8 - Prob. 2PCh. 8 - Write a program that inputs a first and last name,...Ch. 8 - Write a function named firstLast2 that takes as...Ch. 8 - Write a function named swapFrontBack that takes as...Ch. 8 - Prob. 6PCh. 8 - Write a program that inputs two string variables,...Ch. 8 - Solution to Programming Project 8.1 Write a...Ch. 8 - Write a program that will read in a line of text...Ch. 8 - Give the function definition for the function with...Ch. 8 - Write a program that reads a persons name in the...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that can be used to train the user...Ch. 8 - Write a sorting function that is similar to...Ch. 8 - Redo Programming Project 6 from Chapter 7, but...Ch. 8 - Redo Programming Project 5 from Chapter 7, but...Ch. 8 - Prob. 11PPCh. 8 - Write a program that inputs a time from the...Ch. 8 - Solution to Programming Project 8.14 Given the...Ch. 8 - Write a function that determines if two strings...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Program is to be written in C (1) Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. Ex: Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen (3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen (4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input string: Golden , Monkey First word:…arrow_forwardPrompt the user to enter a string s and an integer i in the range 0 to l where l is the length of the string s. Then show how to remove the character at index i from the string s using C++ inbuilt functions. Write program in C++ languagearrow_forwardIn C++ write a program that prompts the user to enter three strings and then make a new string formed by concatenation of the three strings with space in between. Print the new string formed in output. Input- "Alpha", "Beta", "Gamma" Output- "Alpha Beta Gamma"arrow_forward
- Given string stringVal on one line, integer idxBegin on a second line, and integer desiredLen on a third line, output the substring of stringVal starting at position idxBegin and with length desiredLen. End with a newline. Ex: If the input is: Fuzzy bear 3 4 then the output is: zy b Note: Using a pre-defined string function, the solution can be just one line of code. #include <iostream>#include <string>using namespace std; int main() { string stringVal; int idxBegin; int desiredLen; getline(cin, stringVal); cin >> idxBegin; cin >> desiredLen; /* Your code goes here */ return 0;}arrow_forwardIn C++ Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved by executingcout << fixed << setprecision(2); once before all other cout statements. Ex: If the input is: 20.0 3.1599 the output is: 3.16 11.85 79.00 Note: Real per-mile cost would also include maintenance and depreciation.arrow_forwardEvaluate the following expressions. (2)a. 4 * 7 == 74 / 3b. 4 + 7 / 2 <= 9 - 15 % 6f. 3.9 / 4 - 6 >= 8 - 6.2 * 1.5 3.Suppose that x, y, and z are int variables and x = 13, y = 45, and z = 20. Determine whether the following expressions evaluate to true or false. (2, 5)a. !(x - y <= 10)b. x + y > 10 || z < 15c. (x != y) && (x <= z) 4.Suppose that str1, str2, and str3 are string variables, and str1 = "Low", str2 = "High", and str3 = "Medium". Evaluate the following expressions. (2, 7)b. str1 != "low" d. str3 > "Medium" 5.Suppose that x, y, z, and w are int variables and x = 25, y = 3, z = 12, and w = 4. What is the output of the following statements? (2, 5)b. cout << "y != z - 9: " << (y != z - 9) << endl;c. cout<<"x-y==z+10:"<<(x-y==z+10)<<endl;d. cout << "!(z < w): " << !(z < w) << endl; 6.Which of the following are not relational operators? (2) b. == e. || 7.What is the output of the following…arrow_forward
- In a right angled triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program in c++ that prompts the user to enter the lengths of the three sides of a triangle and then outputs a message indicating whether the triangle is a right angled triangle. Assume all sides are integer values.arrow_forwardAssume that nextWord is a String variable that has been given a String value consisting entirely of letters. Write some Java code that outputs the message "First half of the alphabet", provided nextWord precedes "N" in alphabetic ordering. If nextWord does not precede "N" in alphabetic ordering, the code should output "Second half of the alphabet". (Note that "N" uses double quotes to produce a String value, as opposed to using single quotes to produce a char value.)arrow_forwardR4.10 What are the values of the following expressions? In each line, assume that String s = "Hello"; String t = "World"; a. s.length() + t.length()b. s.substring(1, 2)c. s.substring(s.length() / 2, s.length()) d. s + te. t + sarrow_forward
- Consider the following function: int mystery(int x, int y, int z) { if (x <= y && x <= z && x != 0) return (y + z) / x; else if (y <= z && y <= x && y != 0) return (z + x) / y; else if (z <= x && z <= y && z != 0) return (x + y) / z; else return x + y + z; } What is the output of the following C++ statements? i.cout << mystery(1, 0, 0) << endl; ii.cout << mystery(10, 10, 10) << endl;arrow_forwardPLEASE US SCHEME IN DRRACKET: In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozit followed by between zero or more Whatzits. A Whoozit is the character 'x' followed by between one or more 'y's. A Whatzit is a 'q' followed by either a 'z' or a 'd', followed by a Whoozit.-The program should ask the user to “Enter an alien word:”, read the input as a string, and check whether or not it is a valid word (Blurb). If it is valid, it prints "The word is fine.", otherwise it prints "The word is a mess!". -The program should loop and ask the user for new input until they enter a valid blurb.arrow_forward(1) Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. Ex: Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen (3) Using string splitting, extract the two words from the input string and then remove any spaces. Output the two words.Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen (4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input string: Golden , Monkey First word: Golden Second word: Monkey Enter input string: Washington,DC First…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Algebraic Expressions – Algebra Basics; Author: TabletClass Math;https://www.youtube.com/watch?v=U-7nq7OG18s;License: Standard YouTube License, CC-BY
Python Tutorial for Beginners 3 - Basic Math, Mathematical Operators and Python Expressions; Author: ProgrammingKnowledge;https://www.youtube.com/watch?v=Os4gZUI1ZlM;License: Standard Youtube License