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...
Original C code please. Part 1: You can do A, B, and C in one program...
Original C code please. Part 1: You can do A, B, and C in one program with multiple loops (not nested) or each one in a small program, it doesn’t matter. A. Create a loop that will output all the positive multiples of 9 that are less than 99. 9 18 27 36 45        …. B. Create a loop that will output all the positive numbers less than 200 that are evenly divisible by both 2 and 7. 14        28       ...
Write in C Language Write all these code in one program and upload. Consider this array...
Write in C Language Write all these code in one program and upload. Consider this array char address1 [ ] = "12330 Washington Blvd, suite 300, Sacramento, CA 94560-2341" ; (NOTE: The constant string on the RHS gets copied into the array address1 on the LHS) 1. Write a piece of code to count only letters in the string address1 using the function isAlpha   2. Convert to all Upper Case Write a program to convert address1 to all uppercase letters...
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 <<...
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/+?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT