Concept explainers
The following if-else statement will compile and run without any problems. However, it is not laid out in a way that is consistent with the other if-else statements we have used in our
if (x < 0) {x = 7; cout << “x is now positive.”;}
else {x = –7; cout << “x is now negative.”;}
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
- 7) The ideal gas law allows the calculation of volume of a gas given the pressure(P), amount ofthe gas (n), and the temperature (T). The equation is:V = nRT / PSince we only have used integer arithmetic, all numbers will be integer values with nodecimal points. The constant R is 8.314 and will be specified as (8314/1000). This givesthe same result. Implement the idea gas law program where the user is prompted for andenters values for n, T, and P, and V is calculated and printed out. Be careful toimplement an accurate version of this program. Your program should include a properand useful prompt for input, and print the results in a meaningful mannerarrow_forwardExercise III: Catalan numbers For n e N, denote by c, to be the number of ways to form a "mountain range" with n upstrokes (U) and n downstrokes (D) that all stay above a horizontal line. For instance: for n = 1, only UD is allowed, so c = 1; • for n = 2, only UUDD and UDUD are allowed, so c2 = 2. 1. Check that c3 = 5 by writing down or drawing all possible options. 2. Consider the power series +00 g(x) = 2 n=0 (by definition co = 1) called the generating function of the sequence (en). Justify that cn < 4" for each n, and deduce that the radius of convergence of g is at least 1/4. 3. It can be show that for r E (-1/4, 1/4), g(x) = 1+ xg(r)? and therefore 1- VI 4.x g(x) = 2.x Use this formula and the known power series of V1+ x to write the first terms of the power series expansion of g, in the form g(x) = co + c1x + c2x2 + C3x + c4x* + ·.. Show how you obtain a few terms, but you do not need to show all computations and you can use a calculator for fractions. Check that you recover co,…arrow_forwardWhat is the final value of y? int x = 4; 6; int y if (x < 10) { if (y < 5) { y = y + 1; } } else { } y = 7; } else { y = y + 10;arrow_forward
- Problem Description Did you know that in lotteries, a 3-digit number with the same numbers in all digits like 777 will hit the jackpot in a casino? In the same manner, let's make a program that will test if a certain 3-digit number hits a jackpot or not by identifying if all the digits of a given number is the same as the second inputted number. If it is, print "Jackpot!"; else, print "Nah". Input A line containing two integers separated by a space. 777·7 Output A line containing a string. Jackpot! -USED JAVA PROGRAMMING LANGUAGEarrow_forwardSample for Multiple-ifarrow_forwardi. Find the loop invariant for the program code below. void main() { int y = 1, x = 0; while (x < 4) { y = y * z; x = x + 1; }arrow_forward
- The body mass index, BMI, is a measure used to determine if a person is overweight or not. We can calculate BMI from the weight of the person (in pounds) and the height (in inches) of the person.The formula for calculating BMI is:BMI = (weightInPounds * 703) divided by (heightInInches squared)In this problem, you will develop a Java program as a BMI calculator, that reads the user’s weight in pounds and height in inches, then calculates and displays the user’s body mass index BMI. Also, display the following information {from the US Department of Health} so the user can evaluate his/her BMI:BMI values:Underweight: less than 18.5Normal: between 18.5 and 24.9Overweight: between 25 and 29.9Obese: 30 or greaterarrow_forwardC++ Program plsarrow_forwardQUESTION 5 This is a MULTIPLE ANSWER question, which means you are able to select one or more answers as being correct. Note that this does not necessarily mean that there are multiple correct answers. In any case, select all the answers you believe are correct. (NB: There are no part marks awarded for multiple answer questions.) Consider the following Python code, where the variables level and threshold have integer values: alarm = 3 if level = threshold: if level < 100: alarm = 1 alarm = 2 What initial values for variables level and threshold guarantee that variable alarm ends up with the value of 2 after the code has executed? When level is 200 and threshold is 99 When level is 4 and threshold is 5 ☐ When level is 200 and threshold is 100 When level is 400 and threshold is 300 When level is 5 and threshold is 4 When level is 3 and threshold is 4 When level is 1 and threshold is 2 O When level is 10 and threshold is 10arrow_forward
- The objective of this program is to demonstrate your proficiency with the if-elif-else construct. Your program will consist of a simple guessing game. Using the random module, generate an integer between 1 and 10. This will be the secret. You will then ask the user for a guess between 1 and 10. . If the guess is greater than the secret respond, "Too high". • If the guess is less than the secret respond, "Too low". . If both numbers are equal respond, "Success!". Remember to test your program to ensure that all of the comparisons work. Please note that a loop is not required. The images below shows the program being run multiple times to display the three different possible output messages. Your display should look like this. User input is highlighted in green. Please enter your guess: 10 Too high! Please enter your guess: 5 Too low! Please enter your guess: 1 Success!arrow_forwardThe Game of Nim: The game of Nim starts with a random number of stones between 15 and 30. Two players alternate turns and on each turn may take either 1, 2, or 3 stones from the pile. The player forced to take the last stone loses. The computer player will make random choices during their turn. Your program must check to make sure that neither the computer nor the human player attempts to take 3 if there are only 1 or 2 stones left. The computer should only take 1 or 2 stones when 3 are left, and only 1 stone when 2 stones are left. Make sure you are using functions, importing random, and making it at around grade 10 coding levels, haha!arrow_forward3. What does this code print? int i = 0; while (i < 12) { int j; for (j = 0; j < i; j++) { if ((i+j)%3 Ø) == j += 2; } i += j+1; } System.out.println("i = "+i);arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning