Question

CSE 002: Fundamentals of Programming
Spring 2020image?w=619&h=1&rev=1&ac=1&parent=1-6XALimage?w=619&h=1&rev=1&ac=1&parent=1-6XAL

Homework Assignment 6:

Objectives. The objective of this homework is to give you practice with writing while, for, and do-while loops.

You may find it helpful to work through the check point questions embedded in the chapter, and to practice on homework problems from the text that we have not assigned. Note that solutions to the even-numbered problems are available on the book’s student resource website as described on page xii.

All homework is checked for evidence of plagiarism. Academic dishonesty carries a tremendous penalty, and offenders will be caught. Copying homework will result in a minimum of your failure of this class, and can include expulsion from Lehigh, and worse. See the syllabus for a clear guide on collaboration.

Assignment 1) Write a program that asks the user for two integers: Length and Width. Length is to specify how many characters the following pattern should spread, horizontally, across the screen. Width should specify how many characters the following pattern should spread, vertically, across the screen. The input on the screen might look like this:

Input your desired length: Bazooka!

  Error: please type in an integer.

Input your desired length: 39

Input your desired width: 7

# /\ ## /\ ## /\   

# / \ # # / \ # # / \  

  # / \ # # / \ # # / \

   # \ # \ # \

  / # # \ / # # \ / # #

/ # # \ / # # \ / # #  

/ ## \/ ## \/ ##   



Here is another example:

Input your desired length: 45

Input your desired width: 54

  Error: Please input an integer smaller than the length.

Input your desired width: 4

# /\ ## /\ ## /\ ## /\ ## /\ ## /\

#/ \# #/ \# #/ \# #/ \# #/ \# #/  

/# #\ /# #\ /# #\ /# #\ /# #\ /#  

/ ## \/ ## \/ ## \/ ## \/ ## \/ ##

Some details on this pattern: The pattern is always composed of two twists, a slash-based twist, and a hashtag-based twist. When the desired width is odd, then the hashtag and the slash alternate in front (see first example).

Reject any input where the requested width is larger than the requested length, or when the requested length is greater than 80. Original UNIX terminals displayed at most 80 characters, hence the limit.

Hints:

  • The helices displayed can be thought of as a series of “X” patterns, where each pattern is width characters tall (vertically) and width characters long (horizontally). Note that there are two variations on the X pattern - the first pattern involves the hashtags going down and to the right, and the slashes going up and to the right. The second X pattern has the slashes going down and to the right, and hashes going up and to the right. The two patterns alternate.

    • The fact that the patterns repeat means that you can use modulus arithmetic to figure out which “X” a given character is in.

  • When printing out any pattern, you must generate the whole line - including spaces. To generate the pattern, imagine that you are typing out the characters along one line, adding spaces or slashes or hashtags to it. What are the mathematical rules that relate to that?

  • You can generate the pattern with two nested loops - one that controls how many lines are generated, and the second that generates the characters on each line.

  • Some students have been having trouble with testing for errors in input. Since the user can just keep inputting erroneous inputs forever, you need to have an infinite loop that gets broken when the user inputs correct data. Here’s an example looking for a double:

//an integer to store the user input

double myDouble = 0.0;

//a switch to decide if you want to ask again

bool acceptable = false;

//loop until you get acceptable input (i.e. if it's a double)

System.out.print("Input your double: ");

while( !acceptable ){

//check if the input is a double.

if (input.hasNextDouble() ){

//if so, store it.

myDouble = input.nextDouble();

acceptable = true;

}

else{

//if not, trash it. This does not assign the output of

//next() to anything. The output is just discarded.

System.out.println(" ERROR: need a double");

System.out.print("Input your double: ");

input.next();

}

}

Suppose that you need to get a positive double. You can add additional tests (i.e. if statements) after you get the nextDouble.

  • This homework should reveal how hard it can be to create nested loops that generate complex patterns. After you solve it, as an optional exercise, try recreating the same pattern with for loops, while loops, and do-while loops, so that you can recheck that your abilities are just as strong on all kinds of input.

Store the program in Twisty.java.






Part II: Tracing code and Exam Preparation

Answer the following questions without writing code on your computer. Submit your completed work as a jpg or pdf. Regardless of how you scan it, make sure that it is very legible. Name the file PracticeHW6.pdf and submit it on courseSite.

Write a program that forces the user to enter an integer between 1 and 9, inclusive, and then prints out displays that depend on the value entered and look like the following examples. If a negative integer is provided, the program exits, printing out “ERROR”. Otherwise, the program asks again.

Size: 3 Size: 5 Size: 1 Size: 7

33333 555555555 1 7777777777777

32223 544444445 7666666666667

32123 543333345 Size: -3 7655555555567

32223 543222345 ERROR 7654444444567

33333 543212345 7654333334567

543222345 Size: asd 7654322234567

543333345 Size: 0 7654321234567

544444445 Size: -1 7654322234567

555555555 ERROR 7654333334567

7654444444567
7655555555567

7666666666667

7777777777777

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
CSE 002: Fundamentals of Programming Spring 2020 Homework Assignment 6: Objectives. The objective of this homework...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention...

    C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention to the rules at the bottom. Extra good rating to whoever can help me with this. TIA. In certain programming situations, such as getting information from web forms, via text boxes, the data coming in may need to be numerical (we want to perform arithmetic on it), but it is stored in the form of a list of characters (the numerical value stored is...

  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size...

    Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size and pattern, and checks if pattern exists inside size, if it exists then program returns index of first character of pattern inside size, otherwise it returns -1. The method should not use built-in methods such as indexOf , find, etc. Only charAt and length are allowed to use. Analyze the time complexity of your algorithm. Your solution is not allowed to be> = O...

  • Study guide Intro to PYTHON questions: 25) Write the code that will generate this output using...

    Study guide Intro to PYTHON questions: 25) Write the code that will generate this output using only while loops and if statements (no string multiplication). ###AAAAAAAA### ###BBBBBBBB### ###CCCCCCCC### ###AAAAAAAA### ###BBBBBBBB### ###CCCCCCCC### 26) Write code that asks the user for a size and prints a triangle of stars of that size that increases by two at each level. You can only use one while loop and any number of variables and counters you want, but you are limited to these tools....

  • C++ Hey, I really need help with this lab. I don't understand the function part at...

    C++ Hey, I really need help with this lab. I don't understand the function part at all. It'll be great way for me to understand. Than you Functions and loops: Write a program that will ask the user which type of triangle they would like to draw on the characters. The choices are screen with left-top-big left-bottom-big right-top-big right-bottom-big Get the user's choice, ask how big it should be, and then draw the shape. After each successful drawing, ask the...

  • COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning...

    COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...

  • Use Python and only while loops For this part of the homework you will write code...

    Use Python and only while loops For this part of the homework you will write code to draw an isosceles right triangle. (A right triangle in which the height and base are the same size.) Your program should prompt the user for these inputs, in exactly this order: 1. The height of their triangle 2. The symbol the triangle will be outlined in 3. The symbol the triangle will be filled with For these inputs, you can assume the following:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT