Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
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.
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...
Chapter 12 Solutions
Starting Out with C++: Early Objects
Ch. 12.2 - Prob. 12.1CPCh. 12.2 - What will the following program segment display?...Ch. 12.2 - Prob. 12.3CPCh. 12.2 - Prob. 12.4CPCh. 12.2 - Indicate whether the following strcmp function...Ch. 12.2 - Prob. 12.7CPCh. 12.3 - Prob. 12.8CPCh. 12.3 - Write a statement that will convert the C-string...Ch. 12.3 - Prob. 12.10CPCh. 12.3 - Prob. 12.11CP
Ch. 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...
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
- The 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_forwardcsearrow_forward
- HangmanAA.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_forwardCCC '13 J1 - Next in line Canadian Computing Competition: 2013 Stage 1, Junior #1 You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years. Given the ages of the youngest and middle children, what is the age of the oldest child? Input Specification The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0arrow_forwardIn 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. const int SIZE = 2;void getRightmostLowestPoint(const double points[][SIZE], int numberOfPoints, double rightMostPoint[]); Write a test program that prompts the user to enter the coordinates of six points and displays the rightmost lowest point.arrow_forwardManhattan skyline def manhattan_skyline(towers):This classic problem in computational geometry (essentially, geometry that can be done using only integer arithmetic; yes, that is an actual thing) is best illustrated by pictures and animations such as those on the page "The Skyline problem", so you can first check that it out to get an idea of what is going on. Given a list of rectangular towers as tuples (s, e, h) where s and e are the start and end x-coordinates (satisfying e>s) and h is the height of that tower, compute and return the total visible area of the towers, being careful not to double count two or more towers that are partially overlapping. All towers share the same flat ground baseline at the height. The classic solution illustrates the important sweep line technique that starts by creating a list of precisely those x-coordinate values where something relevant to the problem takes place. In this problem, the relevant x-coordinates are those where some tower either…arrow_forwardKnight's Tour: The Knight's Tour is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once. There are several billion solutions to the problem, of which about 122,000,000 have the knight finishing on the same square on which it begins. When this occurs the tour is said to be closed. Your assignment is to write a program that gives a solution to the Knight's Tour problem recursively. You must hand in a solution in C++ AND Java. The name of the C++ file should be "main.cc" and the name of the Java file should be "Main.java". Write C++ only with a file name of main.cc Please run in IDE and check to ensure that there are no errors occuring Output should look similar to: 1 34 3 18 49 32 13 16 4 19 56 33 14 17 50 31 57 2 35 48 55 52 15 12 20 5 60 53 36 47 30 51 41 58 37 46 61 54 11 26 6 21 42 59 38 27 64 29 43 40 23 8 45 62 25 10 22 7 44 39 24 9 28 63arrow_forwardSee the sample outputs for more clarification. Project Specifications Input for this project: Values of the grid (row by row) Output for this project: Whether or not the grid is magic square Programmer's full name Project number Project due date Processing Requirements Use the following template to start your project: #include using namespace std; // Global constants // The number of rows in the array // The number of columns in the array // The value of the smallest number // The value of the largest number const int ROWS = 3; const int COLS = 3; const int MIN = 1; const int MAX = 9; // Function prototypes bool isMagicsquare(int arrayRow1[], int arrayRow2 [], int arrayRow3[], int size); bool checkRange (int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max); bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size); bool checkRowSum (int arrayrow1[], int arrayrow2[], int arrayrow3[], int size); bool checkColiSum(int arrayrow1[], int…arrow_forwardExtreme Fizz BuzzFizz Buzz is a classic Computer Science problem about Selection. For an integer x, print:• “Fizz” if x is only divisible by 3,• “Buzz” if x is only divisible by 5,• “FizzBuzz” if x is divisible by both 3 and 5,• the number x if it is not divisible by both 3 and 5.This problem is the extreme version of Fizz Buzz. You are given a list of K distinct integers A and a list of K characters S. Both lists are numbered from 1 to K. The integer Ai corresponds to the character Si. Denote B as the subset of A. There will be a rule for each possible subset: if an integerx is only divisible by all elements in B, print a string which is the concatenation of the corresponding character of each element in B, sorted by the index in ascending order. However, if B is an empty subset, print the first digit of x instead. Does it look complicated? Do not worry, as it is just a generalization of the regular Fizz Buzz. For example, if A = [3, 5] and S = [F, B], you will get the normal Fizz…arrow_forwarddjkvnuisdvsuykb jkxcnjlvnocvarrow_forwardComputer Science Question LabThere is only one list of N ingredients in the menu. Every ingredient has its beauty value that does not depend on its taste, but on the way it looks, which is expressed as a positive integer. To order a dish, the customer asks Ramsay to use all the ingredients from L to R (L is strictly less than R). Ramsay knows that the dish will be tasty and not only beautiful if the sum of its ingredients' beauty values is divisible by K. Ramsay does not want to use all the ingredients, so he always excludes one of them. Which one? - The least beautiful one! (in other words - which has the minimal beauty value). Now he wonders - how many segments (L,R) are there such that the sum of their beauty values will be divisible by K after excluding the least beautiful ingredient. Your assignment is to develop a python code that prints the answer for the problem. Sample test case are given below:Input:3 51 2 3Output:1arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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