Compute the weakest precondition for each of the following assignment statements and postconditions.
x = 2 * y -5;
y = x + 2;
{y < 2}
We can compute the weakest precondition for a given assignment statement and postcondition by working backwards using the rules of Hoare logic.
For the first assignment statement, we want to find a precondition P such that if P is true before the statement executes, then the postcondition {y < 2} is true after the statement executes. Using algebra, we can rewrite the assignment statement as y = (x + 5) / 2, so we have:
{y < 2} => {(x + 5) / 2 < 2}
=> {x + 5 < 4}
=> {x < -1}
Therefore, the weakest precondition for the assignment statement x = 2 * y - 5 and the postcondition {y < 2} is x < -1.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Can someone help me to do question no.2 in c++? And to add annotate also let the program show there is an error when the user input a number which is bigger than 10 or 100 depends on the test, and finally to let them input another valid number? Thanks a lotarrow_forwardCan I please get help with this program?arrow_forwardZybooks C++ 1.7 LAB: Introduction to data structures labs Step 1: Producing correct output Three commented-out lines of code exist in main(). Uncomment the lines and click the "Run program" button. Verify that the program's output is: 2 + 2 = 4 Unknown function: PrintPlus2 Secret string: "abc" Submit your code for grading. Your submission will pass the "Compare output" test only, achieving 1 of the possible 10 points. Step 2: Inspecting the LabPrinter class Inspect the LabPrinter class implemented in the LabPrinter.h file. Access LabPrinter.h by clicking on the orange arrow next to main.cpp at the top of the coding window. Member functions Print2Plus2() and PrintSecret() print strings using std::cout. Step 3: Implementing CallFunctionNamed() Remove the three uncommented lines from main(). Then implement the CallFunctionNamed() function in main.cpp to handle three cases: If functionName is "Print2Plus2", call printer's Print2Plus2() member function. If functionName is "PrintSecret",…arrow_forward
- C++ Question: Make an execution chart like the example below for the code provided. Example chart: An execution chart is a text version of the hierarchy. Indentation is used to indicate thesublevels or calls inside a call. It also contains the data exchange between the components asdesignated in the hierarchy chart. Given below is the execution chart that corresponds to thehierarchy chart of the property tax calculation program1.0 Main()2.0 CalculatePropertyTax()3.0 displayMessage( input string messageToDisplay)3.1 return double getHomeValue()3.2 return boolean checkHomeValue()3.3 return double applyPropertyTax(input double homeValue)3.4 displayPropertyTax(input homeValue)3.5 return Boolean queryMoreData()4.0 displayMessage(input string messageToDisplay)4.1 return char getYesNo()4.2 return char convertCase(input char)3.6 displayErrorMessage() More exlanation: example: 1.0 means it's of depth 1, line 0 then 2.0 means it's one call inside a function (aka it's inside another function)…arrow_forwardProblem Statement: The mathematician Conway imagined a game, called game of life, whichconsidered cells that are susceptible to reproduce, disappear, or survive when they obey certainrules. These cells are represented by elements on a grid of squares, where a grid has an arbitrarysize. Thus, each cell (except those on the boundaries of the grid) is surrounded by eight squaresthat contain other cells. The rules are stated as follows:1. Survival: Each cell that has two or three adjacent cells survives until the next generation.2. Death: Each cell that has at least four adjacent cells disappears (or dies) by overpopulation.Also, each cell that has at most one adjacent cell dies by isolation.3. Birth: Each empty square (i.e., dead cell) that is adjacent to exactly three cells gives birthto a new cell for the next generation.It is worth noting that all births and deaths occur at the same time during a generation.Write a program that simulates this game and displays all successive…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