Assignment #4



CSE 1321L: Programming and Problem Solving I Lab

Assignment 5 – 100 points

Methods

Program 0: What are they thinking? One common technique for interviewing computing professionals is by asking bizarre questions. For example, “how many gas stations are there in the United States?” Do they expect you to know the answer? No. They are really trying to see if you can reason your way through providing a ballpark estimate. Another common question is to calculate how much the Washington Monument weighs. FYI, the monument is 555 ft tall and 55 ft wide (and deep). So, for this assignment, we’re going to help people that want to build (and move) their own pyramid monuments! The volume of a pyramid with a square base is calculated as V = A(h/3), where A is the area of the square base and h is the height. Our monuments will be made out of marble, which weigh 169.2 pounds per cubic foot. You must write a function called monumentWeight that takes in the width (in feet) of the base of the monument and its height (in feet). The function should return the weight of the monument. Your task is to design (pseudocode) and implement (source code). For the source code, name your class “A5_0” and put it into a file called “A5_0” (either .java, .cs or .cpp)

Sample run 1:

Enter the width of the pyramid: 4

Enter the height of the pyramid: 10

The weight of your monument is: 9024.0

Sample run 2:

Enter the width of the pyramid: 0.5

Enter the height of the pyramid: 2

The weight of your monument is: 28.2

Sample run 3:

Enter the width of the pyramid: 55

Enter the height of the pyramid: 555

The weight of your monument is: 9.4688552E7

Program 1: ASCII Art. Computer graphics were really awful when Personal Computers first came to market. In fact, many computers would show spreadsheets and even full video games using only ASCII characters (look up Nethack, Angband, or even Medievia). We’ll start the beginning of your ASCII Art career by drawing squares that are based on user input. Write a function called drawBox that takes in number representing the width of the square. In main, ask the user for a number and then “draw” a box of that size by calling that function. There are several ways to code this, but you must have one function that you call from main. If you create additional functions that are called from that function, you’re that much more powerful! Hint #1: this is done by drawing individual characters. Hint 2: drawing the top and bottom lines are the same. How would you draw just the second line of Sample Run #3 below? Hint 3: a size of 1 is a special case…

Your task is to design (pseudocode) and implement (source code). For the source code, name your class “A5_1” and put it into a file called “A5_1” (either .java, .cs or .cpp)

Document your code and properly label the input prompt and the outputs as shown below.

Sample run 1:

Enter the size of the box: 1

*

Sample run 2:

Enter the size of the box: 2

* *

* *

Sample run 3:

Enter the size of the box: 5

* * * * *

* *

* *

* *

* * * * *

Sample run 4:

Enter the size of the box: 10

* * * * * * * * * *

* *

* *

* *

* *

* *

* *

* *

* *

* * * * * * * * * *

Program 2: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions:

a |4 |g |9 |m |/\\/\\ |s |$ |y |‘/ | |b |B |h ||-| |n ||\\| |t |7 |z |Z | |c |( |i |1 |o |0 |u |U | | | |d |D |j |j |p |P |v |\\/ | | | |e |3 |k ||< |q |Q |w |\\/\\/ | | | |f |Ph |l |L |r |R |x |>< | | | |

Note! You will need to know how to 1) get the length of a string (the number of characters) and 2) access individual characters of the string. See the appendix for more information. You must call your function translateToL337. Note #2: your first task should be to try to print out a single ‘\’ character…

Your task is to design (pseudocode) and implement (source code). For the source code, name your class “A5_2” and put it into a file called “A5_2” (either .java, .cs or .cpp)

Sample run 1:

Enter a string: you have been powned

'/0U |-|4\\/3 B33|\\| P0\\/\\/|\\|3D

Sample run 1:

Enter a string: you have programming skrilz

'/0U |-|4\\/3 PR09R4/\\/\\/\\/\\1|\\|9 $| ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download