Question

In: Computer Science

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data,...

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even.

5. Make the flowchart and the C ++ program that, when receiving N integers as data, obtains only the sum of the positive numbers.

Solutions

Expert Solution

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even.

Answer:

FLOW CHART:

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

#include <iostream>

using namespace std;

int main()
{
//variables declaration.
int num,digit,flag=0,temp;
  
//scan input.
cout<<"Enter four digit number: ";
cin>>num;
temp=num;
while(temp) //conditon temp not equal to zero.
{
digit=temp%10; //take each digit.
if(digit%2==0) //conditon digit is even
{
temp=temp/10; //take remainig numbers after digit checking.
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1) //conditon flag 1 means contain all even digits.
cout<<num<<" contain all even digits.";
else
cout<<num<<" contains odd digts.";
return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:

5. Make the flowchart and the C ++ program that, when receiving N integers as data, obtains only the sum of the positive numbers.

Answer:

FLOW CHART:

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

#include <iostream>

using namespace std;
int main()
{
int N,sum=0,i; //variables declaration.
  
cout<<"Enter how many elements you want: ";
cin>>N;
  
int arr[N];
cout<<"enter elements: ";
for(i=0;i<N;i++) //for loop used to scan elements.
cin>>arr[i];
for(i=0;i<N;i++) //for loop used to traverse each element.
{
if(arr[i]>0) //conditon element is positive.
sum=sum+arr[i]; //calculate sum.
}
cout<<"Sum of positive integers: "<<sum; //print sum.
return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:


Related Solutions

SOLVE IN C: Playing with encryption: Write a program that will read a four-digit integer entered...
SOLVE IN C: Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Playing with encryption: Write a program that will read a four-digit integer entered by the user...
Playing with encryption: Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original...
what is the best code to construct a C++ program that finds a five digit number;...
what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.
Write a C++ program that checks if the password is correct. The password is a 4-digit...
Write a C++ program that checks if the password is correct. The password is a 4-digit number combination. The program repeats to ask the password until the password is correct or you enter -1 to exit. Input: The password is set to ‘1123’. A user input the password to proceed, or -1 to exit. Sample Output: The program should display the following output. (The red text is a user input.) Test case 1: when you enter the correct password. Enter...
Write a program in C that takes as input a four-digit hexadecimal number and prints the...
Write a program in C that takes as input a four-digit hexadecimal number and prints the next 10 hexadecimal numbers. Define a hexadecimal number as int hexNum[4] Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70, 3C71, . . . .
write a c++ program an expression that determines if an integer, n is a negative four...
write a c++ program an expression that determines if an integer, n is a negative four digit number. write a c++ program an expression that determines if a string, wd, equals "so" ignoring case.
In C ++, Design and implement a program that reads from the user four integer values...
In C ++, Design and implement a program that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered:    95, 80, 100, 70 Highest grade: 100 Lowest grade:   70 Average grade: 86.25
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT