
Data structures and algorithms in C++
2nd Edition
ISBN: 9780470460443
Author: Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 2, Problem 1C
Program Plan Intro
Quine
- Declare the header files and namespace.
- Initialize the string.
- Declare and initialize the necessary constant variables.
- Define the “main()” method,
- Print the string denoting the header files and namespace.
- Print the next line of the program with double quotes.
- Execute loop till the string size,
- Execute switch for string elements,
- If it is “nline”,
- Print the next line of the program with escape sequence.
- Break the switch.
- If it is “bspace”,
- Print the backspaces.
- Break the switch.
- If it is “qqtes”,
- Print the backspace with quotes.
- Break the switch.
- By default,
- Print all the string elements.
- If it is “nline”,
- Execute switch for string elements,
- Print the quotes with semi colon.
- Print the string.
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
(团)
(四)
The Dog class has a constructor that takes two parameters. The first parameter is a String
representing a dog's name and the second parameter is an int representing the dog's age, in months.
9
Mark for Review
ARC
The following code segment appears in a class other than Dog.
Which of the following best describes the contents of dog1 and dog2 as a result of executing this code
segment?
Dog dogl new Dog ("Rex", 4);
Dog dog2
dogl
dog1;
new Dog("Fido", 60);
dog1 and dog2 are Dog variables that each contain the same Dog object, which
represents a dog named "Fido' that is 60 months old.
dogl is a Dog variable that contains a Dog object representing a dog named
"Fido" that is 60 months old, and dog2 is a Dog variable that contains
a Dog object representing a dog named "Rex" that is 4 months old.
dogl and dog2 are Dog reference variables that each contain a reference to the
same memory address that contains the Dog object representing a dog named
"Fido' that is 60 months old.
dogl is a…
The following code segment is intended to assign to newword the result created by removing the first
occurrence of "a" from word. Assume that the String variable word has been properly declared
and initialized. This code segment works for some, but not all, values of word.
int aLoc
word.indexOf("a");
String newword word.substring(0, aLoc) + word.substring(aLoc + 1);
18
Mark for Review
Which of the following conditions best describes the condition in which this code segment will not work a
intended and will result in a runtime error?
is the first character in word.
is the last character in word.
word does not contain the character "a".
word contains only a sequence of multiple "a" characters.
Consider the following code segment, which is intended to create a String that consists of the last
character in word and assign it to the variable lastChar
String word / initialization not shown */;
// line 1
int len word.length();
// line 2
String lastChar word.substring(len);
// line 3
17
Mark for Review
Which of the following best describes why this code segment will not work as intended?
substring needs to be called with two parameters, so the method call in line
3 should be changed to word.substring(len, len + 1).
len is not the correct index of the last character in word, so the method call in
line 3 should be changed to word.substring(len - 1).
len is not the correct index of the last character in word, so the method call in
line 3 should be changed to word.substring(len + 1).
substring cannot be called with a variable as the parameter, so the method
call in line 3 should be changed to word.substring (word.length()).
ABC
Chapter 2 Solutions
Data structures and algorithms in C++
Ch. 2 - Prob. 1RCh. 2 - Prob. 2RCh. 2 - Prob. 3RCh. 2 - Give an example of a software application where...Ch. 2 - Prob. 5RCh. 2 - Draw a class inheritance diagram for the following...Ch. 2 - A derived class’s constructor explicitly invokes...Ch. 2 - Give a short fragment of C++ code that uses the...Ch. 2 - Prob. 9RCh. 2 - Suppose we have a variable p that is declared to...
Ch. 2 - Prob. 11RCh. 2 - Generalize the Person-Student class hierarchy to...Ch. 2 - Prob. 13RCh. 2 - Consider the following code fragment:
class...Ch. 2 - Write a short C++ function that counts the number...Ch. 2 - Write a short C++ function that removes all the...Ch. 2 - Write a short program that takes as input three...Ch. 2 - Prob. 18RCh. 2 - Give an example of a C++ program that outputs its...Ch. 2 - Suppose you are on the design team for a new...Ch. 2 - Most modern C++ compilers have optimizers that can...Ch. 2 - Design a class Line that implements a line, which...Ch. 2 - Write a C++ class that is derived from the...Ch. 2 - Write a C++ class that is derived from the...Ch. 2 - Write a program that consists of three classes, A,...Ch. 2 - Prob. 8CCh. 2 - Write a C++ program that can take a positive...Ch. 2 - Write a C++ program that “makes change.” Your...Ch. 2 - Write a simulator as in the previous project, but...Ch. 2 - Write a C++ program that inputs a document and...
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
- Consider the following code segment. String one String two "computer"; "science"; String concat / missing code */; System.out.println(concat); 2 16 Mark for Review ARC Which of the following expressions can be used to replace/missing code / so that the code segment prints the string "pun"? one.substring(3, 4) + two.substring(4, 4) one.substring(3, 5) + two.substring(4, 5) one.substring(4, 5) + two.substring(5, 5) one.substring(4, 6) + two.substring(5, 6)arrow_forwardPlease R show code and output for the following questions.arrow_forwardGo through Chapters 2-4 of the 9th edition of Foundations of Information Systems: What do you like or not like about the student registration process? Do you believe that a university should be allowed to monitor emails sent and received on the university computers? Why or why not? Support your answer. Is security a technical issue? A business issue? Both? Support your answer.arrow_forward
- Thank You Computer SciencePlease provide source code in C and also the state diagram in drawing form not text Design a state diagram to recognize one form of the comments of the C- based programming languages, those that begin with /* and end with */. Submission: a state transition diagram (no source code required) specifying all necessary components.arrow_forwardHello, Mistakely submitted blurr image please skip otherwise unhelpful. Computer science.arrow_forwardMistakely submitted blurr image please skip otherwise unhelpful. Computer science.arrow_forward
- Subject = Computer Science i mistakely submitted blurr image please skip it.arrow_forwardOR AND Neg-AND D A Output D A Output B D Output AB Output AB Output AB Output AB 00 01 10 00 00 01 10 10 11 NOR 11 10 |1|1 NAND Neg-OR B A Do A Output B Do A Output Output B AB Output AB Output AB Output 00 00 00 01 01 01 10 10 10 11 |11 XOR XNOR NOT A Output Output Output B B AB Output AB Output A Output 00 00 01 01 0 1 10 10 11 |1|1arrow_forwardData Representation Part 3 HW3 1. Convert each decimal number to its 9's complement (use as many digits as shown): a) 73 b) 40512 c) 980034 d) Perform subtraction using 9's complement: 5042-671 2. Convert the following decimal numbers to the 10's complement: a) 128 b) 4097 c) 56020 d) Perform subtraction using 10's complement: 3205-4879 3. Perform the following multiplications. Assume that all values are unsigned numbers. (No problem with unsigned (always positive) numbers, just use the same standard techniques as in base 10.) a) 10112 × 01012 b) 011012 × 001112 c) 1100102 × 10112 d) 10110102 x 111012 4. Perform the following multiplications. Assume that all values are signed 2's complement numbers. a) 11002 01112 b) 00102 x 10102 - first multiply without sign-extending (show the wrong result), then redo with proper sign-extension. c) 111002 × 000112 5. Perform the following divisions. Assume that all values are unsigned numbers. a) 1011012 ÷ 1102 b) 1000112 ÷ 1012arrow_forward
- From MATLAB Calculate the following scalars, matrices and vectors, using the matrices from problem 5. Outputs of the commands are required. (mean, sum, det, find, transpose (aka the apostrophe operator)arrow_forwardModify the car purchase algorithm presented in class (on Chapter 1's slide set) so that the gasprice is no longer a constant, but instead it is subjected to an inflation of 5% yearly. Run thealgorithm and tabulate the costs year by year. (No need to program in C++ for this problemunless you really want to. You can use a spreadsheet or hand calculations.) Which car is abetter deal and by how much? Explain your algorithm welll.arrow_forwardProblem 12. Consider the following grammar: <S> → a <S> c <B> | <A> | b <A> → c <A> | c <B> → d | <A> Which of the following sentences are in the language generated by this grammar? a. abcd b. acccbd c. acccbcc d. acd e. acccarrow_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
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY