Free Essay

Pseudocode

In:

Submitted By scf615
Words 841
Pages 4
CMSC 131 Summer 2005 Quiz 2 Worksheet

The second Quiz of the course will be on Friday, Jun 17. The following list provides more information about the quiz:

• You will have 25 minutes to complete the quiz. • It will be a written quiz (not using any computer). • It will be closed-book, closed-notes, and no calculator is allowed. • Answers must be neat and legible. We recommend that you use pencil and eraser. • The quiz will be based on the exercises you will find below. The quiz will ask you to write pseudocode for a particular problem. • We have provided previous semesters’ quizzes at the end. Take a look at them so you get an idea of the pseudocode we expect.

The following exercises cover the material to be covered in Quiz #2. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TA and the instructor during office hours. Keep in mind that in the following exercises you are being asked to provide only pseudocode.

1. Write pseudocode for a program that computes the average of a set of values after the highest and lowest scores have been removed.

2. Write pseudocode for a program that reads a sequence of integer values and determines whether it is a decreasing sequence. A decreasing sequence is one where each value is greater than or equal to the next element in the sequence. The program will first read the number of values to process followed by the values in the sequence. The program will print the message "Decreasing" for a decreasing sequence and "Non-Decreasing" otherwise. For example, here are two decreasing sequences:

90 87 30 0 -1 -2

110 4 0 -20

The following are non-decreasing sequences:

90 100 20 4

30 24 -2 -1 8 9

3. Write pseudocode for a program that display a multiplication table for a range starting at 1 up to a designated upper limit. For example, for a limit of 4 the table will look as follows:

1 2 3 4

1 1 2 3 4

2 2 4 6 8

3 3 6 9 12

4 4 8 12 16

4. Write pseudocode for a program that prints a histogram for a set of five values. For example, for the set of values 2 5 1 3 1 the program will generate the following histogram:

* * * * * * * * * * * *

5. Write pseudocode for a program that computes the atomic weight of a compound based on the compound formula. For simplicity assume only the following elements can be part of any compound:

Element Atomic Weight Ca 20 H 1 N 7

For example, the weight of the component 2Ca3N will be 40 + 21 ( 61. Examples of other possible components are: Ca3N4H3N, 2H, CaHN

6. Note: This problem was a previous quiz. The solution has been provided at the end. Write pseudocode for a program that reads a sequence of unique integer values and determines whether it is an increasing sequence. An increasing sequence is one where each value is greater than the preceding one. The sequence will be terminated by the special value -999, which is not considered to be part of the sequence. The program will print the message "Increasing" for an increasing sequence and "Non-Increasing" otherwise. For example, here are two increasing sequences:

2 45 90 134 -999

-2 -1 0 5 6 -999

The following represent two non-increasing sequences:

10 20 15 30 -999

11 100 2 90 -999

You may assume that the integer sequence will have at least two integer values and no two values will be equal.

To keep things simple, you can read in the next integer and store it in some variable x as follows: x = read()

You can print a value x or message as follows:

print(x) or print(“Hello”)

You do not need to implement any Java code for this problem, just the pseudocode. Remember, pseudocode should be detailed enough that it can be converted by a competent programmer into Java, but should not contain Java-specific details.

7. Note: This problem was a previous quiz. The solution has been provided at the end.

Write pseudocode for a program that computes the sum of the even numbers from user-provided values. The program will first read the number of values (N) that the user will input. It will then process the N values from user input, one by one. Finally, it will print the sum.

To keep things simple, you can read in the next integer and store it in some variable x as follows:

x = read()

You can print a value x or message as follows:

print(x) or print(“Hello”)

You do not need to implement any Java code for this problem, just the pseudocode. Remember, pseudocode should be detailed enough that it can be converted by a competent programmer into Java, but should not contain Java-specific details.

Problem 6 One possible solution

increasing = true prev = read()

do { curr = read() if ( curr != -999 ) { if ( curr

Similar Documents

Premium Essay

Papers

...Two Pseudocode examples with While loops Problem: Design an algorithm that will prompt for and receive prices of several items. After the last price is entered, the sentinel amount of –1 is entered. The algorithm should calculate the number of items purchased, total cost of the purchase before tax and with the tax of 7.5%, and display the results on the screen. A. Defining diagram: |Input |Processing |Output | | |Prompt for prices | | |price |Get all prices |num_items | |(several prices) |Calculate num_items |cost | | |Calculate total_cost |tax | | |Calculate cost and tax |total_cost | | |Display num_items | | B. Solution algorithm: (with a sentinel-controlled loop) Calculating_Cost 1. set num_items to zero, cost to zero // this...

Words: 589 - Pages: 3

Premium Essay

Pseudo-Code Structure

...Pseudo-code is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Pseudo-code typically omits details that are not essential for human understanding of the algorithm. The programming language is augmented with natural language description details, were convenient, or with compact mathematical notation. The purpose of using pseudo-code is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. Pseudo-code resembles, but should not be confused with skeleton programs, including dummy code, which can be complied without errors. Flowcharts and Unified modeling Language charts can be thought of as a graphical alternative to pseudo-code, but are more spacious on paper. A sequence structure is represented in pseudo-code as a line of instruction. A pseudo-code statement representing sequence would typically contain text very similar to what is found within the rectangle of the flowchart. The sequence control structure simply lists the lines of pseudo-code. The concern is not with the sequence category but with selection and two of the iteration control structures. A good example is; if age greater than 17, display a massage indicating you can vote else display a message indicating...

Words: 765 - Pages: 4

Free Essay

Algorithm and Psuedocode

...varaible declaration? the variable's name and the varaible data type 6. what value is stored in uninitalized varaibles? unpredictables values algorithm workbench questions 3- 10 3.statements that perform the following operations with the variables a.set b=2+ a b.set a = b*4 c. set b = 3/14/b d. set a = b = 8 4. variables results w,x, y and z all integers w=5 x=4 y=8 z=2 a. x=y = 4+ 8 b. 2*2 = 2*2 c. y/x = 8/4 d. y- 2 = 8-2 5. psuedocode statement declares varaible cost floating= point varaible cost 6.psuedocode that declares the caraible total declare real price= 99.95 display " orginal price" input item orginal price display price 7. pseudocode statement that assign the value 27 count = 27 8. pseudocode statement that assign the value of 10 and 14 declare integar total = 0 set total =10 9. psuedocode statement that subtracts the varaible downpayment declare integar downpayment declare integar total declare integar due set due total 10.puedocode statement that multiplies the variable subtotal declare variable subtotal 0.15 declare integar total declare total fee pg.73 questions 6 & 8 6. design a program that will ask the user to enter the amount of a purchase. program should compute the stat and county tax. state sales tax is 4 % and the county sales tax is 2% count< how much did you purchase>...

Words: 256 - Pages: 2

Free Essay

Media Disadvantge

...UNIVERSITY OF SARGODHA LAHORE Department of Computer Science & IT Introduction to Algorithms Assignment # 4 MSc (IT)-A Due Date: 20th Nov 2013 till 8:30am BS(CS)-A,B,C,D,E Due Date: 21th Nov 2013 till 8:30am New students (all sections) Due Date: 23rd Nov 2013 till 8:30am ------------------------------------------------- Note: Those who still not submitted assignment # 1, 2, 3 do submit it with assignment # 4, after that no late submission will accept. Pseudocode & Flowchart Assignment Selection Structure 1. Write pseudo-code and draw flowchart that input any number between 1 and 7 inclusive. If 1 is input, the output should be Monday, for 2 the output should be Tuesday and so on. For invalid input, message “wrong input” should be displayed. 2. Write pseudo-code and draw flowchart for a company in which an employee is paid as under: If his basic salary is less than Rs. 15000, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs.15000, then HRA = Rs. 5000 and DA = 98% of basic salary. If the employee’s salary is input, then find his gross salary. 3. Write pseudo-code and draw flowchart that enters the marks obtained, Homework, Assignment and Test with weight age. Home work = 0.2 Assignment = 0.3 Test = 0.5 If net marks are more than 60%, prints PASS, else FAIL. 4. Write pseudo-code and draw flowchart that reads in five...

Words: 282 - Pages: 2

Free Essay

Designing a Program

...Designing a Program When creating anything no matter what it is, a good design is always going to be very beneficial and in most cases required. When creating a new program, designing it will make things so much easier. Designing a new program will allow you to “see” what steps you need to accomplish in order to get what you want. In the long run it also save time because without a good design you would just be going into the project blindly and will more than likely need redoing over and over again. Designing a program using algorithm, flowcharts and pseudocode are all very important and I will use all of them but I think that the most important one would be the algorithm. We need to know what steps we need to take in order to get the results that the customer wants. Without the algorithm you really wouldn’t know what to put in the flowchart or what needs to be in the mock up or pseudocode. So for me the algorithm is the most important part of the designing process. Now let’s say we wanted to start a new project to design a game but didn’t want to take the time to design it. Well where would you start? I guess pull up the IDE that you will be working with and then? What do you want the game to be about? What do you need to do in order to play the game? I mean where do you start? That’s why designing is almost a necessity. References Gaddis, T. (2012). Starting Out with Programming Logic & Design, Custom Edition. [VitalSource Bookshelf Online]. Retrieved from...

Words: 286 - Pages: 2

Free Essay

Calorie Management Program

...PRG/211 – Week 5 Team B – Algorithm Planning Visual Logic CALORIE MANAGEMENT PROGRAM Week 2 Algorithm Planning Week 3 Program Variables for Calorie Management Week 4 Verification & workaround for Calorie Management Week 5 Learning Team Assignment ****************************************************** About the Assignment Imagine that your team of software developers won a contract to develop a program that will identify whether a person is balancing calories consumed with those being expended or burned by taking the following into account:   The balance of calories is calculated daily. Calories are consumed in both food and beverages. Calories can be identified from both product labeling and calorie counters located on the Internet. Calories are burned daily in both daily living and exercise. Calories expended or burned can be calculated using calorie calculators located on the Internet. The balance of calories may be displayed in either calories or pounds and ounces. The following are examples of the information that might be provided: Calories are in balance. _ _ _ more calories are consumed than expended. _ _ _ more calories are expended than consumed. No pounds/ounces were gained or lost. _ pounds _ _ ounces may have been gained. _ pounds _ _ ounces may have been lost. Use the following computation: One pound equals 3500 calories. THE PLAN Identify the criteria TEAM B will need to develop the required software. To do this, Team B must...

Words: 1400 - Pages: 6

Premium Essay

Pseudocode

...In event that was rather a stir up in the 1920’s was the Harlem Renaissance. The Harlem Renaissance was a time when African Americans all around showcased their artistic talents, showing the whites that they did indeed have talent. Obviously after the name “The Harlem Renaissance” was based in Harlem, New York. The Harlem Renaissance was a movement of writers, artist, actors, musicians, and poets of color expressing themselves through their talents. They used these talents not only to express themselves but also to tell stories of their past and the troubles the black people faced as a whole. This movement brought together so many African Americans. Not only that but it showed the white people of America they weren’t the only people who had talents. The arts were shared, whites bought black paintings and they were entertained by black shows that went on in venues. Often there were poems that were exclusively written for black people of America. During the renaissance Things were happening and the people of the Harlem Renaissance were reacting. Langston Hughes was a writer who created quite the impact during the Harlem Renaissance. He wrote poems, stories and even plays. He kept black communities entertained and gave opportunity with his plays. His poems kept African Americans motivated and pushing for what was right, equality. Jacob Lawrence was an artist creating abstract pictures of events happening beginning in 1917. He was the artist of “ The Great Migration Series” which...

Words: 355 - Pages: 2

Free Essay

Pseudocode

...Main module: Declare Jobs As String Declare Date As String Declare Spring As String Declare Fall As String Declare Winter As String Declare Storm As String Declare Monthly As String Declare Season As INT Write “Choose what tasks you need to check!” Write “Spring………..1” Write “Fall…………..2” Write “Winter……….3” Write “Storm………..4” Write “Monthly……..5” Input = Season If (Season < 0 or Season > 6) Then Write “You need to input a number between 1 – 5.” If input = 1 Then call Spring module Else If input = 2 Then call Fall module Else If input = 3 Then call Winter module Else If input = 4 Then call Storm module Else If input = 5 Then call Monthly module End If Spring module: Write “You have selected to view the Sping checklist of your home maintenance.” Write “These are the things you need to check for listed below:” Jobs Write “What jobs did you complete?” Input Job Write “Congratulations! You have completed checking the “ + Jobs + Date + “ Make sure you check that job again next spring.” Fall module: Write “You have selected to view the Fall checklist of your home maintenance.” Write “These are the things you need to check for listed below:” Jobs Write “What jobs did you complete?” Input Job Write “Congratulations! You have completed checking the “ + Jobs + Date + “ Make sure you check...

Words: 411 - Pages: 2

Premium Essay

Student

...interpreter does for you Know difference between a Logic & Syntax error Know Fortran is first High level programming language Know Assembly Language Know how CPU works(Fetch,Decode,Execute) Which is faster, Interpreter or compiler Pg.18 Machine Language (1001001) Know about unicode Know difference between logic and syntax......again lol Program development cycles Pg.30 Difference between psuedocode and flowchart Same as 13 Repetition and sequence of structure Know all of the processing symbols for flowchart Mathematical operators Pg.46 Order of precedence Know data types Pg.56 What is constant variable (named constant) Know benefits of using modules know pseudocode in sequence same as 23 know about return point (memory address location) what flowchart symbol is the module call (rectangle with 2 lines?) difference between flowchart and hierarchy chart Pg.83 parameter difference know passing argument by value and by reference Pg.97 know difference between global & Local variable same as 28 difference between control and sequence of structure what is sequence structure diamond shape is a symbol of what (condition) relational operator what is ! = ( different symbols ) what is the oval sign in a flow chart? Appendix B is the answer Pg.570 symbols on pg.570 what is the variable location inside the computer know variable name...

Words: 259 - Pages: 2

Premium Essay

Program Design and Tools

...PROGRAM DESIGN TOOLS Algorithms, Flow Charts, Pseudo codes and Decision Tables Designed by Parul Khurana, LIECA. Introduction • The various tools collectively referred to as program design tools, that helps in planning the program are:– Algorithm. – Flowchart. – Pseudo-code. Designed by Parul Khurana, LIECA. Algorithms • An algorithm is defined as a finite sequence of instructions defining the solution of a particular problem, where each instruction is numbered. • However, in order to qualify as an algorithm, every sequence of instructions must satisfy the following criteria: Designed by Parul Khurana, LIECA. Algorithms • Input: There are zero or more values which are externally supplied. • Output: At least one value is produced. • Definiteness: Each step must be clear and unambiguous, i.e., having one and only one meaning. • Finiteness: If we trace the steps of an algorithm, then for all cases, the algorithm must terminate after a finite number of steps. Designed by Parul Khurana, LIECA. Algorithms • Effectiveness: Each step must be sufficiently basic that it can in principle be carried out by a person using only one paper and pencil. – In addition, not only each step is definite, it must also be feasible. Designed by Parul Khurana, LIECA. Formulation of Algorithm • Formulate an algorithm to display the nature of roots of a quadratic equation of the type: ax2 + bx + c = 0 provided a ≠ 0 Designed by Parul Khurana, LIECA. Formulation...

Words: 914 - Pages: 4

Free Essay

Pseudocode - Texas Assignment

...Problem Statement - Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas. Family contains a maximum of ten members. Pseudocode: //Main Method MAIN //variable declarations //create parallel array to store family members information //array of Strings for family names DECLARE names[10] of STRING //array of ages for family members DECLARE ages[10] of INTEGER //array of states where they reside DECLARE states[10] of STRING //stores the total number of family members //as entered by user DECLARE count as INTEGER //age average DECLARE average as FLOAT DECLARE count as INTEGER SET count = 10 //declare variables to store current user input DECLARE name as STRING DECLARE age as INTEGER DECLARE state as STRING //prompt for family member count WRITE "How many family members do you have? " //read the value from user INPUT count //use for loop to prompt user to enter information //for all family members //repeat the loop "count" times FOR (COUNTER=1; counter <= count; COUNTER++) //prompt for name WRITE "Enter family member name: " INPUT name //prompt for age WRITE "Enter family member age: " INPUT age //prompt for state WRITE "Enter family member state: " INPUT state //store input values in the array SET names[COUNTER] = name SET ages[COUNTER]...

Words: 456 - Pages: 2

Free Essay

Artificial Inteligence Problems

...Search Quiz ICS171 Name___________ ID____________ No text, no notes, no questions. Do the best that you can on each question. No questions will be answered about the quiz questions. If you think a question is ambiguous, write your interpretation and answer your modified question. Be reasonable. The following abbreviations are used: BF = branching factor, DFS = depth first search, BFS = breadth first search, IDS = iterative deepening search, A* = A* search, LI = local improvement search, HC = hill-climbing search. [pic] 1. For the 8-tile puzzle, what is the average branching factor, assuming the blank is equally likely to occur in any position. Show your work. (4*2 + 4*3 +1*4)/9 = 24/9 = 2 & 2/3. 2. Suppose that you are solving the 8-tile puzzle where it has solution. Which of the methods (DFS, BFS, IDS) is guaranteed to find a solution, assuming no computational limits are reached. List all that are correct. DFS, BFS, IDS 3. For the same puzzle, which of the methods (DFS,BFS,IDS) is guaranteed to find the shortest solution? List all that are correct. BFS, IDS 4. For the same puzzle, which methods are guaranteed to use no more than O(BF * length of solution) amount of memory. DFS, IDS 5. Suppose you apply the A* algorithm to the same problem. You decide to let f = current cost of the path. Would it be appropriate to let h = 0 for all states? Yes or no and why. ...

Words: 504 - Pages: 3

Free Essay

Parallel Computing and Algorithms

...i SASTRA UNIVERSITY Shanmugha Arts, Science, Technology and Research Academy Thirumalaisamudram Thanjavur – 613 402 BCSCCS705 PARALLEL COMPUTING AND ALGORITHMS LAB B.TECH (COMPUTER SCIENCE AND ENGINEERING) 7TH SEMESTER ii List of Exercises: 1. Basic arithmetic operations in parallel 2. Find out factorial of a number 3. Generation of Fibonacci series, finding prime numbers in an interval. 4. Evaluate the integral of a function 5. Merging of two sorted lists 6. Parallel tree traversals 7. Matrix multiplication 8. Enumeration sort 9. Odd-Even transposition sort 10. Bitonic merge 11. Quick sort 12. Single source shortest path iii Exercise 1 Aim: Basic Arithmetic Operations in parallel To perform a set of arithmetic operations in parallel using a cluster of computers Procedure: Step 1: Identify a set of numbers over which arithmetic operations are to be done Step 2: Identify the rank in the cluster Step 3: Split the set of numbers into domains and assign each domain to their corresponding processor Step 4: Get the result from each computer in the cluster and assimilate them at the master Step 5: Verify the time taken for the completion of each task. Algorithm:function sum(+,identity,a) = if #a == 1 then [identity] else let e = even_elts(a); o = odd_elts(a); s = scan_op(op,identity,{op(e,o): e in e; o in o}) in interleave(s,{op(s,e): s in s; e in e}); iv Input:- An array of integers Output: - The sum 3,2,7,6 P1 18 0,5,4,8 P2 17 62 2,0,1,5 P3 8...

Words: 1116 - Pages: 5

Free Essay

Pseudocode - Using Functions to Solve Dimensions of Rectangle

...PseudoCode : //This program will calculate the area and perimeter using different functions. //The numerical values for length and width will be provided as an input by the user //Set function areaofrec as float //Set function periofrec as float //START Program //set menuSelect, intValue as int //set length, width, and result as float //set while loop (while intValue >0) continue loop //print “Enter a positive integer to calculate the area or perimeter of a rectangle; “ //print “OR a negative integer to exit program” //input positive or negative integer //create if else statement //If intValue >0 continue with program //else if intValue < 0 exit program //if intValue > 0 print “Enter 1 to calculate area, 2 to calculate perimeter” //input menuSelect option //if menuSelect == 1 //call the area function //print “you chose to calculate the area of the rectangle!” //print “please enter the length and width of the rectangle” //print “enter length first, hit enter, enter width, hit enter” //input length and width //set result = areaofrec(length,width) //print result “The area of the rectangle is (result) “ //else if menuSelect == 2 //call the perimeter function //print “you chose to calculate the perimeter of the rectangle!” //print “please enter the length and width of the rectangle” //print “enter length first, hit enter, enter width, hit enter” //input length and width //set result = periofrec(length,width) //print result “The perimeter...

Words: 280 - Pages: 2

Free Essay

Data Structures

...Data Structures & Algorithms Coursework Assignment 1 Q1. (a) Algorithm swap(x, y): Node n head While (n.getNext () != x ) do n n.getNext() Node v y.getNext () n.setNext(y) y.setNext(x) x.setNext(v) (b) Algorithm swap Doubly(x, y): DNode n x.getPrev() DNode v y.getPrev() n.setNext(y) y.setPrev(n) y.setNext(x) x.setPrev(y) x.setNext(v) v.setPrev(x) (c) The run time complexity for the singled linked algorithm is O (n) and for the doubly linked algorithm is O (1). Doubly linked list has the best time complexity. Time complexity in singly linked list take more time because we have to move from head to the node before x Q2. (b) RedBlueStack implements Stack{ protected Object A[]; Int capacity; int top = -1; RedBlueStack(int cap) { A = new Object [capacity]; capacity = cap; } int size() { return (top + 1); } void push(Object obj) throws FullStackException { if (size() == capacity) throws new FullStackException("Stack is full."); A[++top] = obj; } Object top() throws EmptyStackException { if (isEmpty()) throws new EmptyStackException("Stack is empty."); return A[top]; } Boolean isEmpty() { return (top < 0); } Object top() throws EmptyStackException { if (isEmpty()) throws new EmptyStackException("Stack is empty."); return A[top]; }  Object pop() throws EmptyStackException { Object elem; if (isEmpty()) throws new EmptyStackException("Stack...

Words: 551 - Pages: 3