Question

In: Computer Science

C++ Plan and code a program utilizing one or more repetition structures to solve the following...

C++

Plan and code a program utilizing one or more repetition structures to solve the following problem:

Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. A number is a multiple of 9 if the sum of its digits is evenly divisible by 9. Determine if a number is a multiple of 9 by adding together the individual digits of the number and determining if the sum of the digits is evenly divisible by 9. Input should be limited to numbers from 1 through 1000.

Check your solution with valid and invalid data. Use good program design, efficient code, and document your code with explanatory comments throughout.

Be sure to include adequate error handling in your program and error data when you run the program to demonstrate error handling.

Input

One or more numbers entered by a user.

Output

The input number, the sum of its digits. and whether the number is a multiple of 9 or not.

Solutions

Expert Solution

ANSWER - C++ code pasted below.

#include <iostream>
using namespace std;
void sumofdigits(int x)
{
//initialize sum to 0 and take a copy of a to a1
int sum=0;
int a1=x,digit;
//continously divide x by 10 to get the remainder until x reaches 0
while(x!=0){
//taking the digit
digit=x%10;
//adding the sum with digit
sum=sum+digit;
//dividing the number with 10 to remove the last digit
x=x/10;
}
if(sum%9==0)
cout<<a1<<" is a multiple of 9"<<endl;
else
cout<<a1<<" is not a multiple of 9"<<endl;
}

//main progarm
int main()
{ int a, b, c;
// Reading three numbers a, b, c
cout<<"Enter three numbers between 1 and 1000:";
cin>>a>>b>>c;
//checking whether the nunbers are in the range 1--1000
if(a<1 || a>1000){
cout<<"Number "<<a<<" is out of range!..Enter a number between 1 and 1000";
return 0;
}
  
if(b<1 || b>1000){
cout<<"Number "<<b<<" is out of range!..Enter a number between 1 and 1000";
return 0;
}
  
if(c<1 || c>1000){
cout<<"Number "<<c<<" is out of range!..Enter a number between 1 and 1000";
return 0;
}
//function calling for a
sumofdigits(a);
//function calling for b
sumofdigits(b);
//function calling for c
sumofdigits(c);
return 0;   
}
  

Output Screen- Test case 1

Output Screen - Test case 2


Related Solutions

Programing lanugaue is C++ Purpose of code: Plan and code a menu-driven modular program utilizing an...
Programing lanugaue is C++ Purpose of code: Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able to understand and use linear interpolation in a program. Modify/Extend an existing program. Problem Description: Linear Interpolation There are two credit levels for this assignment. Completing the “B” level correctly is worth 16/20 points, completing the “A” level is worth 20/20. You are encouraged to get the code for the “B” level working first and then complete the “A” level if you have time/interest....
Using C++ Write One one single program with two or more functioncallsWrite a C++...
Using C++ Write One one single program with two or more function callsWrite a C++ function, smallest Index, that takes as parameters an int array and its size and returns the index of the smallest element in the array. Also the program should test the function.Write another function that prompts the user to input a string and outputs the string in uppercase letters. You must use a character array to store the string.
There are at least five (probably more) places in the attached C# program code that could...
There are at least five (probably more) places in the attached C# program code that could be optimized. Find at least five things in the Program.cs file that can be changed to make the program as efficient as possible. List five problems you found with the code (Put your list either in comments within the code or in a separate Word or text document), and then optimize the code in the attached code below to make it as efficient as...
Need C++ code for following with a document describing the code as well: Write a program...
Need C++ code for following with a document describing the code as well: Write a program to implement the game of Tic Tac Toe Four. The game is played on a 4 × 4 chessboard, within 2 players. The player who is playing "X" always goes first. Players alternate placing Xs and Os on the board until either one player has four in a row, horizontally, vertically, or diagonally; or all 16 squares are filled(which is a draw). The program...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std;...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std; void leapYear(int x); int main() { int x; cout << "Enter a year: "; cin >> x; leapYear (x);   return 0; } void leapYear(int x ) {    if (x % 400 == 0)    {    cout << "This is a leap Year";}    else if    ((x % 4 == 0) && (x % 100 != 0))    {    cout <<...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
C++ Use BinaryNodeTree to solve the following questions in a program: 1) What is the value...
C++ Use BinaryNodeTree to solve the following questions in a program: 1) What is the value of the prefix expression +−∗ 235/↑ 2 3 4? 2) What is the postfix form of the expression ((x + y) ↑ 2) + ((x − 4)/3)? 3) What is the value of the postfix expression723 ∗ − 4 ↑ 9 3/+?
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT