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 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...
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
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...
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...
ite a C program that prompts for and reads in a non-negative integer from the keyboard....
ite a C program that prompts for and reads in a non-negative integer from the keyboard. Read it into an int variable x. Then display the 32 bits in x from the lsb to the msb (so the display will show the value in x in binary with the bits in reverse order). For example, if you input 6, then your program displays 00000000000000000000000000000110 Use the algorithm given in class (repeatedly divide by 2). Use the / and % operators....
PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a program to do the following. • Input an integer n. • Create a BST...
Write a program to do the following. • Input an integer n. • Create a BST S inserting the keys 1, 2, . . . , n in that order, which will result in a completely-skewed tree. • Measure the time to search for n + 1 in S. • Display the time taken for search. /** * Exception class for access in empty containers * such as stacks, queues, and priority queues. * @author Mark Allen Weiss */ public...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT