Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12, Problem 13PC
Program Plan Intro
Digits Sums of Squares and Cubes
Program Plan:
- Include the required header files to the program.
- Define the function prototype.
- Define the “main ()” function. Inside this function,
- Set the field width to print the string “Number”.
- Set the field width to print the string “Square”.
- Set the field width to print the string “Cube”.
- Set the field width to print the string “Sum”.
- Loop 1000 times using “for” loop.
- Find the square of a number and store it in a variable “square_Num”.
- Find the cube of a number and store it in a variable “cube_Num”.
- Call the function “sum_Of_Digits ()” by passing “num” as an argument. Store the returned value in a variable “sum”.
- Check if the sum of digits of “square_Num” and sum of digits of “cube_Num” are equal.
- Print the value of “num”, “square_Num”, “cube_Num” and “sum”.
- Give function definition for “sum_Of_Digits ()”. Inside this function,
- Declare required variables “numberString”, and “digitSum”.
- Print the value of “number”.
- Find the sum of digits using “for” loop.
- Find the sum and store it in a variable “digitSum”.
- Return the value.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
P1
P2
P3
P4
A pentagonal number is one that corresponds to dots arranged into a
pentagon. Above are the first four pentagonal numbers and their
pentagons.
The pentagonal number PN has sides made of N dots. When you count the
dots for a pentagonal number, include the dots for the inner pentagons. So
to figure out how many dots PN has, find out how many P(N-1) has and add
the dots for the new sides of size N.
P1 = 1, P2 = 5, P3 = 12, P4 = 22
Figure out a recursive formula for PN and then write a function that
implements it. That is, implement pentagonal() using recursion.
pentagonal(1) -> 1
pentagonal(2) -> 5
pentagonal(3) -> 12
Q1: Write a program that reads a set of N integers. Then,
the program finds and outputs the sum of the even values
and the sum of the odd values of them. For example: if the
value entered for N=5, and the five integers are 3, 6, 2, 9, 7.
Then the sum of even values (6+2 = 8), and the sum of
odd values (3+9+7 = 19)
Q2: Write a program that reads some numbers until it
reaches a specific value (assume -1 is a stop value in this
case). The program should find and outputs the average of
all of the numbers (between 10...40) except the stop value
(-1). For example: If the numbers look like: 12 5 30 48 -1.
Then, the average of the numbers: (12+30)/2 = 21.
In computational geometry, often you need to find the rightmost lowest point in a set of points. Write the following function that returns the rightmost lowest point in a set of points:# Return a list of two values for a pointdef getRightmostLowestPoint(points):Write a test program that prompts the user to enter the coordinates of six points and displays the rightmost lowest point.
Chapter 12 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 12.2 - Write a short description of each of the following...Ch. 12.2 - What will the following program segment display?...Ch. 12.2 - Prob. 12.3CPCh. 12.2 - Prob. 12.4CPCh. 12.2 - Write code that uses the cin.get1ine function read...Ch. 12.2 - Indicate whether the following strcmp function...Ch. 12.2 - Prob. 12.7CPCh. 12.3 - Write a short description of each of the following...Ch. 12.3 - Write a statement that will convert the C-string...Ch. 12.3 - Prob. 12.10CP
Ch. 12.3 - Prob. 12.11CPCh. 12.3 - Prob. 12.12CPCh. 12.4 - What is the output of the following program?...Ch. 12 - A(n)___________is represented in memory as an...Ch. 12 - The____________ statement is required before the...Ch. 12 - A(n)____________is written in your program as a...Ch. 12 - Prob. 4RQECh. 12 - The______________ is used to mark the end of a...Ch. 12 - Prob. 6RQECh. 12 - Prob. 7RQECh. 12 - Prob. 8RQECh. 12 - Prob. 9RQECh. 12 - Prob. 10RQECh. 12 - Prob. 11RQECh. 12 - Prob. 12RQECh. 12 - Prob. 13RQECh. 12 - Prob. 14RQECh. 12 - Prob. 15RQECh. 12 - Prob. 16RQECh. 12 - Prob. 17RQECh. 12 - Prob. 18RQECh. 12 - Write a function whose prototype is char...Ch. 12 - #inc1ude iostream using namespace std; int main()...Ch. 12 - #include iostream using namespace std; int main()...Ch. 12 - #include iostream using namespace std; int main()...Ch. 12 - #inc1ude iostream #inc1ude string using namespace...Ch. 12 - #inc1ude iostream #inc1ude cstring using namespace...Ch. 12 - #inc1ude iostream using namespace std; int main()...Ch. 12 - #inc1ude iostream #inc1ude string using namespace...Ch. 12 - #include iostream #inc1ude cstring using namespace...Ch. 12 - #include iostre4m #inc1ude cstring using namespace...Ch. 12 - Each of the following programs or program segments...Ch. 12 - Soft Skills 30. You are a member of a...Ch. 12 - Prob. 1PCCh. 12 - Prob. 2PCCh. 12 - Prob. 3PCCh. 12 - Prob. 4PCCh. 12 - Name Arranger Write a program that asks for the...Ch. 12 - Prob. 6PCCh. 12 - Prob. 7PCCh. 12 - Prob. 8PCCh. 12 - Prob. 9PCCh. 12 - Password Verifier Imagine you are developing a...Ch. 12 - Prob. 11PCCh. 12 - Check Writer Write a program that displays a...Ch. 12 - Prob. 13PCCh. 12 - Dollar Amount Formatter Modify Program 12-13 by...Ch. 12 - Word Separator Write a program that accepts as...Ch. 12 - Prob. 16PCCh. 12 - I before e except after c A friend of yours who is...Ch. 12 - User Name Write a program that queries its...Ch. 12 - String Splitter Write a function vectorstring...Ch. 12 - Palindromic Numbers A palindromic number is a...
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 prime number is called a Mersenne prime if it can be writtenin the form 2p - 1 for some positive integer p. Write a program that findsall Mersenne primes with p ≤100 and displays the output as shown below.(Hint: You have to use BigInteger to store the number because it is too big tobe stored in long. Your program may take several hours to run.) p 2^p – 1---------------------2 33 75 31...arrow_forwardThe following is useful as part of a program to play Minesweeper. Suppose you have a 5×5 list that consists of 0s and M's. Write a program that creates a new 5×5 list that has M's in the same place, but the Zeroes are replaced by counts of how many M's are in adjacent cells (adjacent either horizontally, vertically, or diagonally). An example is shown below. An example is shown below:arrow_forwardJava Programarrow_forward
- #in c++arrow_forwardBaby Names: Each year, the government releases a list of the 10,000 most common baby namesand their frequencies (the number of babies with that name). The only problem with this is thatsome names have multiple spellings. For example, "John" and ''.Jon" are essentially the same namebut would be listed separately in the list. Given two lists, one of names/frequencies and the otherof pairs of equivalent names, write an algorithm to print a new list of the true frequency of eachname. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John andJohnny are synonyms. (It is both transitive and symmetric.) In the final list, any name can be usedas the "real" name.EXAMPLEInput:Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19)Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher)Output: John (27), Kris (36)arrow_forwardIN JS PROGRAMMING LANGUAGE Your local bank has decided to upgrade its ATM machines by incorporating motion sensor technology. The machines now interpret a series of consecutive dance moves in place of a PIN number. Create a program that converts a customer's PIN number to its dance equivalent. There is one dance move per digit in the PIN number. A list of dance moves is given in the code. Examples danceConvert("0000") danceConvert("3856") ["Shimmy", "Shake", "Pirouette", "Slide"] → ["Slide", "Arabesque", "Pop", "Arabesque" ] -arrow_forward
- In c++arrow_forwardHangmanAA.java For this program, you will create the game Hangman. (If you are unsure of how to play Hangman, Google it.) The game will start by asking player 1 for a word or phrase (can be multiple words). Then player 1 will be asked how many missed guesses are allowed by player 2. Once this information is received, player 2 will take over. (Have the program print many blank lines of space so that player 2 can’t see what player 1 entered.) The instructions should be displayed for player 2 as well as the number of misses they’re allowed to make before they lose the game. The screen should also output dashes or underscores to represent each letter of player 1’s secret word/phrase. Player 2 should guess one letter at a time. Case should not matter. Typing x or X should give the same result. If that letter is present in the mystery phrase, then it should be displayed. (It will replace the dash/underscore in that spot. Spaces, punctuation, and all other non-alphabetic characters should…arrow_forwardAssignment 5A: Multiple Frequencies. In the last assignment, we calculated the frequency of a coin flip. This required us to have two separate variables, which we used to record the number of heads and tails. Now that we know about arrays, we can track the frequency of all numbers in a randomly generated sequence. For this program, you will ask the user to provide a range of values (from 1 to that number, inclusive) and how long of a number sequence you want to generate using that number range. You will then generate and save the sequence in an array. After that, you will count the number of times each number occurs in the sequence, and print the frequency of each number. Hints: You can use multiple arrays for this assignment. One array should hold the number sequence, and another could keep track of the frequencies of each number. Sample Output #1: What's the highest number you want to generate?: 5 How Long of a number sequence do you want to generate?: 10 Okay, we'll generate 10…arrow_forward
- Question 3 Write a program that finds the equivalent series and parallel resistance for a collection of resistor values. Your program should first read in the number of resistors and then compute the equivalent series resistance for all resistors in the collection and the equivalent parallel resistance. For example, if there are 3 resistors of 100, 200, and 300 Ohms, respectively, their equivalent series resistance is 100+200+300 and their equivalent parallel resistance is 1(1/100+1/200+1/300). Your program should read each resistance value (R), add R to the series sum (RS) and add 1/R to the parallel sum (RP). After loop exit, display RS and 1/RP.arrow_forwardYou have a list of student ID’s followed by the course number (separated by a space) that the student is enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list might look like this:1 CS1002 MATH2102 CS1051 CS200Write a program that reads data in this format from the console. If the ID is −1 then stop inputting data. Use the HashMap class to map from an Integer (the student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this:HashMap<Integer, ArrayList<String>> students =new HashMap<Integer, ArrayList<String>>();After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student ID.arrow_forwardQuestioin: Hidden Secret Problem! In this problem, you are given two names, you have to find whether one name is hidden into another. The restrictions are: You can change some uppercase letters to lower case and vice versa. You can add/remove spaces freely. You can permute the letters. And if both the names match exactly, then you can say that one name is hidden into another. Input Input starts with an integer T (≤ 100), denoting the number of test cases. Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100(inclusive). Output For each case, print the case number and Yes if one name is hidden into another. Otherwise print No. Sample Input Output 3 Tom Marvolo Riddle I am Lord Voldemort I am not Harry Potter Hi Pretty Roar to man Harry and Voldemort Tom and Jerry and Harry Case 1: Yes Case 2: Yes Case 3: No And I want…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