Question

In: Computer Science

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.

Solutions

Expert Solution

Here are the answers for your questions in C++ Programming Language.

Kindly upvote if you find the answer helpful.

#########################################################

CODE :

Question : write a c++ program an expression that determines if an integer, n is a negative four digit number.

#include<iostream>

using namespace std;

int main(){
   //Required variable
   int n;
  
   //Read value from user(assuming user eners valid value)
   cout << "Enter an integer: ";
   cin >> n;
  
   //Expression to determine if 'n' is a negaive four digit number
   if(n >= -9999 && n <= -1000){
       cout << "Given integer " << n << " is a negative four digit number." << endl;
   }else{
       cout << "Given integer " << n << " is NOT a negative four digit number." << endl;
   }
   return 0;
}

##############################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

##########################################################################

OUTPUT :

#########################################################################

CODE :

Question : write a c++ program an expression that determines if a string, wd, equals "so" ignoring case.

#include<iostream>
#include<strings.h>

using namespace std;

int main(){
   //Required variable
   string wd;
  
   //Reading input from user
   cout << "Enter a string: ";
   cin >> wd;
  
   //Expression to determise the string wd equals 'so' ignoring case
   if(strcasecmp(wd.c_str(),"so")== 0){
       cout << "Given string equals 'so'." << endl;
   }else{
       cout << "Given string doesn't equal 'so'." << endl;
   }
   return 0;
}

####################################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

########################################################################

OUTPUT :

Any doubts regarding this can be explained with pleasure :)


Related Solutions

Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
Write a program that reads n integer values. If a negative value is entered, we want...
Write a program that reads n integer values. If a negative value is entered, we want to terminate the input, i.e., exit from the loop. If a zero value is entered, we want to ignore it and read the next value. Any strictly positive values (greater or equal zero) are to be totaled. Print the number of values read, the number of values totaled and the total. If a negative value is entered, print an error message before terminating the...
Write a program in C or in Java, that takes an integer value N from the...
Write a program in C or in Java, that takes an integer value N from the command line, generates N random points in the unit square, and computes the distance separating the closest pair of points. A unit square is a square with sides of length 1, at points (0, 0), (0, 1), (1, 0), and (1, 1). If you wish to avoid the command-line processing, you can just assume you will generate a fixed number of points, say between...
Write a C++ program that will take and validates from the user an integer n between...
Write a C++ program that will take and validates from the user an integer n between 1 and 4. The program will then continue by taking 5 characters from the user. The program will ask the user whether he needs to rotate the characters to the left or to the right. If the user enters a wrong answer, the program will do a rotation to the right. Depending on the answer, the program will rotate the characters "n" times and...
In C++ Let n be a non-negative integer. The factorial of n, written n!, is defined...
In C++ Let n be a non-negative integer. The factorial of n, written n!, is defined by 0 ! 5 1, n! = 1·2·3· · ·n if n $ 1. For example, 4! = 1·2·3·4 = 24. Write a program that prompts the user to enter a nonnegative integer and outputs the factorial of the number. Allow the user to repeat the program. Example: If the user enters a 3 then your program should perform answer = 3 * 2...
Write a c++ program of the Fibonacci Sequence. Have the user enter a positive integer n...
Write a c++ program of the Fibonacci Sequence. Have the user enter a positive integer n and compute the nth Fibonacci number. The program should end when the user enters a number less than or equal to zero
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...
Write a program factor that prints the prime factors of a specified non-negative integer. The integer...
Write a program factor that prints the prime factors of a specified non-negative integer. The integer will be provided as a command-line argument. You may assume that the integer will be greater than 1 and less than or equal to the largest signed integer on your platform (that is, you may use an int).
Q#1 Write a C++ program that reads n integer values and stores them in an array...
Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements. Q#2 Write a C++ program that reads 10 integer values and stores them in an array. The program should find and display the average of the array elements and how many elements are below...
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT