Question

How to write this code in C++???? using fstream Write a program which: Asks the user...

How to write this code in C++????

using fstream

Write a program which:

Asks the user to enter a positive integer greater than 0

Validates that the entry is a positive integer

Outputs the digits in reverse order with a space separating the digits

Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even)

If there are no even digits, the an appropriate message should be displayed: There are no even digits

Outputs the odd digits not in reverse order with a space separating the digits

If there are no odd digits, the an appropriate message should be displayed: There are no odd digits

Allows user is to repeat/continue the program as many times as he/she wants

Keeps a record in a txt file named outDataFile.txt with the history of all numbers entered and the associated results, in the following format:

the original number is 1234
the number reversed 4 3 2 1
the even digits are 2 4
the odd digits are 1 3
-----------------
the original number is 135
the number reversed 5 3 1
There are no even digits
the odd digits are 1 3 5
-----------------
the original number is 862
the number reversed 2 6 8
the even digits are 8 6 2
There are no odd digits
-----------------

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

#include <iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int main()
{
char s[1000000];
int k=0,l=0;
cout<<"enter the no. greater than 0"<<endl;
gets(s);
int n=strlen(s);
cout<<"the reversed digits";
for(int i=n-1;i>=0;i--)
{
cout<<s[i]<<" ";

}
cout<<endl;
for(int j=0;j<n;j++)

{
if(s[j]%2==0)
k++;
else
l++;

}
if (k==0)
cout<<"there are no even numbers";
else
{

cout<<"the even digits are ";
for(int j=0;j<n;j++)

{
if(s[j]%2==0)
cout<<s[j]<<" ";
}
cout<<endl;
}
if (l==0)
cout<<"there are no odd numbers ";
else
{
cout<<"the odd digits are ";
for(int j=0;j<n;j++)
{
if(s[j]%2!=0)
cout<<s[j]<<" ";
}

}
}

output

enter the no. greater than 0
12345
the reversed digits5 4 3 2 1
the even digits are 2 4
the odd digits are 1 3 5

Add a comment
Know the answer?
Add Answer to:
How to write this code in C++???? using fstream Write a program which: Asks the user...
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
  • use C++ please 1. Vowels and Consonants Write a program that asks the user to input...

    use C++ please 1. Vowels and Consonants Write a program that asks the user to input three different integers. Write a function called numberStyle for this program that will accept each integer (one at a time) and return the following . If the integer is even, return 1 . If the integer is odd, return -1 . If the integer is zero, return O In main, after calling the function output the appropriate message describing the integers ing the function...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • I need to revise a c++ code that asks to: enter up to 5 digits positive...

    I need to revise a c++ code that asks to: enter up to 5 digits positive integer number, then reverse the order of the digits. The program outputs both numbers and calculates their square roots in the following way Please enter a 5-digits integer: ( inputs 56789) output as follow The square root of 566789 is: The number in reverse is: 98765 The square root of the reversed number 98765 is:

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number...

    NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number ( the user should input any integer number, say N), then the program outputs N if N is even; or N+3 if N is odd ( note: the output is always even) Example: Enter any number: 25 Even output is: 28 Another example: Enter any number: 32 Even output is: 32.

  • Write a program in Python that asks the user for the ISBN of the book in...

    Write a program in Python that asks the user for the ISBN of the book in the format xxx-x-xxx-xxxxx-x. To validate: Initialize a total to 0 Have the program remove the dashes so that only the 13 digits are left in the ISBN string for each index of the first 12 digits in the 13 digit ISBN string get the digit at the current index as an integer If the current index is an even number, add the digit to...

  • Write code that prompts the user to input a number. The program should then output the...

    Write code that prompts the user to input a number. The program should then output the number and a message saying whether the number i "Positive, "Negative" or "Zero". It should further output whether the number is odd or even (zero is counted as even) For example:

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • Write a program to reverse an integer number by using a function called reverse. The program...

    Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...

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