Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
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
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:
Java Program
A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address,
birthday, etc. Write a program that first takes in word pairs that consist of a name and a phone number (both strings). That list is followed
by a name, and your program should output the phone number associated with that name.
Ex: If the input is:
Joe 123-5432 Linda 983-4123 Frank 867-5309
Frank
the output is:
867-5309
LAB
6.21.1: LAB: Contact list
0/ 10
ACTIVITY
main.py
Load default template...
1 user_input = input()
2 entries = user_input.split()
3 contact_list = dict(pair. split(':') for pair in entries)
Chapter 12 Solutions
Starting Out With C++: Early Objects (10th 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
- 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_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_forward
- You 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_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_forwardYou are going to create an autogenerated list of numbers. Ask a user for a random number between 1 and 25. Your program must create a list of numbers between 1 and the user-given number. BUT it should only include every second number. Display the list of numbers in a nicely formatted way. The numbers should be seperated by (",")(comma with no spaces)(notice the spaces on each side of the comma) If the user types 19 the program will print: 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 , 19 Use a For loop to answer this question. Do not write a function or procedure. Only write the code. The output must match the above and the test case output formatting. For example Input Result 15 Please enter a number between 1 and 25: 1,3,5,7,9,11,13,15 12 Please enter a number between 1 and 25: 1,3,5,7,9,11 8 Please enter a number between 1 and 25: 1,3,5,7arrow_forward
- Computer Science This is a codingbat problem. Please answer in Java and do not change the starter code. You have been asked to write the game of tic tac toe. In the first version of the game, we will only be comparing horizontally for a win. A win is determine by all of the elements in a row either being an X or an O. You need to return a String with the winner or TIE if there is no winner. ticTacToe(["X", "O", "O"], ["X", "O", "O"], ["X", "X", "X"]) → "X"ticTacToe(["X", "O", "X"], ["X", "X", "O"], ["O", "O", "O"]) → "O"ticTacToe(["X", "O", "X"], ["X", "X", "O"], ["O", "X", "O"]) → "TIE" public String ticTacToe(String[] top, String[] middle, String[] bottom) { }arrow_forwardIn C Programming Language Palindrome: “A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward, such as ‘madam’ or ‘kayak’” (excerpt from Wikipedia).Write a program that reads 8 words from Palindrome.txt and checks whether the word you read is a palindrome (please read its description above) or not. Print the index numbers of all the palindrome words in your array. You are required to read words character by character into a character array.• Write readFile function, which gets a file pointer and a two-dim array, to read each word(bunch of characters) line by line and store them into a two-dim character array.• Write findSize function takes a one-dim array and returns its actual size.• Write isPalindrome function takes a one-dim character array to check whether the content is a polindrome or not. If the word (character squence) is a palindrome, then it returns 1. Otherwise, it returns 0.arrow_forwardYour math teacher has asked you to write a program that grades the multiple-choice questions in a Math exam. The exam has 10 multiple-choice questions. Here are the correct answers: 1. A 6. B 2.D 3. B 4.B 5.C 7.A 8. B 9.C 10.D Your program should store the correct answers shown above in a list. It should ask the student to enter her answers for each of the 10 questions, and the answers should be stored in another list. After the student's answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly at least answer 7 of the 10 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions. Your program must have at least the following functions: 1. getInput(inputList) 2. checkAnswers(userlist, correctAnswerList, rightQuestions, wrongQuestions) *. The getInput function accepts a list and asks the user to input…arrow_forward
- : In the classic problem FizzBuzz, you are told to print the numbers from 1 to n. However,when the number is divisible by 3, print "Fizz''. When it is divisible by 5, print "Buzz''. When it isdivisible by 3 and 5, print"FizzBuzz''. In this problem, you are asked to do this in a multithreaded way.Implement a multithreaded version of FizzBuzz with four threads. One thread checks for divisibilityof 3 and prints"Fizz''. Another thread is responsible for divisibility of 5 and prints"Buzz''. A third threadis responsible for divisibility of 3 and 5 and prints "FizzBuzz''. A fourth thread does the numbers.arrow_forwardCounting hashtags Write Python code to count the frequency of hashtags in a twitter feed. Your code assumes a twitter feed variable tweets exists, which is a list of strings containing tweets. Each element of this list is a single tweet, stored as a string. For example, tweets may look like: tweets = ["Happy #IlliniFriday!", "It is a pretty campus, isn't it, #illini?", "Diving into the last weekend of winter break like... #ILLINI #JoinTheFight", "Are you wearing your Orange and Blue today, #Illini Nation?"] Your code should produce a sorted list of tuples stored in hashtag_counts, where each tuple looks like (hashtag, count), hashtag is a string and count is an integer. The list should be sorted by count in descending order, and if there are hashtags with identical counts, these should be sorted alphabetically, in ascending order, by hashtag. From the above example, our unsorted hashtag_counts might look like: [('#illini', 2), ('#jointhefight', 1),…arrow_forwardC LANGUAGEarrow_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