This is an individual assignment. You must complete this lab on your own, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and ninjas, and do not look at anyone else's code for this lab. If you need help, please post a question on Piazza, or contact the professor.
The goal of this lab is to introduce you to review some of the concepts we have covered since the beginning of class and to prepare you for the first test. The concepts we review are:
For each problem you have to solve, the solution should be written in a function that has the input / output behavior described in the problem.
The current pattern for displaying 50 stars on the American flag is five rows of 6 stars (30), interlaced with four offset rows of 5 stars (20), as shown on the right. This pattern has the property that adjacent rows differ by no more than one star. We represent this star arrangement compactly by the number of stars in the first two rows: 6,5.
If the U.S. were to accept a new state in the union, a 51-star flag that preserves the relationship can have three rows of 9 stars, interlaced with three rows of 8 stars (27 + 24 = 51), or 9,8. If yet another state were to be added, a 52-star flag could have 13 rows of 4 stars, or 13,13 (because there are 13 stars in each of the first 2 rows).
A star arrangement is visually appealing if it satisfies the following conditions:
Your goal is to write a function printStarArrangements
that will, given the number of stars to place on a flag (an integer), find and print on screen all
possible visually appealing star arrangements.
Your function should print each visually appealing star arrangement on its own line, in the form [int],[int]. That is, each visually appealing star arrangement should be described by printing the number of stars of the first and second line, separated by a comma and no other characters
The list of compact representations is to be printed in increasing order of the number of stars in the first row. If there are multiple compact representations with the same number of stars in the first row, print them in increasing order of the number of stars in the second row.
For example:
You may want to write a function isPossibleArrangement
which, given 3 integers, the total number of stars and the numbers of stars in the first two lines, returns true if it is possible to have a visually appealing arrangement that would have the correct total number of stars with the given numbers of stars in the two first lines, and returns false otherwise.
A group of students is studying for an upcoming standardized test in mathematics. They need practice with the common style of problem in which the student is asked to fill in the missing value in a sequence of numbers.
These problems feature either arithmetic sequences (where each number in the sequence is formed by adding an integer constant to the prior number) or geometric sequences (where each number in the sequence is formed by multiplying the prior number by an integer constant).
Your goal is to write a function completeSequence
that will help them practice on this style of problem by allowing them to check
their answers on sample problems. The function should take no input, and return no output. It will ask the user for the input and print the output on screen
Your function should ask the user to enter an input, and the user will enter a sequence of numbers, all at once. The first integer in the line is at least 5, and indicates the number of integers in the sequence. It is followed by that exact number of integers, one of which will be -1 to indicate the missing number. The remainder will be positive integers between 1 and 10,000,000, inclusive. Other than the `-1' placeholder value, the values will be in non-decreasing order.
Your function should use the existing numbers in the sequence to determine if the sequence is an arithmetic sequence or a geometric sequence, and based on that information, determine the missing number. If the sequence of numbers is neither an arithmetic or a geometric sequence, or if the result would not be between 1 and 10,000,000 inclusive, your function should return -1. You may want to write two functions, one that will return the correct result if the sequence is an arithmetic sequence, and one function that will return the correct result if the sequence is a geometric sequence.
For example:
This problem is based off of problems from the ICPC live archive.