Write a program to: (i) Input the ISBN code as a10-digiti integer.(ii) If the ISBN is not a 10 - digit integer , out put the message “IllegalISBN” and terminate the program.(iii) If the number is 10 - digit, extract the digit so if the number and compute the sum .If the sum is divisible by 11,out put the message,“LegalISBN”.If the sum is not divisible by 11,out put the message,“IllegalISBN”.
Answers
Answer:
Note: I am using C++ programming language.
#include<iostream>
using namespace std;
//function to calculate number of digits
int countDigit(long long n)
{
int count = 0;
while (n != 0) {
n = n / 10;
++count;
}
return count;
}
//This class is for calculating the sum of digits.
class digit_sum
{
public:
int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
};
int main () {
digit_sum ds ;
long long isbn;
cout<<"Enter ISBN number : ";
cin>>isbn;
if( countDigit(isbn) != 10 ){
cout<<"Illegal ISBN! " ;
}
else {
int sum_of_digit = ds.getSum(isbn) ;
if( sum_of_digit %11 == 0 ){
cout<<"Legal ISBN. " ;
}
else {
cout<<"Illegal ISBN. " ;
}
}
return 0;
}
Please follow me and mark this ans as Branliest answer.Thank you!