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_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_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_forward
- How 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_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_forwardWhat 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_forward
- 2. 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_forwardScenario 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_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
- The 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_forwardYou 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_forwardProblem: Write a program for computing the amount of money in a bank account at the end of each quarter for a period of one year. A quarter is equivalent to 3 months. Assume that the account is created at the beginning of a year (i.e. January 1). The year will be entered at run time through the keyboard. The account has an initial principal that is entered at run time through the keyboard. No deposit or withdrawal is made within the one-year period. The interest is compounded quarterly which means that the interest earned for the first quarter will form part of the principal for the second quarter, the interest earned for the second quarter will form part of the principal for the third quarter and so on. The annual interest rate is 5%. The interest rate for a quarter is computed by dividing the annual interest rate by 4 since there are four quarters in a year. The computational procedure (see algorithm) and the output of the program (see sample run) are shown below. The output includes…arrow_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