Concept explainers
Suppose we attend a party. To be sociable, we will shake hands with everyone else. Write a fragment of code using a for statement that will compute the total number of handshakes that occur. (Hint: Upon arrival, each person shakes hands with everyone who is already there. Use the loop to find the total number of handshakes as each person arrives.)
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- stoppingDistance = speed * (2.25 + speed / 21)Write a program which determines whether a vehicle’s tailgating distance is safe.The program should read in the speed of the vehicle and the vehicle’s tailgatingdistance. The program should then calculate the distance that would be required tostop the vehicle.If the stopping distance is less than the tailgating distance, your programshould print “No problem.” If the stopping distance equals the tailgatingdistance, your program should print “Minor wreck.” If the stopping distanceis greater than the tailgating distance, your program should print “Majorwreck!”arrow_forwardThe following statement should determine if x is not greater than 20. What is wrong with it?arrow_forwardExercise I- Medicine Write a program that asks the user to enter the name of the medicine (t for ThroX, f for FeliX), his mass. The user should enter as well if he has a prescription or not. The program will calculate the dosage using: age and his ThroX without prescription -The max dosage should be 0.75 mL -The dosage = mass / 150 -The number of pills per day to take is 1 ThroX with prescription -The dosage =mass * 3 / 150 -The number of pills per day to take is 5 FeliX with prescription -The dosage = 0.77 mL FeliX without prescription -The dosage should be between 0.3 and 0.7 -The dosage = mass * 0.009 -The number of pills per day to take is 2 -The number of pills per day to take is 6 The program should display the dosage and the number of pills to be taken per day if the requirements are full filled, otherwise it display "Please check your doctor for a prescription". In case the medicine does not exist in the database, the program display “Your medicine is not in our database!"…arrow_forward
- C Language - Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.arrow_forward1)Write a game of rock paper scissors, one of the choices will be from the user and the other from the computer (use random) Print results for each game.Play the games in a row until you exit the game. Explain each step as comment.Game rules:Rock crushes scissors, you win.Paper covers rock, you win.Scissors cut paper, you win. (solution will be Pyhton code,thank you) 2)Write a program that sorts a list in ascending order. Don’t use sort method.Ask user number of list elements (at least 10 elements)Enter all elements from keyboard and printed.Sort your list. (solution will be Pyhton code,thank you)arrow_forwardCan only use boolean opearators and numerical comparisons.arrow_forward
- Functions Exercise (Parking Charges) A parking garage charges a $2.00 minimum fee to park for one hour. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the function Charge to determine the charge for each customer. Car Hours Charge 1 2 Computer skills (Engineering) 3 1 4 24 TOTAL 2 8 10 20arrow_forwardProblem Description: The bird of paradise called the Helipixsal is renowned for its magnificent tail feathers which range in number from five to nine ornate feathers each of a different length. Their "magnificence" is quantified by the rather simple process of counting the exact number of tail feathers and multiplying this by the difference in the length of the minimum and maximum lengths of tail feather. You are to write a simple program that will allow the user to enter the length of each tail feather individually and keep on entering feathers until a -1 is entered. The program will then return the quantified "magnificence" factor.arrow_forwardParking Charges) A parking garage charges a $2.00 minimum fee to park for up to threehours and an additional $0.50 per hour for each hour or part thereof over three hours. The maximumcharge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hoursat a time. Write a program that will calculate and print the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for eachcustomer. Your program should print the results in a tabular format, and should calculate and printthe total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format:Car Hours Charge1 1.5 2.002 4.0 2.503 24.0 10.00TOTAL 29.5 14.50arrow_forward
- 31. If originally x=4, what is the value of x after the evaluation of the expression: x++arrow_forwardComputer Sciencearrow_forward12: guess.cpp) Write a program that plays a guessing game with the user. The user should pick a letter, and the computer should try to guess the letter. After each guess, the user should tell the computer whether its guess was too high or too low. With this information, the computer should be able to guess the letter within five tries. The user should be able to give whole words or single upper or lower case letters as responses.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning