CIS 120 Problem-solving and Programming Concepts I

advertisement
CIS 120 Problem-solving and Programming Concepts I
Lab Exercise 14: Problem-Solving Final Review
Purpose:
The purpose of this lab is to provide students with an opportunity to review their problem
solving skills and programming capabilities in preparation for the final exam.
Objectives:
Upon completion of this laboratory exercise, students will:
1. Demonstrate their knowledge of evaluating problems.
2. Demonstrate their ability to code complete class definitions, program segments,
and methods.
3. Be prepared to answer all programming questions on the final exam. (Hopefully!)
Associated readings: Chapters 1 - 9 of the textbook.
Modules 1 - 6 of the Greenbook.
Lab Submission Requirements:
Your final source code and output results should be brought to class tomorrow for review
and to answer questions concerning the code.
Exercise 1: Study the following problem description. Create a flowchart that reflects an
appropriate and correct solution for the problem.
Problem Description:
Federal income tax is charged at these rates:
17% on the first $29,590 of taxable income,
26% on the next $29,590 of taxable income,
29% on any income in excess of $59,180.
Write a program to compute the tax for any taxable income submitted by the
user. Have the program work for a series of taxpayers until a negative taxable
income is entered.
Analysis:
Inputs:
Outputs:
The amount of income or a negative sentinel value.
The amount of computed tax.
Flowchart for Exercise 1:
Exercise 2: Generate the code developed in Exercise 1.
Question 1: What data structures did you use in generating this code?
Exercise 3: Study the following design. Generate the psuedocode that reflects an
appropriate and correct solution for the problem.
Problem Description:
Write method compound that has as parameters an amount of money deposited in
the bank and an annual compound interest rate, and produces a table of values of
the balance after each year for 10 years. Be sure that the annual balance is kept to
the nearest cent. Write a driver program and test the method.
Analysis:
Inputs:
Outputs:
A float indicating the amount of money deposited.
A float indicating the current interest rate.
A table showing the account balance at the end of each of the ten
years.
Psuedocode for Exercise 3:
Exercise 4: Generate the code developed in Exercise 3.
Question 2: How would you code a call to method compound?
Exercise 5: Study the following design.
Problem Description:
Write a class definition that defines an array of integers composed of 20 elements.
Generate random integer numbers between 1 and 10 to fill the array.
Read through the array and accumulate the sum of the values in the array.
Sort the array in ascending order.
Allow the user to input a value and search the array to see if the value exists as an
element in the array.
Analysis:
Inputs:
Outputs:
A value to be searched for.
Display the sorted list of the array.
Display the outcome of the search.
Code for Exercise 5:
Question 3: Why did you select the type of search that you choose to use in Exercise 5?
Question 4: How many passes did you make through the array created in Exercise 5 to
complete the required tasks? Could you have made the process more efficient by using
fewer passes?
Exercise 6: Study the following design.
Problem Description:
Write a class definition for class Movies. The class has instance variables of
name, star, and releaseYear and a class variable of population that is used to
store the number of members that have been created for this class. The default
values for these fields would be null. Include the following methods in your
definition:
a. Two constructors, a default constructor and one other.
b. A get method for each instance variable.
c. A set method for all variables as well as set methods for each individual
variable.
d. A toString method to display the object.
e. A method that determines the age of the movie (current year – release year).
Code for Exercise 6:
Exercise 7: Code a driver program that asks the user to input information about movies
and use that information to create objects of class Movies.
Reflection Question: As a programmer, how does object-oriented programming improve
your ability to solve problems?
Download