Implement a program to compute the sum of all digits

Assignment Help C/C++ Programming
Reference no: EM132388422

Methods

Exercise #1: Design and implement a program (name it SumDigits) to compute the sum of all digits in an integer number. The program defines the following method:

Method sumDigits (int number) returns the sum of all digits in number.

In the main method, prompt the user for an integer input and pass the input to method sumDigits() to obtain the sum of its digits. Then display the entered number followed by the sum of its digits as shown below. Document your code and properly label the input prompt and the outputs as shown below.

Sample run 1:

You entered: 12345
Sum of digits: 15

Sample run 2:

You entered: 78501
Sum of digits: 21

Sample run 3:

You entered: 9000
Sum of digits: 9

Exercise #2: Design and implement a program (name it PrintCharacters) to print the characters between a start character and an end character specified by the user. The start character must come before the end character. For example, we can display all characters between character F and character W, but not the other way around. The program defines the following method:

Method printChars (char ch1, char ch2) prints all characters between ch1 and ch2, inclusive.

In the main method, prompt the user to enter the start character and end characters, validate the entered characters are in order, then call method printChars(). Display the character 5 per line. Document your code and properly label the input prompts and the outputs as shown below.

Sample run 1:

Start character: A
End character: L
Output:
A B C D E
F G H I J
K L

Sample run 2:

Start character: W
End character: c
Output:
W X Y Z [
\ ] ^ _ ‘
a b c

Sample run 3

Start character: B
End character: 5
Output: start and end characters are out of order. Try again.

Exercise #3 Guess the Number

Write a "Guess the Number" game that randomly assigns a secret number [1,20] for the user to guess. I recommend hard coding your secret number at first to make testing your code easier. You can write this a number of ways, but try to stick to the instructions outlined here.

Write three methods to make your game work.
• The first method should generate a random number and return the value to main to store in the secret number variable.
• The second method should ask your user what his first guess is. Return this information to main.
• The third method should take in the guess and the secret number via parameters, then evaluate whether or not the quess is correct. Return a string to let the user know if their guess was too high, too low, or correct.

You will need a nested loop in main. You'll want the outer loop to ask if the user wants to play again. You'll also need to think about how to include an inner loop that continues to call the third method until the user guesses correctly.

Attachment:- Programming and Problem Solving.rar

Reference no: EM132388422

Questions Cloud

Area under the normal curve : What are the Z values of the limits of the area covering the middle of 25% of the area under the normal curve?
Stock prices are normally distributed : Assume the stock prices are normally distributed. How high does a stock price have to be to put a company in the bottom 2.5%?
Research on some initiatives and security measures : Conduct research on some initiatives and security measures that have been taken in the aviation industry. Are these measures successful, why or why not?
Who is responsible for making the decision : Use your training in economics and business to address the problems. As a consultant, you need to first make sure you are familiar with the company.
Implement a program to compute the sum of all digits : Design and implement a program (name it SumDigits) to compute the sum of all digits in an integer number. The program defines the method
Conducting the hypothesis tests : Identify the appropriate test statistic, or statistics, (and degrees of freedom if possible) for conducting the hypothesis tests and state why you use that test
Significant t-statistic for the one-tailed test : What will be the significant t-statistic for the one-tailed test and what will it be for the two-tailed test? Show your work.
Probability of drawing a spade : Draw a histogram that graphs the probability of drawing a spade, a heart, a diamond or a club from a normal deck of 52 cards.
Determine a p-value for the test statistic : Suppose that we are testing a null hypothesis vs an alternative hypothesis and we determine a p-value for the test statistic of 0.029.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd