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
- 1. Write a program in C which is a Menu-Driven Program to compute the area of the various geometrical shapes. You are required to use switch... case statement. i. Circle ii. Rectangle iii. Cylinder 2. Write a C program to read electricity unit (kW) and calculate the total electricity bill (RM) according to the given condition by using if... else if statement → For first 100 units RM 0.44/unit ⇒>> For next 100 units RM 0.51/unit For unit above 200 RM 0.65/unit →>> An additional tax (SST) of 6% is added to the bill. RM must be shows in two decimal points. => The output must have the option to choose from a menu as follow: Information of tariff charge; i. ii. Calculate a power consumption (kWh) from the keyboard and display the total bill; If the total bill calculated is less than or equal to RM20, print "Your bill is free". Otherwise, print the total bill. iii. Exit the calculator and say "Thank You", Other than the options, print "Option unavailable"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
- Use visual studio 2010arrow_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_forwardProgramming Lab-2 1. Mr. Smith takes care of the water level in a machine. In the machine, the water level is denoted by I. If the value of 12 + 121 goes above 150 then he has to turn off the machine. Since he is poor at calculations so help him by writing a program that prompts him to enter the value of I and displays the message "Turn off the machine." or "Level under control." according to the condition mentioned above.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_forwardQuestion 4 The correct statements are: L {E} = {E}L = L. LØ = ØL = Ø. OL₁= (a, b) and L₂ = {a, c}. Then L₁ L2 = {aa, ac, ba, bc}.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_forward
- Compute the weakest preconditions of the following statements for the given postconditions. Assume all variables are integers1)a = 2*b + 1;b = a*a + 1;{ a > 10 } 2)if (b > 0)a = 4*b - 10;elsea = b + 172;{ a > 0 }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-Write a program that asks the user to enter a person's age. The Problem 2: Age Classifier program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. These are the guidelines: If the person is 1 year or less, he or she is an infant If the person is older than 1 year, but younger than 13 years, he or she is a child. If the person is at least 13 years old, but less than 20 years old, he or she is a teenager. If the person is at least 20 years old, he or she is an adult.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