Please find the code below with detailed inline comments.
CODE
=========================
#include <iostream>
#include <cstring>
#define SIZE 4 // CONSTANT to represent the size of the number`
using namespace std;
int main() {
string number_str;
cout << "Enter a 4-digit number: ";
getline(cin, number_str);
int length = number_str.length(); // stores the length of the input
string
// the length of the input string is less than 4
if(length < SIZE) {
cout << "Error.... the number has less than 4 digits!!"
<< endl;
}
// the length of the input string is greater than 4
else if(length > SIZE) {
cout << "Error.... the number has more than 4 digits!!"
<< endl;
}
int number = 0; // represent the numerical value of the input
string
// loop through all the characters of the input string
for(int i=0; i<number_str.length(); i++) {
int digit = number_str[i] - '0';
// the character is not a digit, print error message
if(digit < 0 || digit > 9) {
cout << "Error.... the given string is not a valid number!!"
<< endl;
return 0;
}
// update the number value
number = number * 10 + digit;
}
// print the output
cout << "The output is: " << endl;
cout << number + number << ", " << number_str +
number_str;
return 0;
}
OUTPUT
=========================
C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention...
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...
c++ pleased Assignment 6a (15 points] - Character and String related processing... Listed below are two interesting programming challenges that will require a bit of character and/or string related processing with functions. (Carefully read the specifications for each programming challenge and select ONE.) (1) Sum of Digits in a String Write a program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program...
Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...
Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...
In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....
Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...
This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global Edition, 10/E) Question Do Programming Project 7 in Chapter 7 using a dynamic array. In this version of the problem, use dynamic arrays to store the ditits in each large integer. Allow an arbitrary number of digits instead of capping the number of digits at 20. TER 7/ Arrays time. For example digit at a the integer 1234 could be stored in the array...
C language please 2. You are to write a subroutine/function which will expect a string as input. The function should locate any instances of multiple space characters together. The function should modify the string to replace all mulktiple-space blocks with single spaces. No non-space characters should be altered Example: The string "Bob has twelve has twelve apples." apples." should be altered to become "Bob
In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...
1.In Chapter 4, we developed an algorithm for converting from binary to decimal. You can generalize this algorithm to work for a representation in any base. Instead of using a power of 2, this time you use a power of the base. Also, you use digits greater than 9, such as A . . . F, when they occur.In convert.py, define a function named repToDecimal that expects two arguments, a string, and an integer. The second argument should be the base....