Question

C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if...

C++

Write a function named “hasDescendingDigits” that accepts a string of numbers. It
returns true if the string contains the digits in descending order. The function can
ignore (e.g. skip checking) all the characters that are not digits in the string. Empty
string will return false.
For example, string of “95421” or “862” or “8622” or “88” or “9” will return true and
string of “95423” or “889” or “9445” or “449” or “” will return false.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.cpp

#include<iostream>

using namespace std;

bool hasDescendingDigits(int n)

{

int wh = n%10;

while (n / 10 > 0)

{

n /= 10;

if (wh > n % 10)

{

return false;

}

wh = n % 10;

}

return true;

}

int main()

{

  int n;

cout<<"Enter numbers without spaces: ";

   cin>>n;

cout<<hasDescendingDigits(n)<<endl;

return 0;

}

Output:

Enter numbers without spaces: 95421 1

Enter numbers without spaces: 449 00

Add a comment
Know the answer?
Add Answer to:
C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...

    1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...

  • 1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...

    1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...

  • 39) Which function accepts two strings as arguments, returns "True" if the first string contains the...

    39) Which function accepts two strings as arguments, returns "True" if the first string contains the second string, and otherwise returns "False"? None of the above Contains Append Substring Concatenate

  • 1. Write a function named “areFirstTwoTheSameAsTheLastTwo” that accepts an array of integers, its size and return...

    1. Write a function named “areFirstTwoTheSameAsTheLastTwo” that accepts an array of integers, its size and return true if the first two numbers in the array are the same as the last two numbers in the array. It returns false otherwise. If the array has less than 4 elements, it always returns false. For example, this array of {10, 20, 30, 40, 10, 20} or {10, 20, 10, 20} will return true but this array of {10, 20, 20, 10} or...

  • in C ++ containsTwice Language/Type: Related Links: Cboolean string caturn stine stlih Write ea function named...

    in C ++ containsTwice Language/Type: Related Links: Cboolean string caturn stine stlih Write ea function named containsTwice that accepts a string and a character as parameters and returns true if that character occurs two or more times in the string. For example, the call of cantainsTaice("helle", 1') should return true because there are two '1' characters in that sto Type your Ce solution code here: C lutson coe here h function cerce e C ntion

  • PYTHON QUESTION PLEASE!! Write a function named problem3 that accepts two strings as the arguments, returns...

    PYTHON QUESTION PLEASE!! Write a function named problem3 that accepts two strings as the arguments, returns the characters that occur in both strings. Test case: the arguments are “apple@123” and “banana@#345”, your program should return “a@3”. Write a function named problem3 that accepts two strings as the arguments, returns the characters that occur in both strings. (20 pts) Test case: the arguments are "apple@123” and “banana@#345”, your program should return "a@3".

  • 1. String Length Write a function that returns an integer and accepts a pointer to a...

    1. String Length Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function’s return value. c++

  • In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s"...

    In C++ 1.Define a function named "sumCodes" that accepts two input parameters: "s "and "pos". "s" is an object of the type "string" and "pos" is a boolean value with the default argument of "true". If "pos" is "true", the function returns the summation of the ASCII codes of all the characters located at the even indices of "s" and if "pos" is "false", the function returns the summation of the ASCII codes of all the characters located at the...

  • Write a program with a function named isEqualArr that accepts a pair of arrays of integers...

    Write a program with a function named isEqualArr that accepts a pair of arrays of integers as parameters and returns true if the arrays contain the same elements in the same order. If the arrays are not the same length, your function should return false. For example, if the following arrays are declared: int[] arr1 = {10, 20, 30, 40, 50, 60}; int[] arr2 = {10, 20, 30, 40, 50, 60}; int[] arr3 = {20, 3, 50, 10, 68}; The...

  • Write a javascript function that accepts 3 arrays and returns a string of the elements sorted...

    Write a javascript function that accepts 3 arrays and returns a string of the elements sorted in ascending value, with duplicates removed. Return all alphabetic characters in lowercase. E.G. function([ 1,2,3, d], [5, 3, 0, ‘a’], [‘a’,’d’,9]) returns “0,1,2,3,5,9,a,d” E.G. function(['w', 'i', 'H', 5], [8, 5, 9, 'c', 'Z'], [6, 4, 'a', 'b', 'y']) returns “4,5,6,8,9,a,b,c,h,i,w,y,z” we must not use ' sort, remove, split,join and any built-in fucntions

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT