Question

In: Computer Science

The following problem should be done in pseudocode. Problem 1 The programmer intends for this pseudocode...

The following problem should be done in pseudocode.

Problem 1
The programmer intends for this pseudocode to display three random numbers in the range of 1 through 7. According to the way we've been generating random numbers in the book; however, there appears to be an error. Assume that the random() function is a built-in library function. Correct the pseudocode so that the program works as it should (This has 1 error and is easy to spot)
//This program displays 3 random numbers in the range from 1 to 7.
    Declare Integer count
    //Display 3 random numbers
    For count = 1 to 3
        Display random(7,1)
    End For

Problem 2
This problem should return the amount of a discount to a main() module when the calcDiscountPrice() function is called. (This has 1 error and is pretty easy to spot.)
//The calcDiscountPrice funciton accepts an item's price and the discount percentage as arguments. It uses those values to calculate and return the discounted price.
Function Real calcDiscountPrice(Real price, Real percentage)
Function Real calcDiscountPrice(Real price, Real percentage)
    //Declarations
    Declare Real discount
    Declare Real discountPrice

    //Calculations
    discount = price * percentage
    discountPrice = price - discount
    
    //Return the discount amount
    Return discount

Problem 3
This problem should calculate and display 10% of any number given. Correct the pseudocode (a bit harder than the last 2 problems)
Module main()
    //Declarations
    Declare Real value, result
    
    //Get a value from the user
    Display "enter a value"
    Input value
    
    //Set 10% of the value
    result = tenPercent(value)
    
    //Display value
    Display "10 percent of ", value, " is ", result
End Module

//The tenPercent() function calculates and returns 10% of any number passed into it
Function Real tenPercent(Real num)
    //Declarations
    Declare Integer myResult
    
    //Calculations
    myResult = num * .10
    
    //Return the result
    Return myResult
    
End Function

Solutions

Expert Solution


Related Solutions

1. What should be done in the following situations: i. A room containing a 57Co sheet...
1. What should be done in the following situations: i. A room containing a 57Co sheet source is posted with a sign reading “Caution-Radioactive Materials”. The exposure rate measured next to the source is 5.2 mR/hr. ii. A technologist discovers that a patient in the room next to a radioiodine therapy will receive 2.5 mrem/hr. when lying in his bed which is against the shared wall. iii. A spill of 99mTc increases the exposure rate in a room from 1.7...
WHAT IS THE PSEUDOCODE OF THE FOLLOWING PROBLEM? Design a microcomputer system using a uP 8086...
WHAT IS THE PSEUDOCODE OF THE FOLLOWING PROBLEM? Design a microcomputer system using a uP 8086 10 Mhz. This system must have a Coprocessor 8087, a parallel connector, a serial connector, ADC and DAC connector for data conversion, a 16 byte seven segment display, a 64-key matrix keyboard, a USB connector thru a DMA for high speed data transfer. A special connector to connect a printer. The system must have an interrupt controller to handle all the I/O interface. The...
Problem 1: (10 marks) ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a...
Problem 1: ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a positive numberias an input, where i=a1a2...an,n>=3(numberwith 3 or more digits, every digit can have the value between 0 and 9–both inclusive). The algorithm should find the largest number jsuch that j=b1..bm, 1<=m<=n(numberwith m digits),andevery bk<=bk+1where1<=k<m and bk,bk+1ε{a1, a2, an}.Also, perform the computational complexity (time complexity)analysis of your algorithm and write the algorithm complexity in Big-Oh notation. Examples:Input: 23720, Output: 237Input: 9871, Output: 9Input: 1789, Output:1789Input: 2372891,...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Develop a Complete Interactivity Chart, The Coupling Diagram and a Pseudocode for this problem: Problem Specification:...
Develop a Complete Interactivity Chart, The Coupling Diagram and a Pseudocode for this problem: Problem Specification:      Jennifer Camacho It’s the owner of Amazing Toyota, a company that sells this type of cars in Puerto Rico. She wants a program that displays the amount of salespersons commission. Some companies use a fixed rate to calculate the commission, while others (like Amazing Toyota) use a rate that varies with the amount of sales. If The salesperson sales $15,000 in one moth...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your own words)
If cloning of humans could be done safely, should it be done? What are the ethical...
If cloning of humans could be done safely, should it be done? What are the ethical and legal implications of cloning humans? Would you consider cloning yourself? Why or why not?
Please describe HOW TO FORMULATE research problem. What should be done? ( i need very good...
Please describe HOW TO FORMULATE research problem. What should be done? ( i need very good EXAMPLES thank you)
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a month, then determine what season it is based on that input. Write a method that takes in a month and day and returns which season it is (“Spring”, “Summer”, “Fall”, “Winter”). Your main method should be the only one that includes a print statement. Note the first days of each season: • March 19th – Spring • June 20st – Summer • September 22nd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT