Concept explainers
write a c++
Do all of your output in main(). Make it look like this. Don’t forget your underlines won’t be immediately underneath.
Use methods for the following:
getPurchaseAmt()
Get the monthly purchase amount from the user. Include an error-trap around this input value so the user will have to enter a positive number (0r 0 to end the loop). Return the purchase amount.
displayMenu()
Display a menu of the membership types for the user to choose from, as follows:
Membership Types:
- Premium
- Plus
- Standard
Enter choice (1, 2, or 3):
This method only displays. There is nothing to return, so it will be a void method. You will call this method from getType().
getType()
Call the displayMenu() method and get the membership type from the user. Include an error-trap around the menu and choice so the program will not continue until the user enters a valid choice. Return the choice.
calcPoints()
Premium members receive 3 reward points for every 100 dollars they spend, Plus members receive 2 reward points for every hundred dollars they spend, and Standard members receive 1 reward point for every 100 dollars they spend. (Hint: Integer division and type casting as int will come in handy for this). Return the number of reward points.
Step by stepSolved in 3 steps with 1 images
- In this lab, you will make additions to a C++ program that is provided. The program is a guessing game. A random number between 1 and 10 is generated in the program. The user enters a number between 1 and 10, trying to guess the correct number. If the user guesses correctly, the program congratulates the user, and then the loop that controls guessing numbers exits; otherwise, the program asks the user if he or she wants to guess again. If the user enters a "Y", he or she can guess again. If the user enters "N", the loop exits. You can see that the "Y" or an "N" is the sentinel value that controls the loop. Note that the entire program has been written for you. You need to add code that validates correct input, which is "Y" or "N", when the user is asked if he or she wants to guess a number, and a number in the range of 1 through 10 when the user is asked to guess a number. Instructions Ensure the source code file named GuessNumber.cpp is open in the code editor. Write loops that…arrow_forwardWrite a do while loop in C++ that validates an input classCode. The valid inputs are ‘F’, ’S’, ’J’, or ’R’. Use a boolean variable invalid to assign the invalid expression. Have it output the input and either “ is an INVALID INPUT – Please try again!” or “ is valid – thank you!”. For Example: G is an INVALID INPUT – Please try again! OR F is valid – thank you! Use the following declarations: char classCode; bool invalid;arrow_forwardcode must be done in C++ no other language is acceptableWrite a program using nested loops that asks the user to enter a value for the number of rows to display. It should then display that many rows of * and $, with one * in the first row, two in the second row, and so on. However, the last in each row should be aligned (preceded by as many $ as necessary). A sample run would look like this: Enter number of rows: 5 Then the and $ should appear like this: * $ $ $ $ $ $ $ * * * $ $ $ * * *arrow_forward
- A credit card company awards monthly reward points (integer type) based on the type of membership a customer has and the amount they charge to their card that month. The user will enter the membership type and purchase amount, then determine the appropriate number of reward points. Use a pretest loop to allow the user to enter data until they input 0 for the purchase amount. Do all of your output in main(). Make it look like this. Don’t forget your underlines won’t be immediately underneath. Use methods for the following: getPurchaseAmt() Get the monthly purchase amount from the user. Include an error-trap around this input value so the user will have to enter a positive number (0r 0 to end the loop). Return the purchase amount. displayMenu() Display a menu of the membership types for the user to choose from, as follows: Membership Types: Premium Plus Standard Enter choice (1, 2, or 3): This method only displays. There is nothing to return, so it will be a void method. You will…arrow_forwardmatch the sample run pleasearrow_forwardWrite an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Test aborted." 367012.2549490.qx3zqy7 1 import java.util.Scanner; 2 3 public class NonNegativelooper { public static void main (String [] args) { 4 5 Scanner scnr new Scanner(System.in); int userNum; 7 8 userNum scnr.nextInt(); 9. while (* Your solution goes here System.out.println("Body"); scnr.nextInt(); 10 11 12 userNum } System.out.println("Done."); } 13 14 15 16 }arrow_forward
- PrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forwardIN C++arrow_forwardIn java, create a program that will use a do while loop with a "yes/no" prompt. The program should include user input and output with getters and setters. Once the end of the loop is reached, ask the user if they'd like to do the program again. Answering "Yes" will start the program over again. Answering "No" will end the program. Answering with anything else will be an invalid input. Once the loop begins again, the program should also discard all previous inputs so that there won't be any overlapping. Use Scanner.nextLine();, it will help.arrow_forward
- Answer in Java pleasearrow_forwardin C#arrow_forwardFor C Programming This has to deal with the Fibonacci sequence. Complete a program so that it prints the nth Fibonacci number, where n is an integer value read as input by the program. For example, if the input 4, then the output should be: Fibonacci number 4 is 3. Another example if the input is 7 then the output should be: Fibonacci number 7 is 13. Use a loop for this program.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