Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers!
To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest.
Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money!
Lesson learned: whether it’s your code or your money, save early and save often…
Sample run 1:
Enter the principle: 2000
Enter the annual addition: 300
Enter the number of years to grow: 10
Enter the interest rate as a percentage: 10
Year 0: $2000
Year 1: $2530
Year 2: $3113
Year 3: $3754.3
Year 4: $4459.73
Year 5: $5235.7
Year 6: $6089.27
Year 7: $7028.2
Year 8: $8061.02
Year 9: $9197.12
Year 10: $10446.8
Sample run 2 (yeah, that’s $9.4MM):
Enter the principle: 5000
Enter the annual addition: 1000
Enter the number of years to grow: 67
Enter the interest rate as a percentage: 10
Year 0: $5000
Year 1: $6600
Year 2: $8360
Year 3: $10296
Year 4: $12425.6
Year 5: $14768.2
.
.
Year 59: $4.41782e+06
Year 60: $4.86071e+06
Year 61: $5.34788e+06
Year 62: $5.88376e+06
Year 63: $6.47324e+06
Year 64: $7.12167e+06
Year 65: $7.83493e+06
Year 66: $8.61952e+06
Year 67: $9.48258e+06
please in pseudocode and c++. thank you! sorry about that.
In: Computer Science
In: Computer Science
C programming - Implement a dynamic array, please read and implement the dynarray.c file with what is given
dynarray.h
/*
* This file contains the definition of the interface for the
dynamic array
* you'll implement. You can find descriptions of the dynamic array
functions,
* including their parameters and their return values, in
dynarray.c. You
* should not modify anything in this file.
*/
#ifndef __DYNARRAY_H
#define __DYNARRAY_H
/*
* Structure used to represent a dynamic array.
*/
struct dynarray;
/*
* Dynamic array interface function prototypes. Refer to dynarray.c
for
* documentation about each of these functions.
*/
struct dynarray* dynarray_create();
void dynarray_free(struct dynarray* da);
int dynarray_size(struct dynarray* da);
void dynarray_insert(struct dynarray* da, void* val);
void dynarray_remove(struct dynarray* da, int idx);
void* dynarray_get(struct dynarray* da, int idx);
void dynarray_set(struct dynarray* da, int idx, void* val);
#endif
dynarray.c
#include
#include "dynarray.h"
/*
* This is the definition of the dynamic array structure you'll use
for your
* implementation. Importantly, your dynamic array implementation
will store
* each data element as a void* value. This will permit data of any
type to
* be stored in your array. Because each individual element will be
stored in
* your array as type void*, the data array needs to be an array of
void*.
* Hence it is of type void**.
*
* You should not modify this structure.
*/
struct dynarray {
void** data;
int size;
int capacity;
};
/*
* This function should allocate and initialize a new, empty dynamic
array and
* return a pointer to it. The array you allocate should have an
initial
* capacity of 2.
*/
struct dynarray* dynarray_create() {
return NULL;
}
/*
* This function should free the memory associated with a dynamic
array. In
* particular, while this function should up all memory used in the
array
* itself (i.e. the underlying `data` array), it should not free any
memory
* allocated to the pointer values stored in the array. In other
words, this
* function does not need to *traverse* the array and free the
individual
* elements. This is the responsibility of the caller.
*
* Params:
* da - the dynamic array to be destroyed. May not be NULL.
*/
void dynarray_free(struct dynarray* da) {
return;
}
/*
* This function should return the size of a given dynamic array
(i.e. the
* number of elements stored in it, not the capacity).
*/
int dynarray_size(struct dynarray* da) {
return 0;
}
/*
* This function should insert a new value to a given dynamic array.
For
* simplicity, this function should only insert elements at the
*end* of the
* array. In other words, it should always insert the new element
immediately
* after the current last element of the array. If there is not
enough space
* in the dynamic array to store the element being inserted, this
function
* should double the size of the array.
*
* Params:
* da - the dynamic array into which to insert an element. May not
be NULL.
* val - the value to be inserted. Note that this parameter has type
void*,
* which means that a pointer of any type can be passed.
*/
void dynarray_insert(struct dynarray* da, void* val) {
return;
}
/*
* This function should remove an element at a specified index from
a dynamic
* array. All existing elements following the specified index should
be moved
* forward to fill in the gap left by the removed element. In other
words, if
* the element at index i is removed, then the element at index i+1
should be
* moved forward to index i, the element at index i+2 should be
moved forward
* to index i+1, the element at index i+3 should be moved forward to
index i+2,
* and so forth.
*
* Params:
* da - the dynamic array from which to remove an element. May not
be NULL.
* idx - the index of the element to be removed. The value of `idx`
must be
* between 0 (inclusive) and n (exclusive), where n is the number
of
* elements stored in the array.
*/
void dynarray_remove(struct dynarray* da, int idx) {
return;
}
/*
* This function should return the value of an existing element a
dynamic
* array. Note that this value should be returned as type
void*.
*
* Params:
* da - the dynamic array from which to get a value. May not be
NULL.
* idx - the index of the element whose value should be returned.
The value
* of `idx` must be between 0 (inclusive) and n (exclusive), where n
is the
* number of elements stored in the array.
*/
void* dynarray_get(struct dynarray* da, int idx) {
return NULL;
}
/*
* This function should update (i.e. overwrite) the value of an
existing
* element in a dynamic array.
*
* Params:
* da - the dynamic array in which to set a value. May not be
NULL.
* idx - the index of the element whose value should be updated. The
value
* of `idx` must be between 0 (inclusive) and n (exclusive), where n
is the
* number of elements stored in the array.
* val - the new value to be set. Note that this parameter has type
void*,
* which means that a pointer of any type can be passed.
*/
void dynarray_set(struct dynarray* da, int idx, void* val) {
return;
}
In: Computer Science
2) You've been hired by Superfluous Stats to write a C++ console application that analyzes a string. Prompt for and read from the user a string that may contain spaces. Then prompt for and read from the user a single character. Print the following stats about the string and character inputs. Use formatted output manipulators (setw, left/right) to print the following rows about the string:
● The string value.
● The string length.
● The spot, if any, where the character is found within the string.
And the following rows about the character:
● The character value.
● Whether the character is an alphabetic character.
● Whether the character is a numeric character.
● Whether the character is a punctuation character.
And columns:
● A left-justified label.
● A right-justified value.
Define constants for the column widths. The output should look like this:
Welcome to Superfluous Stats
----------------------------
Enter a string: Detroit Michigan
Enter a character: r
String s
Value: Detroit Michigan
Length: 16
Index: 3
Character c
Value: r
Is alpha? 2
Is digit? 0
Is punctuation? 0
End of Superfluous Stats
Note that you may get a value for true that is not 1. Do not use this sample input for the final run that is pasted below.
In: Computer Science
For the following function, what are the best types for the parameters (can be used for all parameters)? (best = will not cause errors, will compute what is intended.)
For example, if you select "string" that means that a call with 3 string values—add_and_mult("Hi", "bye", "llama") is a great choice.
def add_and_mult(num1, num2, num3): sub_val1 = num1 * 60 sub_val2 = (sub_val1 + num2) * 60 answer = sub_val2 + num3 print("Wow! that's " + str(answer))
A. int
B. float
C. string
D. boolean
In: Computer Science
can you please look at the following code and fix it for me so that it does not have any syntax errors. also can you tell me what was fixed
/**
* Driver program to demonstrate calling methods of Client
class.
*
* @author Doyt Perry/Tina Comston
* @version Fall 2019
*/
public class ClientDemo
{
public static void main()
{
/**
* main method - makes this an executable program.
*/
// create a client with placeholder values
System.out.println("Client with default information");
// Create a client object using first constructor
Client client1 = new Client();
// Display information about the client
System.out.println(client1.toString());
System.out.println();
System.out.println("Create a client by providing
information");
// client last name - Jameson
// client first name - Rebecca
// client age - 32
// client height - 65
// client weight - 130
Client client2 = new Client("Jameson", "Rebecca",
32, 65, 130);
// Display information about the client
System.out.println(client2.toString());
// Display the first name
System.out.println("original first name = " +
client2.getfirstname());
// set the first name to the value Rachel
client2.setFirstName("Rachel");
// Retrieve and dislplay the client first name
System.out.println("new first name = " +
client2.getFirstName());
// Display information about the client
System.out.println(client2.toString());
// set their weight to 180
client2.setWeight(180);
// Display information about the client
System.out.println(client2.toString());
}
}
In: Computer Science
2) Show how each of the following signed, decimal integers would be stored in 16-bit two's complement format. Give your answer in hexadecimal.
a) -21 (5 points)
b) 4096 (5 points)
In: Computer Science
* what are some negative consequences of IT security?
* what are the 4 ways to respond to risk give example? *
give example of information that an employee should not reveal?
In: Computer Science
You are asked to design a database to support a Instant Recruitment System of casual staff for a school. The major business requirements are summarised below in the Mini Case: An Instant Recruitment System. You are asked to develop a detailed Entity-Relationship model for this mini case. Your ER model should consist of a detailed ER diagram integrated with itemised discussions on the features of the entities and relationships and all the assumptions you made where applicable. The ER diagram and the accompanying document should identify keys, constraints, entity types, relationship types, specialisation/generalisation if any, etc. You must use the same notation scheme for the ER diagram as the textbook (use UML notations as shown in the last page of the textbook, and don't use Crew Foot notations), and the ER diagram should be strictly in the way the textbook uses for.
In: Computer Science
write a python script to calculate the return of a stock with 10years of historical data/returns
In: Computer Science
Please solve all parts of the following question on MATLAB.
1. Penn State football travels to Ohio State to play the Buckeyes on Nov 23, 2019. The official capacity of Ohio Stadium is 104,944. Let’s say that the stadium is filled at the beginning of the game, but every time Penn State scores a touchdown half of the fans leave. How many touchdowns does Penn State have to score until there is just one fan left in the stadium?
a. construct a two-column matrix in which one column is number of touchdowns and the other column is number of people in the stadium.
b. plot touchdown number vs. number of fans on linear axes. The satisfactory plot will include: a title, and labeled axes. Since you are plotting discrete data points, please plot them with a symbol and connect the symbols with a line. All fonts should be large enough to be legible. You may choose the aspect ratio of your plot and what kind of symbol and line style to use.
c. redo the plot, but this time with a logarithmic y axis.
In: Computer Science
Describe the difference between classification, clustering, and association rules. Be specific and provide details.
In: Computer Science
Python Problem
Problem 1:
In this problem you are asked to write a Python program to find the greatest and smallest elements in the list.
The user gives the size of the list and its elements (positive and negative integers) as the input.
Sample Output:
Enter size of the list: 7
Enter element: 2
Enter element: 3
Enter element: 4
Enter element: 6
Enter element: 8
Enter element: 10
Enter element: 12
Greatest element in the list is: 12
Smallest element in the list is: 2
Hit enter to end program
------------------------------------------------------------------------------------------
Problem 2:
In this problem you are asked to write a Python program you are asked to perform multiple operations on a list.
What you need to do:
Ask the user what is the length of the list.
Ask the user to enter string values into a list.
Print the first 4 and last 4 elements in the list.
Ask the user if he/ she wants to insert elements to the list or delete the elements from the list.
Repeat step 4 until the user chooses a ‘NO’.
Sample Output:
Enter size of list: 5
Enter a string value: john Enter a string value: mary
Enter a string value: steve
Enter a string value: julia
Enter a string value: jake
The elements in the list:
['john', 'mary', 'steve', 'julia', 'jake']
The first four elements in the list: ['john', 'mary', 'steve', 'julia']
The last four elements in the list: ['mary', 'steve', 'julia', 'jake']
Want to insert (i) or delete (d) elements in the list: i Enter
the position to insert: 5
Enter the value to insert: lara
The modified list:
['john', 'mary', 'steve', 'julia', 'jake', 'lara']
Want to insert or delete more elements (y/n): y
Want to insert (i) or delete (d) elements in the list: i Enter
the position to insert: 2
Enter the value to insert: Jacob
The modified list:
['john', 'mary', 'jacob', 'steve', 'julia', 'jake', 'lara']
Want to insert or delete more elements (y/n): y
Want to insert (i) or delete (d) elements in the list: d Enter the index of the value to be deleted: 4
The modified list:
['john', 'mary', 'jacob', 'steve', 'jake', 'lara']
Want to insert or delete more elements (y/n): n
Hit enter to end program
In: Computer Science
# print out the steps to make chex mix, taking into account whether or not to include peanuts
# Here is the pseudo code we developed earlier:
#
#Get Bowl
#Add wheat Chex
#Add cheez-its
#Add Pretzels
#Add m & ms (why? – just taking it from the video…)
#If no peanut allergy
# Add peanuts
#else (there was a peanut allergy)
# if we have another bowl
# get second bowl
# put some of the mix so far into the second bowl
# add peanuts to second bowl
# else (at this point there was a peanut allergy, but no second
bowl)
# don’t do anything. We’re done.
# Here is the start of the Python code
print("Get Bowl")
print("Add wheat chex to bowl")
print("Add cheez-its to bowl")
print("Add pretzels to bowl")
print("Add m & ms to bowl")
# Note that the string in the following prompt has embedded
single quotes inside double quotes
peanut_allergy = input("Is there a peanut allergy? (enter 'yes' or
'no')")
# finish the code
# when it's time to ask for the second bowl, use this as the
prompt:
# "Is there a second bowl? (enter 'yes' or 'no')"
In: Computer Science
Referencing SQL Databases
Elaborate on a scenario where you can apply data manipulation commands and transaction controls.
In: Computer Science