Please provide “proof” screenshot for the program with it compiled ( i have a sa
ID: 3871690 • Letter: P
Question
Please provide “proof” screenshot for the program with it compiled ( i have a sample ouput but still would like the screeshot) and please copy and paste the source code with your reply so I can put it into my compiler. I have the code below, so fill out the areas where it says "student provides missing code". Please use C++ programming only
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
//-----------------------------------------------------
int main()
//-----------------------------------------------------
{
bool IsArmstrongNumber(int x);
int LB,UB,x;
printf("LB? "); scanf("%d",&LB);
printf("UB? "); scanf("%d",&UB);
Student provides missing code to traverse range [ LB,UB ] to display all
Armstrong Numbers found in the range.
system("PAUSE");
return( 0 );
}
//-----------------------------------------------------
bool IsArmstrongNumber(int x)
//-----------------------------------------------------
{
// Pre-condition (x >= 0)
int NumberOfDigits(int x);
int DthDigitOfX(int x,int d);
int sum,d;
auto int n = NumberOfDigits(x);
Student provides missing code which returns true when x is
an Armstrong Number, otherwise returns false.
}
//-----------------------------------------------------
int NumberOfDigits(int x)
//-----------------------------------------------------
{
// Pre-condition (x >= 0)
int r = 0;
do
{
r++;
x /= 10;
}
while ( x != 0 );
return( r );
}
//-----------------------------------------------------
int DthDigitOfX(int x,int d)
//-----------------------------------------------------
{
// Pre-conditions (x >= 0) and (1 <= d <= 10)
/*
d is interpreted as follows
1
d = 0,987,654,321
x = X,XXX,XXX,XXX
For example, when x = 153, d = 1 (returns 3), d = 2 (5), d = 3 (1), and d > 3 (returns 0).
*/
Student provides missing code to return the d-th digit of x.
}
Introduction The n-digit integer x is an Armstrong number when x is equal to the sum of each of its digits raised to the n th power. For example, 15313 5333 820884+ 2 + 04 + 8° Problem Allow the user to input a lower bound, LB, and an upper bound, UB, such that (0 s LB display all Armstrong numbers found in the range LB,UB using the format UB), then 123456789012345678901234567890123 XxxxxxxXX is an Armstrong number Sample Program Dialo 1PE4Lexe 1 is an Arnstrong nunber 2 is an Ar strong nunber 3 is an rns trong nunber 4 is an Arnstrong nunber 5 is an Arnstrong nunber 6 is an Arnstrong nunber ? is an Arnstrong nunber 8 is an Arnstrong nunber 9 is an Arnstrong nunber 153 is an Arnstrong nunber 370 is an Arnstrong nunber 371 is an Arnstrong nunber 187 is an Armstrong nunber 1634 is an Arnstrong nunber 8208 is an Amstrong nunber. 9474 is an r"strong nunber 54248 is an Arnstrong nunber 92727 is an Ar strong nunbe3° 93084 is an Arnstrong nunber 548834 is an Arnstrong nunber 1741725 is an Arf,strong nunber 4210818 is an Ar strong nunber 980881 is an Arnstrong nunber 9926315 is an Arnstrong nunber 24678858 is an Arnstrong nunber 24678051 is an Armstrong nunber 8859342? is an Arnstrong nunber 146511288 is an Arnstrong nunber 172335975 is an Arnstrong nunber 534494836 is an Armstrong nunber 912985153 is an Arm; trong nunbe ress any key to continue ···Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
//-----------------------------------------------------
//Main function definition
int main()
//-----------------------------------------------------
{
//Prototype for the function
bool IsArmstrongNumber(int x);
//To store lower bound, upper bound and loop variable
int LB,UB,x;
//Accept lower bound
cout<<"LB? ";
cin>>LB;
//Accept upper bound
cout<<"UB? ";
cin>>UB;
//Student provides missing code to traverse range [ LB,UB ] to display all
// Armstrong Numbers found in the range.
//Loops from lower bound to upper bound
for(x = LB; x <= UB; x++)
{
//Checks for Armstrong number
if(IsArmstrongNumber(x))
//If function returns true display the number as Armstrong number
std::cout << std::right << std::setw(13)<<x<<" is an Armstrong number."<<endl;
}//End of for loop
//Pause for any key to press
system("PAUSE");
return( 0 );
}//End of main method
//-----------------------------------------------------
//Function return true if the number x is Armstrong number otherwise returns false
bool IsArmstrongNumber(int x)
//-----------------------------------------------------
{
// Pre-condition (x >= 0)
//Prototype for the functions to calculate and return number of digits
int NumberOfDigits(int x);
//Prototype for the function to return the digit of number x at d position
int DthDigitOfX(int x,int d);
//To store the total, to store power and d is loop variable
int sum = 0, power, d;
//Calls the function to calculate number of digits and stores it in n
auto int n = NumberOfDigits(x);
// Student provides missing code which returns true when x is an Armstrong Number, otherwise returns false.
//Loops 1 to number of digits
for(d = 1; d <= n; d++)
{
//Initializes power to one
power = 1;
//Loops 1 to number of digits to calculate the power of the digit i.e., d to the power n
for(int c = 1; c <= n; c++)
power *= DthDigitOfX(x, d);
//Calculates the total of the power
sum = sum + power;
}//End of outer for loop
//Checks if the number is equal to sum then return true otherwise false
if(x == sum)
return true;
else
return false;
}//End of function
//-----------------------------------------------------
//Functions to calculate and return number of digits
int NumberOfDigits(int x)
//-----------------------------------------------------
{
// Pre-condition (x >= 0)
//Initializes the r to zero for number of digits
int r = 0;
//Loops till n is not equals to zero
do
{
//Increase the r value by one
r++;
//Stores the quotient of the number x in x
x /= 10;
} while ( x != 0 );
//Returns number of digits
return (r);
}//End of function
//-----------------------------------------------------
//Function to return the digit of number x at d position
int DthDigitOfX(int x, int d)
//-----------------------------------------------------
{
// Pre-conditions (x >= 0) and (1 <= d <= 10)
/* d is interpreted as follows
1
d = 0,987,654,321
x = X,XXX,XXX,XXX
For example, when x = 153, d = 1 (returns 3), d = 2 (5), d = 3 (1), and d > 3 (returns 0).
*/
//To store digit of a number
int digit;
//Loops till the digit position d
for(int c = 0; c < d; c++)
{
//Calculate the remainder for the position d
digit = x % 10;
//Stores the quotient of the number x in x
x /= 10;
}//End of for loop
//Returns the digit at d position
return digit;
}//End of function
Sample Run 1:
LB? 1
UB? 1000000
1 is an Armstrong number.
2 is an Armstrong number.
3 is an Armstrong number.
4 is an Armstrong number.
5 is an Armstrong number.
6 is an Armstrong number.
7 is an Armstrong number.
8 is an Armstrong number.
9 is an Armstrong number.
153 is an Armstrong number.
370 is an Armstrong number.
371 is an Armstrong number.
407 is an Armstrong number.
1634 is an Armstrong number.
8208 is an Armstrong number.
9474 is an Armstrong number.
54748 is an Armstrong number.
92727 is an Armstrong number.
93084 is an Armstrong number.
548834 is an Armstrong number.
Sample Run 2:
LB? 1
UB? 100000000
1 is an Armstrong number.
2 is an Armstrong number.
3 is an Armstrong number.
4 is an Armstrong number.
5 is an Armstrong number.
6 is an Armstrong number.
7 is an Armstrong number.
8 is an Armstrong number.
9 is an Armstrong number.
153 is an Armstrong number.
370 is an Armstrong number.
371 is an Armstrong number.
407 is an Armstrong number.
1634 is an Armstrong number.
8208 is an Armstrong number.
9474 is an Armstrong number.
54748 is an Armstrong number.
92727 is an Armstrong number.
93084 is an Armstrong number.
548834 is an Armstrong number.
1741725 is an Armstrong number.
4210818 is an Armstrong number.
9800817 is an Armstrong number.
9926315 is an Armstrong number.
24678050 is an Armstrong number.
24678051 is an Armstrong number.
88593477 is an Armstrong number.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.