Programming and Problem Solving With C++
6th Edition
ISBN: 9781449694265
Author: Nell Dale
Publisher: Jones & Bartlett Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 1, Problem 2CSF
Program Plan Intro
(a)
To indicate which line of the given
Program Plan Intro
(b)
To indicate which line of the givenalgorithmtells whether the year 1945 is the leap year.
Program Plan Intro
(c)
To indicate which line of the givenalgorithmtells whether the year 1600 is the leap year.
Program Plan Intro
(d)
To indicate which line of the givenalgorithmtells whether the year 1492 is the leap year.
Program Plan Intro
(e)
To indicate which line of the givenalgorithmtells whether the year 1776 is the leap year.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Algorithm Analysis
Start with 102 coins on a table, 98 showing heads and 4 showing tails. There are two ways to
change the coins:
• flip over any ten coins, or
• place n+ 1 additional coins, all showing tails, on the table where n is the number of heads
currently showing on the table.
For example, you might begin by flipping nine heads and one tail, yielding 90 heads and 12 tails,
then add 91 tails, yielding 90 heads and 103 tails.
(a) Model this situation as a state machine, carefully defining the set of states, the start state, and
the possible state transitions.
(b) Optionally, explain how to reach a state with exactly one tail showing.
(c) Consider the following derived variables:
C ::= the number of coins on the table H ::= the number of heads on the table
T::= the number of tails on the table C, ::= parity (C)
H2 ::= parity(H)
T2 ::= parity(T)
Here the parity : Z → {0,1} function is defined as parity(n) = 0 when n is even and 1
otherwise.
Which of these variables is strictly…
Check My Work
Here is an algorithm for calling a friend on the telephone:
Step Operation
1. Dial the phone and wait for either an answer or a busy signal
2.
If the line is not busy then do Steps 3 and 4
3.
Talk as long as you want
4.
Hang up the phone, you are done
5.
Otherwise (the line is busy)
6.
Wait exactly 1 minute
7.
Go back to Step 1 and try again
During execution, this algorithm could get into a situation in which, as in the deadlock problem, no useful work can ever get done. Describe the problem, explain why it occurs, and suggest
how it could be solved.
Q2: Explain each step in the following algorithm, and then compare it with DDA
Start
X=X1
AL IRAQIA UNIVERSITY
Y=Y1
DX=X2-X1
DY=Y2-Y1
E= (DY / DX) - 0.5
For I=1 to DX
الغراقي
Begin
Plot (X,Y)
While (E 20)
Y=Y+1
E=E-1
End While
X=X+1
E=E + ( DY / Dx)
End
Finish
1
Chapter 1 Solutions
Programming and Problem Solving With C++
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- given k positive integer, if k is even we divide it by 2, if odd we multiply it by 3 and add 1. and we reach 1 eventually. and it stops after 1000 iterations. below is the code to this algorithm, find the errors from the pseudocode and correct them.arrow_forwardCan you please help me I don’t understand how to solve this with the trading off algorithm, and also I did it once and my teacher said that I got it wrong so she said that I need to try to make 1 number end with 0, and not end with 5 because its easier to add the number that ends with 0 so we don’t need to worry about the carry over. Can you please help me understand what she meant and also help me solve this problem correctly like my teacher wanted it.arrow_forwardWrite an algorithm to find the given number is POSITIVE or NEGATIVE. Just answer without explanation pleasearrow_forward
- Simplistic Algorithms with a Fixed Number of Integers Write a program that takes three integers and outputs them in reverse order of how they were entered. For example, if the user enters 39, 51, 16 then the program should output 16, 51, 39.arrow_forwardExplain Algorithm: To sequentially search for the first occurring even number in the list of numbers given.Input 1: –1, 3, 5, 7, –5, 7, 11, –13, 17, 71, 21, 9, 3, 1, 5, –23, –29, 33, 35, 37, 40.Input 2: 6, 17, 71, 21, 9, 3, 1, 5, –23, 3, 64, 7, –5, 7, 11, 33, 35, 37, –3, –7, 11.Input 3: 71, 21, 9, 3, 1, 5, –23, 3, 11, 33, 36, 37, –3, –7, 11, –5, 7, 11, –13, 17, 22.arrow_forwardWrite an algorithm that reads 10 integer numbers and calculates the average for numbers that are divisible by 5.arrow_forward
- 3. Is the following algorithm deterministic? Explain your answer. def mystery (Number): if (Number > 0): else: Answer "yes" pick a value less than 5 and give this number as the answerarrow_forwardA consumer can withdraw up to $500 per day from an ATM. If a customer withdraws more than $300, the service charge is 4%. It tells the consumer of inadequate cash and offers to withdraw the money for a fee of $25.00. The ATM won't let you withdraw money if your account is empty or has a negative balance. If the withdrawal exceeds $500, the ATM informs the customer of the maximum withdrawal amount and refuses the withdrawal. Write an algorithm that allows customers to enter withdrawal amounts. The algorithm then verifies the account balance, debits the customer's account for the amount withdrawn plus any service fees.arrow_forwardRe-write the algorithm below so that it correctly solves the problem. Briefly explain the error and the correction. Problem Create an algorithm that will calculate the average of a group of numbers that are input and print the average. Calculate_Average 1 Get num1, num2, num32 sum = num1 - num2 + num33 average = sum/44 print averagearrow_forward
- Write an algorithm that computes the Body Mass Index (BMI) given the heights and weights of students. The algorithm should first read the total number of students and then read the height and weight of each student to calculate and print the BMI category A student is considered Underweight if the BMI is less than or equal to 18.5; Normal Weight if between 18.5 and 24.9; Overweight if between 25 and 29.9; and Obese if greater than or equal to 30.arrow_forwardThe greatest common divisor of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid's algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: 1. Compute the remainder of dividing the larger number by the smaller number. 2. Replace the larger number with the smaller number and the smaller number with the remainder. 3. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5arrow_forwardQUESTION 8 The following algorithm construct a sequence of positive whole numbers, which demonstrates the famous Collatz's conjecture: starting from any positive whole number, the sequence will eventually go down to 1. 1. input: positive integer x 2. i+0 3. repeat 3.1. i+i+1 3.2. if x is odd then 3.2.1. x (3 x x) + 1 else 3.2.2. x x+ 2 until x = 1 4. output i By tracing the algorithm, how many times does the algorithm perform Step 3.2.1. if the input is set to x = 6?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License