1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Archy [21]
3 years ago
13

The homework is based on E5.3, write a program that has the following methods. a. int firstDigit(int n) , returning the first di

git of the argument b. int lastDigit(int n) , returning the last digit of the argument c. int digits(int n) , returning the number of digits of the argument For example, firstDigit(1729) is 1, last digit(1729) is 9, and digits(1729) is 4. d. a main method that i) ask the user to input a non-negative integer ii) print out the number of digits, the first digit and the last digit of the input by calling the methods you defined iii) repeat the above process (i and ii) until the user input a negative number
Computers and Technology
1 answer:
Nat2105 [25]3 years ago
4 0

Answer:

C++ code is explained

Explanation:

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

int firstDigit(int n){

// Converting int to string

ostringstream convert;

convert << n;

string s = convert.str();

char first_char = s[0];

int first_int = first_char - '0';

return first_int;

}

int lastDigit(int n){

// Converting int to string

ostringstream convert;

convert << n;

string s = convert.str();

char last_char = s[s.length() - 1];

int last_int = last_char - '0';

return last_int;

}

int digits(int n){

// Converting int to string

ostringstream convert;

convert << n;

string s = convert.str();

int length = s.length();

return length;

}

int main() {

int number;

cout << "Enter integer: " << endl;

cin >> number;

cout << "The first digit of the number is " << firstDigit(number) << endl;

cout << "The last digit of the number is " << lastDigit(number) << endl;

cout << "The number of digits of the number is " << digits(number) << endl;

}

You might be interested in
The rules of right-of-way<br> Pedestrians, bicyclists, and skateboarders<br> when they use the road.
lorasvet [3.4K]

Whenever you are driving and you see a pedestrian, bicyclist, or skateboarder, they always have the right of way, no matter the scenario. Always give bikers 3-4 feet if possible between them and your vehicle when passing them, and always be careful around skateboarders.

I hope this helped you! Have a great day!

7 0
3 years ago
One microsleep warning sign occurs when you catch yourself leaning blank in the drivers seat
mariarad [96]
The answer is Forward.
One microsleep warning sign occurs when you catch yourself leaning <span>Forward in the drivers sea.</span> Microsleeping while driving is surprisingly common and according to surveys, at least 10 percent admitted to having slept briefly while at the wheel. A person is likely to fall asleep when he or she is the driver of the vehicle and may likely lean forward because the individual does not have anything to lean on but only the steering wheel.<span />



4 0
4 years ago
Late at night, some traffic signals change patterns and become _____.
SCORPION-xisa [38]
The answer is B.

Late at night, some traffic signals change patterns and become flashing yellow or red lights.
4 0
4 years ago
Read 2 more answers
MmfbfMMMMMMMMMMMMMMMMMmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Mumz [18]

Explanation:

bdhabsusvsjsvdhewjsbdueyssbwksv

6 0
3 years ago
What should I put on a college application?⊕
gizmo_the_mogwai [7]

Answer:

Student Government. ...

Academic Teams and Clubs. ...

The Debate Team. ...

The Arts. ...

Internships. ...

Culture Clubs. ...

Volunteer Work and Community Service. ...

The Student Newspaper.

Explanation:

8 0
4 years ago
Other questions:
  • When you see a blank pointer this means you can drag the row or column border to change height or width
    14·1 answer
  • What is the code for loading image in matlab
    15·1 answer
  • Match the definition with the corresponding word
    12·2 answers
  • Which function will show 6 as the answer in the following formula<br><br> =_ (36)
    10·1 answer
  • When converting the relationships to the relational model and the database schema, it is possible that some of the relationships
    15·1 answer
  • What software could i use to create music like Aphex Twin?
    6·1 answer
  • Please can someone help me with this?
    6·1 answer
  • Como se diseña y produce un material audiovisual
    5·1 answer
  • 3. Output the following:<br>a.<br>21%4​
    12·1 answer
  • After months of hard work, the big day has finally arrived, and your software will be produced and distributed. Which phase of t
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!