
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
My assignment wants me to program the hailstone series. I have done that, but my program isn't executing because I did not put it in the format of returning a string, instead I cout the n value. How can I make it so it returns the series as a string?

Transcribed Image Text:Hailstone
Editor
1 #include <string>
Problem Statement
Take a number, n. If n is even, divide it by 2. If odd, multiply by 3 and add
1. Repeat with the new number, forever or until you get the number 1. For
instance, suppose you start with the number 3:
3 string sequence(int n) f
4 cout <<n <<"";
5- whileCn-1)
6
7
if(n%2-0)(
Since 3 is odd, you multiply by 3 and add 1 to get 9+1-10
Since 10 is even, you divide by 2 to get 5
Since 5 is odd, you multiply by 3 and add 1 to get 16
Since 16 is a power of 2, you will repeatedly divide by 2, getting 8, 4,
2, and 1 in that order
cout << n<<""
}else if(n%2-1)(
10
cout << n<<""
The sequence of numbers produced by this procedure is known as a
hailstone sequence. The hailstone sequence beginning with 3 is therefore
"3 10 5 16 8 4 21". The Collatz conjecture, proposed by Lothar Collatz in
1937, is that the hailstone sequence for any starting number always
terminates; that is, it always reaches 1. This conjecture is unproven at this
time, but is easy to verify for small n
12
13
14
15
Your task for this lab is to produce the hailstone sequence for an arbitrary
starting value. You are given an int value n, and asked to return a
string containing the hailstone sequence beginning at n. The string
should contain each number in the sequence in order, separated by single
spaces. There should be no leading or trailing spaces
Constraints
. The input n will be between 1 and 100, inclusive
Test
Submit
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

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
- A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words.arrow_forwardI keep getting an error "wrong type argument: stringp, nil" what does that mean?arrow_forwardWrite a program that creates an input function to enter a string. Then use .isalpha method to find ifthe first character in the string starts with a letter or a non-letter. (Hint: use indexing and if and if notfunction). Make sure to print the two statements ‘Your string starts with a letter’ and ‘Your stringcontains a non-letter’)arrow_forward
- I need help with using the Stringtokenizer. I'm not sure if it should be in a class, and called in the main. Or should be in my main program. this is the description : Using StringTokenizer, the program will parse the input file and identify words and integers. Words are notcase sensitive and can only contain letters, apostrophes, hyphens, and digits but must start with a letter. The numbers are a sequence of digits. They can be positive or negative integers. If the number is negative, there is no space between the negative sign, -, and the first digit. A sum will be made form the integers contained in the input file. StringTokenizer methods inline now contains the tokens. A few useful method of the StringTokenizer are: Boolean hasMoreTokens() // test if there are more tokens available from this tokenizer's string. String nextToken() // returns the next token from this string tokenizer. Int countTokens() //calculates the number of times that this tokenizer's nextToken method can…arrow_forwardPlease answer ASAParrow_forwardMy instructor saying my code has wrong indentation on several lines… please let me know which lines. I’ve asked this twice before and I haven’t got it yetarrow_forward
arrow_back_ios
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