What is the output of the following cout statements embedded in these if-else statements? You are to assume that these are embedded in a complete correct program. Explain your answer.
a. if (0)
cout << “0 is true”;
else
cout << “0 is false”;
cout << endl;
b. if (1)
cout << “1 is true”;
else
cout << “1 is false”;
cout << endl;
c. if (–1)
cout << “–1 is true”;
else
cout << “–1 is false”;
cout << endl;
Note: This is an exercise only. This is not intended to illustrate
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Programming in C
Java: An Introduction to Problem Solving and Programming (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Concepts Of Programming Languages
- Compute the weakest precondition for each of the following statements based on their postconditions. b= 2*a + 3*b – 1; a = 2*b {a >= 2} if ( x==4) x = y /2+3; else x = y / 2; {x > 1}arrow_forwardHow do you find the weakest precondition for the conditional statements below? if (x < 7) x = x*x; else x = x+1; { x >= 11 } if (x != 0) z = x; else z = x+1;arrow_forward2. Write a program that determines a student's grade. The program will read three scores and determine the grade based on the following rules: -if the average score >=90% and grade=A -if the average score >= 70% and grade=B -if the average score>=50% and grade=C -if the average scoregrade=Farrow_forward
- What is the major advantage of using a for loop instead of a while loop? a. Unlike with a while loop, the execution of multiple statements can depend on the test condition. b. With a for loop, it is impossible to create an infinite loop. c. It is the only way to achieve an indefinite loop. d. The loop control variable is initialized, tested, and altered all in one place.arrow_forwardQuestion 2: Ali gives pocket money to his son in following fashion. Whatever pocket money is given on first day, next day it becomes double, and in next day it becomes the double of the previous day, and so on. For Example: If on first day 5 rupees are given then on second day 10 rupees will be given and on third it will be 20 rupees. You have to write a C++ Program that asks the number of days for which pocket money is to be given as well as ask the amount of pocket money given on the first day then compute and display the total pocket money. Explanation: Example 1: Enter pocket money on First day: 5 Enter number of days for which pocket money is given: 4 Total pocket money is: 75 75 will be computed as 5+10+20+40 Example 2: Enter pocket money on First day: 2 Enter number of days for which pocket money is given: 7 Total pocket money is: 254 254 will be computed as 2+4+8+16+32+64+128arrow_forwardQ3, A lecturer intends to separate his students into 2 groups based on their INDEX Numbers, those with odd numbers in group A and EVEN numbers in B. Use if-else statement to implement this. Q4.Your son intends to randomly mention some numbers to you, write a program using While or do-whileloop that will print all the numbers and the sum of the positive numbers.arrow_forward
- Scenario As you surely know, due to some astronomical reasons, years may be leap or common. The former are 366 days long, while the latter are 365 days long. Since the introduction of the Gregorian calendar (in 1582), the following rule is used to determine the kind of year: if the year number isn't divisible by four, it's a common year, otherwise, if the year number isn't divisible by 100, it's a leap year. otherwise, if the year number isn't divisible by 400, it's a common year. otherwise, it's a leap year. none of the above year int(input("enter the year")) if (year%4 1-0) and (year%400 -0) or (year % 1000): print (year is common year") else: print(year, is leap year") year= int(input ("enter the year")) if (years !-0) or (year480 1-0) and (year % 1001-0): print(year is common year") else: print(year, "is leap year") D year= int(input("enter the year"))arrow_forward2. Consider the expression used by the if statement if (*ptr == a && ptr != NULL) {printf("Yes\n"); } in the language C. How many different possible values does this expression have? Explain.arrow_forwardThe topics are: >>How to declare constants. >>How to Implement Arithmetic Operations. >>How to Implement Decision (Part 1: if - elseif - else). please this is a C++ program.arrow_forward
- You are required to write a C++ program to determine the number of students based ontheir weight range. First, the user must input the total number of students in the class. Next,by using looping, the user need to input the weight, in kilogram (kg), for each of thestudents. The program should display error message if the user input invalid weight. Theprogram should produce the output according to the following format: Range(kg) Number of StudentsBelow 40 ?41 – 60 ?61 – 80 ?81 – 100 ?Above 100 ?arrow_forwardModify the extended BNF (EBNF) in the answer box below to include: 1. if-then-else-end statements (in addition to the if-then statements it already includes) 2. read statements of the form read į that reads a value and stores it in the variable with identifier i 3. write statements of the form write e that print the value of the expression e Notes: ● ● Tokens must be written in lowercase letters, e.g. if, identifier. (The provided EBNF shows terminals in a monospaced font, but you do not need to worry about monospacing for your answers.) Non-terminals must start with a capital letter, e.g. If, Expression. (The provided EBNF shows non-terminals in italics, but you do not need to worry about italics for your answers.) Program = Statements Statements = Statement (; Statement)* Statement = If | While | Assignment If = if Comparison then Statements |--Choose-- While = while Comparison do Statements end Assignment = identifier := Expression Read = Write = Comparison = Expression Relation…arrow_forwardAnswer the following question based on the given statement. "Calculation of electricity meter reading for domestic usage at a rate of RMO.25 per kWh." Write a complete C program that permits interaction with user in this manner. Example of output: Enter previous meter reading: 5635 Enter current meter: 5777 You have used (kWh): 142 Your total payment (RM): 35.50arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education