PDA

View Full Version : Final Exam Urgent Help Needed! 1.5 Hrs Left



Moloch
12-19-2008, 02:11 AM
Quick synopsis I'm on my final exam for college. I have a few questions that have me puzzled.


Assume an array named salesData[] contains a company's sales figures for the last twelve months. The following is the (partial) pseudocode for a program that uses an accumulator (totalSales), a counter (monthNumber), a loop to sum all the elements in the array, and uses the sum to find the average sales figures over the last 12 months. (Assuming not zero based)

Part A: fill in the missing elements of the pseudocode (15 points)

totalSales = ___________

for monthNumber = 1 to ___12_______ //this was np

totalSales = ___________ + salesData[ ___________ ]

endfor

salesAverage = ____totalSales________ divided by 12 //this part easy

Part B: Code a second loop to determine how many months the sales exceed the average and then output that value. (10 points)


The following pseudocode for the logic of a program does the following:

1) Prompts the user to input a savings account balance and inputs that balance.
2) Prompts the user to enter the annual interest rate for the account and inputs the interest rate.
3) If the interest rate was not entered in decimal form, it converts it to a decimal.
4) Calculates twice the current balance and set this equal to the target balance;
5) Initializes the year counter that will keep track of the number of years it takes.
6) Calculates the balance of the account as it continues to earn interest until the balance in the account has reached or exceeded the target balance (each year the new balance is equal to the old balance plus the old balance times the interest rate);
7) Output the number of years it takes to reach the target balance.

Note: each row (1-7) in the table given below refers to the description (1 - 7) given above.


output _______________

input balance


output _______________

input rateOfReturn


if rateOfReturn >= 1 then

rateOfReturn = _____________ divided by 100

_________


targetBalance = 2 _________ balance



yearCounter = _____________


while balance < targetBalance

____________ = ____________ + balance times rateOfReturn

yearCounter = ______________

endwhile


output "It will take " + ____________ + "years to double your balance."

Any help would be greatly appreciated.
Please delete this post after 1.5 hours

Method
12-19-2008, 02:30 AM
For the first one, you probably instantiate totalSales at 0. Then, when you're adding to it, you probably can do totalSales = totalSales + salesData[monthNumber]. Finding the number of months above the average is easy - loop through each value of salesData and increment a counting variable if the sales for that month is greater than salesAverage.

The first two outputs for the second one are probably just strings asking for the information needed. Those are easy. Third spot should be rateOfReturn. Number four seems as simple as multiplying the two, but I'm not sure about it. The fifth one should be zero. The two blanks on number six are both balance. And finally, number seven is yearCounter.

This coding style is really weird, so forgive me if I couldn't figure out everything. I'm more used to Java. Good luck. :p

Moloch
12-19-2008, 02:41 AM
Hey thanks :D we're not dealing with any specific language atm just psuedocode or "computer language in english" you we're a big help though thanks :D