Concept explainers
The following statements use conditional expressions. Rewrite each with an if /else statement.
A) j = k > 90 ? 57 : 12;
B) factor = x >= 10 ? y * 22 : y * 35;
C) total += count == 1 ? sales : count * sales;
D) cout << (((num % 2) == 0) ? "Even\n" : "odd\n");
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Modern Database Management (12th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- Q2: using java please type this code Code Problem 2 Book Sales Barnes and Nobles sells a package of books that retails for $125. Quantity discounts are given according to the following table: Quantity Discount: 10–19 books 15% 20–49 books 25% 50–99 books 35 % 100 or more books 50% Write a program that asks the user to enter the number of books they want to purchase. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount. Be sure to include comments at the top of your program to indicate your name and the name of the program and date. ( for the name use: bilge and use today's date)arrow_forwardThe company discounted used cars pays their employees according to this chart: 250$ per months plus 50$ per car sold. If the salesman sells more than 10 cars, the employee receives a bonus of 5% of the total of his sales, in addition to his regular salary.Each month, the owner sits in front of the computer, and enters the following information: The name of the employee, the number of cars sold, as well as the total of all the sales for the month. algorithm that will calculate the salary of an employee for the month, and then display on the screen, his name, total cars sold, base salary, bonus if applicable and entire salaryarrow_forwardsoftware.cpp A software company sells a package that retails for $99. Quantity discounts are given according to the following table. Quantity 10-19 20-49 50-99 100 or more Discount 20% 30% 40% 50% Write a program that asks for teday's date (you MUST use cin >> date. Do not use getline(cin, date), the company name and the quantity'they wish to buy and computes the total cost of the purchase. If the user enters a negative value for the quantity, tell him/her "invalid quantity". If a zero is entered, tell "Hope you decide to buy our software in the future." Otherwise display an invoice in the same format shown below. Your prompts and outputs have to look exactly the same as the following sample run (spacing too). I used 30 spaces for the labels and 10 spaces for the numbers. [kslotteempress cs111_lec_fall16]s ./a.out Enter today's date (mm/dd/yy): 09/27/16 Enter your company name: Little Coffee Shop Enter the quantity you would like to purchase: 10 Invoice for Little Coffee Shop Price…arrow_forward
- LIFE INSURANCE PREMIUM CALCULATOR Write a C program that calculates monthly, quarterly, half-yearly and yearly life insurance premium based on given sum assured. Monthly Premium Quarterly Premium Half Yearly Premium Yearly Premium sum assured / (years*12). sum assured / (years*4). = sum assured / (years 2). = sum assured / years. %3D %3D Output of program Enter your sum assured: 250000 Enter life insurance policy term (in years):5 Your Monthly Premium Your Quarterly Premium Your Half Yearly Premium: 25000.00 Your Yearly Premium : 4166.67 : 12500.00 : 50000.00arrow_forward35. Evaluate: 1+6==7 || 3+2==1. Write T for true and F for false ( ||-or)arrow_forwardYou may only use 'not' and 'or' to solve this along with parenthesesarrow_forward
- Rewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;arrow_forwardUntitled Section This is a segment of program, when it executed with multiple values for n and s the program displays the value of f, choose which output of f values are wrong answers cin>>x>>y; if (x>1) &&(y<5) {f=x+y*9; else f-x-y-11; } cout<arrow_forwardif s=15; t=-6; r=0; u=9; how will evaluate s > t && r < uarrow_forwardComplete the following table by writing statements with combined assignment operators in the right-hand column. The statements should be equivalent to the statements in the left-hand column.arrow_forwardA mail-order house sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; prod- uct 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the pro- gram should stop looping and display the final results.arrow_forwardThe following statement should determine if x is not greater than 50. What is wrong with that? Correct it if ( !x > 50 )arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr