Starting from:

$30

CSCI1300 Homework 1-Algorithm and Pseudocode Solved


 

In your algorithms, use​ indentation to show that a line in the algorithm is inside of a loop or a conditional.


For example:

if x equals y        output(x) 
 

The line output(x) only executes if x equals y is true. As a result output(x) is indented under the if statement.​ 

Note:  

1.    Please make sure that what you submit is not code in any language (cpp, python, etc).

Merely produce pseudocode using algorithm rules.

2.    Examples of good pseudocode are found her​               e.​

3.    Your work should be typed​ .​ Submit your assignment as a PDF​ to Homewor​ k 1 on Moodle.  
 

Problem Set

1.           The​ U.S. Census provides information about the current U.S. population as well as approximate rates of change. Using those rates and the current US population, write an algorithm to calculate the U.S. population in exactly one year (365 days).

Your algorithm should output the result of your calculations. Three rates of change are provided:

A.    There is a birth every 8 seconds

B.    There is a death every 12 seconds

C.   There is a new immigrant every 27 seconds

Current U.S. population: 328,441,687

2.      A​ day has 86,400 seconds (24⨉60⨉60). Given a number of seconds in the range of 0 to 1,000,000 seconds, output the time as days, hours, minutes, and seconds for a 24 ​ hour clock. For example, 70,000 seconds is 0 days, 19 hours, 26 minutes, and 40 seconds. Your program should have user input that is the number of seconds to convert, and then use that number in your calculations. If your results are W, X, Y, and Z, then your output should be displayed as : The time is W days, X hours, Y minutes, and Z seconds.

3.            The​ Zootopia Police Department is recruiting new officers and has come up with an innovative equation to hire. They define hireScore​ as a weighted sum of agility​ ,​ strength, and ​ speed​ .​  hireScore = 1.8 * ​ agility​ + 2.16 * ​ strength ​ +​ 3.24 * speed​

The candidate for this hiring season are foxes, bunnies, and sloths. Chief Bogo has requested you to write a program that takes in these attributes and process a higreScore​ for the candidate.  

 

The program should provide a menu to choose the anthropomorphic animal. The menu should have the following options:

1.    Fox  

2.    Bunny

3.    Sloth

4.    Quit

Once an animal is selected, the program should ask the two of the characteristics based on the animal

1.    For fox, take input for agility​             and ​     strength​          

2.    For bunny, take input for agility​      and ​     speed​   

3.    For Sloth, take input for strength​     and ​     speed​   

Write an algorithm to compute the hireScore​ ​ based on the inputs using the weighted sum formula. When you compute the hireScore, the third characteristic would be 0. The computed hireScore​ should​ be displayed on the screen. The menu will run in a loop, continually offering Bogo four options until he chooses to quit.

4.A.       A​ bank account has an initial deposit of $10,000. Every month $500 is withdrawn to meet college expenses. After the money is withdrawn, an interest is computed at the rate of 6 percent per annum (0.5 percent per month). This interest is compounded monthly. Write an algorithm to find how many years it takes for the account balance to become $0.


Hint: ​Create a table with money that is getting compounded and the money that is withdrawn and calculate by hand what happens in the first 5 months. Then use the pattern to help you figure out the algorithm.


4.B.       Make​           changes to the algorithm to ask the user to input the values for principal, rate and monthly expenditure. Is there a scenario where the algorithm will not terminate (maybe enter an infinite loop)? If so, make changes to the algorithm so that it always terminates.
 

5.          Write​ an algorithm that will ask the user to enter 10 characters. Letters ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ in the English alphabet are vowels. The algorithm should then count​ and​ display the total number of vowels among the 10 characters entered by the user.
 

6.            In​ science, the temperature is always described in Celsius, but in the U.S. we tend to use Fahrenheit. Write an algorithm that takes user input for Fahrenheit and converts it into Celsius. The formula is:


Celsius = 59 (Fahrenheit − 32)  
 

7.            Punith​ is a student in CSCI 1300 in this semester. He’s writing a program that prints “Hello​ 1300!”,​ but it’s not working well. Describe two compile-time errors and one run-time error and how to fix them. (The cpp file is available on Moodl​ e.​ Try to run it by yourself)

 

  

 

More products