Question

In: Computer Science

Implement C++ program for each of the following. Let D = [-48, -14, -8, 0, 1,...

Implement C++ program for each of the following.
Let D = [-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36] Each answer is either True or False. If False, give example
of number(s) that make it False. i.e. The Counterexample. ∀x∈D, if x is odd then x > 0
Let D = [-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36] Each answer is either True or False. If False, give example
of number(s) that make it False. i.e. The Counterexample. ∀x∈D, if x is less than 0 then x is even.
Let D = [-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36] Each answer is either True or False. If False, give example
of number(s) that make it False. i.e. The Counterexample. ∀x∈D, if x is even then x <= 0;
Let D = [-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36] Each answer is either True or False. If False, give example
of number(s) that make it False. i.e. The Counterexample. ∀x∈D, if the ones digit of x is 2, then the tens
digit is 3 or 4.
Let D = [-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36] Each answer is either True or False. If False, give example
of number(s) that make it False. i.e. The Counterexample. ∀x∈D, if the ones digit of x is 6, then the tens
digit is 1 or 2.

Solutions

Expert Solution

The above problem can be solved by following these steps-

STEP 1- We will first declare and initialize the array as given in the question and find out its size so that we can iterate over its elements.

STEP 2- Here we will deal with the first conditon:if x is odd then x > 0. To find out the numbers which do not satisfy this condition, we check if a number is odd or not. If its odd, in the nested if, we check if number>0. If number is greater than 0, move on to next element, otherwise print the number. We also keep a flag variable to keep a count of such counter examples. If we do not get any counter examples, print None as output.

STEP 3- Here we will deal with the second conditon:if x is less than 0 then x is even. To find out the numbers which do not satisfy this condition, we check if a number is less than 0. If yes, in the nested if, we check if number is even or not. If number is even, move on to next element, otherwise print the number. We also keep a flag variable to keep a count of such counter examples. If we do not get any counter examples, print None as output.

STEP 4- Here we will deal with the third conditon:if x is even then x <= 0. To find out the numbers which do not satisfy this condition, we check if a number is even. If yes, in the nested if, we check if number <=0. If number<=0, move on to next element, otherwise print the number. We also keep a flag variable to keep a count of such counter examples. If we do not get any counter examples, print None as output.

STEP 5- Here we will deal with the fourth conditon:if the ones digit of x is 2, then the tens digit is 3 or 4. To find out the numbers which do not satisfy this condition, we check if ones digit is 2. If yes, in the nested if, we find out the tens digit and check if it is 3 or 4. If yes, move on to next element, otherwise print the number. We also keep a flag variable to keep a count of such counter examples. If we do not get any counter examples, print None as output.

STEP 6- Here we will deal with the fourth conditon:if the ones digit of x is 6, then the tens digit is 1 or 2. To find out the numbers which do not satisfy this condition, we check if ones digit is 6. If yes, in the nested if, we find out the tens digit and check if it is 1 or 2. If yes, move on to next element, otherwise print the number. We also keep a flag variable to keep a count of such counter examples. If we do not get any counter examples, print None as output.

C++ Code-

#include <bits/stdc++.h>
using namespace std;
//driver method
int main()
{
//initialize the array of numbers
int D[] = {-48, -14, -8, 0, 1, 3, 16, 23, 26, 32, 36};
//calculate the size of array
int size = sizeof(D)/sizeof(D[0]);
  
cout<<"\nExample of number(s) that make condition \"If x is odd, then x>0\" false.\n";
//if x is odd, then x>0
int flag = 0; //flag to keep a count of numbers not satisfying the condition
//iterate over all the elements
for(int i = 0;i<size;i++){
//if number x is odd
if(D[i]%2 == 1){
//then, number x>0
//nested if
if(D[i]>0){
//do nothing as the number satisfies the condition
continue;
}
else{
//increment flag and print the number
flag++;
cout<<D[i]<<endl;
}
}
}
//if all numbers satisfy the condition, that means flag is 0, print none as output
if(flag == 0){
cout<<"None\n\n";
}
  
  
flag = 0; //flag to keep a count of numbers not satisfying the condition
cout<<"\nExample of number(s) that make condition \"If x is less than 0, then x is even\" false.\n";
//if x is less than 0, then x is even
//iterate over all the elements
for(int i = 0;i<size;i++){
//if number x is less than 0
if(D[i]<0){
//then number x is even
//nested if
if(D[i]%2 == 0){
//do nothing as the number satisfies the condition
continue;
}
else{
//increment flag and print the number
flag++;
cout<<D[i]<<endl;
}
}
}
//if all numbers satisfy the condition, that means flag is 0, print none as output
if(flag == 0){
cout<<"None\n\n";
}
  
  
flag = 0; //flag to keep a count of numbers not satisfying the condition
cout<<"\nExample of number(s) that make condition \"If x is even then x <= 0\" false.\n";
//if x is even then x <= 0
//iterate over all the elements
for(int i = 0;i<size;i++){
//if x is even
if(D[i]%2 == 0){
//then x<=0
//nested if
if(D[i]<=0){
//do nothing as the number satisfies the condition
continue;
}
else{
//increment flag and print the number
flag++;
cout<<D[i]<<endl;
}
}
}
//if all numbers satisfy the condition, that means flag is 0, print none as output
if(flag == 0){
cout<<"None\n\n";
}
  
  
flag = 0; //flag to keep a count of numbers not satisfying the condition
cout<<"\nExample of number(s) that make condition \"If the ones digit of x is 2, then the tens digit is 3 or 4\" false.\n";
//if the ones digit of x is 2, then the tens digit is 3 or 4.
//iterate over the elements
for(int i = 0;i<size;i++){
//if ones digit is 2
if(D[i]%10 == 2){
int number = D[i];
number/=10; //divide the number by 10 to remove ones digit
//then tens digit is 3 or 4
//nested if
if(number%10 == 3 || number%10 == 4){
//do nothing as the number satisfies the condition
continue;
}
else{
//increment flag and print the number
flag++;
cout<<D[i]<<endl;
}
}
}
//if all numbers satisfy the condition, that means flag is 0, print none as output
if(flag == 0){
cout<<"None\n\n";
}
  
flag = 0; //flag to keep a count of numbers not satisfying the condition
cout<<"\nExample of number(s) that make condition \"If the ones digit of x is 6, then the tens digit is 1 or 2\" false.\n";
//if the ones digit of x is 6, then the tens digit is 1 or 2.
//iterate over elements of array
for(int i = 0;i<size;i++){
//if ones digit is 6
if(D[i]%10 == 6){
//remove ones digit and then taking mod 10 will give us tens digit
int number = D[i];
number/=10;
//then tens digit is 1 or 2
//nested if
if(number%10 == 1 || number%10 == 2){
//do nothing as the number satisfies the condition
continue;
}
else{
//increment flag and print the number
flag++;
cout<<D[i]<<endl;
}
}
}
//if all numbers satisfy the condition, that means flag is 0, print none as output
if(flag == 0){
cout<<"None\n\n";
}
  
  
return 0;
}

To help in better understanding of comments and indentation, given below is image of code -


OUTPUT-

If this answer helps, please give an up vote and Feel free to comment for any query.


Related Solutions

3. Let A = D + 1, B = D − 3, C = D +...
3. Let A = D + 1, B = D − 3, C = D + x, where D = dx. Calculate the differential operators AB, BC, CA and their effect on y(x) = e^3x
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d...
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d =[7, 1, 7] e = [3, -5, 2, 1] f =[5, -7, -3, 6] g = [3, -4, 4, 3] P = Projection of ex. C = |g|(gf/gf) C = gf/|f| ex. P g --> f = Cgf = C(gf/f) (1/|f|) (f) =( gf/ff)(f) Find a. Pg --> f b. Pa --> 3b + e Find (cross multiply) a. ||a X b|| b. ||g...
Let C be the following matrix: C=( 1 2 3 -2 0 1 1 -2 -1...
Let C be the following matrix: C=( 1 2 3 -2 0 1 1 -2 -1 3 2 -8 -1 -2 -3 2 ) Give a basis for the row space of Cin the format [1,2,3],[3,4,5], for example.
a b c d f 0 0 0 0 0 0 0 0 1 0 0...
a b c d f 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 0 1...
Differential Equations 22. Solve each of the following systems of equations. (c) (D-2)x=0; -3x+(D+2)y=0; -2y+(D-3)z=0 I...
Differential Equations 22. Solve each of the following systems of equations. (c) (D-2)x=0; -3x+(D+2)y=0; -2y+(D-3)z=0 I got x=c1e2t, y= 3/4 C1e2t + C2e-2t by using diffieq method d/dx(ye2t) = 3C1e2t....., but the right answer is x=4c1e2t, y= 3C1e2t + 5C2e-2t , z= -6C1e2t -2C2e-2t+C3e3t I want to know where 4 came from, and please do not use matrix system.
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings....
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings. Assume that any char array passed into the functions will contain valid, null-terminated data. The functions must have the signatures listed below. 1. This function returns the last index where the target char can be found in the string. it returns -1 if the target char does not appear in the string. For example, if s is “Giants” and target is ‘a’ the function...
For each n ∈ N, let fn : [0, 1] → [0, 1] be defined by...
For each n ∈ N, let fn : [0, 1] → [0, 1] be defined by fn(x) = 0, x > 1/n and fn(x) = 1−nx if 0 ≤ x ≤1/n. The collection {fn(x) : n ∈ N} converges to a point, call it f(x) for each x ∈ [0, 1]. Show whether {fn(x) : n ∈ N} converges to f uniformly or not.
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1....
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1. Accept a message as keyboard input to your program. 2. Accept a secret key for the sender/recipient as keyboard input to your program. 3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85...
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
Let C be the closed path that travels from (0, 0) to (1, 1) along y...
Let C be the closed path that travels from (0, 0) to (1, 1) along y = x^2 , then from (1, 1) to (0, 2) along y = 2 − x^ 2 , and finally in a straight line from (0, 2) to (0, 0). Evaluate Z C e ^3−x √ 3 − x ) dx + (5x − y √ y^2 + 2) dy
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT