Write a C program that creates a structure and displays its content. • Create a struct that will be used to hold a student's name, age, and year in school (Freshman, Sophomore, Junior, or Senior) • Within function main, dynamically allocate space to hold the structure and assign a pointer to point to the memory space allocated • Read in (from the keyboard) the student's name, age, and year in school • Create a separate function with the prototype: void display (struct student *) that can be used to display the contents of a single structure • Call this function twice - once for the original contents of the structure and again when the structure has been modified (Display year in school as indicated above, not 1, 2, 3, 4) • Increase the student's age by one and upgrade their year in school one level (unless they are already a Senior) • Free up the memory space before exiting
In: Computer Science
Exercise 5 (1 pt for each correct answer)
For each of the following statements indicate whether it is true, false, or unknown.
Bonus exercise (2 pts)
Show that if P=NP then there is a polynomial-time algorithm for the following search problem: given a graph, find its largest clique.
In: Computer Science
A hospital has a large number of registered physicians. Attributes of PHYSICIAN include Physician ID (the identifier) and specialty. Patients are admitted to the hospital by physicians. Attributes of PATIENT include patient ID(identifier) and patient name. Any patient who is admitted must have exactly one admitting physician. A physician may optionally admit any number of patients. Once admitted, a given patient must be treated by at least one physician. A particular physician may treat any number of patients or none at all. Whenever a patient is treated by a physician, the hospital wishes to record the details of the treatment (Treatment Detail). Components of Treatment Detail include date, time, and results.
Part C - UML Diagramming:
Recall the EER diagram you made for Medical Solutions Hospital in Part A. Use Draw.io or Visio to construct a UML diagram from your EER diagram. The UML diagram should have spaces for both fields/attributes and methods. Both Visio and Draw.io have built-in templates for UML diagramming. Be sure to add the multiplicities (like cardinalities).
Include:
What is possible to express with a UML diagram that is not possible to express with an EER diagram? Are there any limitations compared to an EER diagram?
In: Computer Science
Lab 3-5:
Activity 5-5: Using Condition Statements 10 minutes
Objective: Create a script with if, then, and else statements.
Description: In this activity, you create a shell script that tests whether a file the user specifies exists and uses output and error redirection to do some simple command validation.
NOTE:
If necessary, start a virtual machine in the server mode, and sign-on. This script will determine if a user has sudo permission and then as such can execute the find command and traverse the hierarchy without Permission denied errors.
Make a subdirectory in your home directory and call it scripts (for roots scripts).
Exit insert mode and switch to extended mode. Save your changes and exit the vimeditor.
Give the owner execute permission to run the script. Run the script searching for a valid file, like bash.
What command did you use to run the script?
Answer:____________________________
Explain how you would test the script to make sure it was working.
Answer:___________________________________________
In: Computer Science
Mac OS X Directory Structure
Outline how to organize files and directories. Describe preferences for file names and how the concepts of a hierarchical directory structure could improve existing method of storage. If useing an alternative method, justify its use and benefits over and above basic approaches.
In: Computer Science
Write a C program to control an autonomous robot. It runs on two wheels, each wheel connected to a DC motor. If both wheels run at the same speed, robot moves forward. If the right wheel runs slower, robot makes a right turn. There are two sensors mounted on the robot that can detect an obstacle, one in the front, one on the right.
Once the robot is turned on, it moves forward at 80% of the maximum possible speed. When an obstacle is detected in front, if there is nothing blocking on the right side; it slows down to 40% of maximum speed and then it makes a right turn. Unless there is an obstacle on the right side too, then the robot will stop.
You must use PWM to control the wheels. The sensor outputs are digital, the mbed board will detect low when no obstacle and will detect high, when there is an obstacle. This is pin connections for this robot.
Device LPC1768 mbed pin
Right wheel pin 21
Left wheel pin 22
Front sensor pin 10
Right sensor pin 11
Use a flowchart to show the algorithm of your program.
In: Computer Science
1. Starting with an empty tree, show each step in the construction of an AVL tree using the following input in the order given. For full credit, you must show the tree after each new input is added. 16, 7, 14, 18, 6, 17, 2, 5, 13, 22, 4 (6 pts.)
2. Show how the AVL tree in previous changes with the following operations. For full credit, you must show the tree after each iteration.
Remove: 17
Remove: 18
Remove: 22
In: Computer Science
One of your chapters this week is on recursion. Below are the three recursive algorithms laws:
1. A recursive algorithm must have a base case.
2. A recursive algorithm must change its state and move toward the base case.
3. A recursive algorithm must call itself, recursively.
Do you have any examples of recursive algorithms used in the real-world?
Approximately 175 words in the answer.
In: Computer Science
ERD Lucid chart with Crow's foot notation for the following. include all entities, attributes, and correct carnality in relationships between entities. primary and foreign keys.
You have been asked to build a database for a sportswear company called Ath Fleet.
The company owner needs to keep track of the customers that buy their products, the employees that work at Ath Fleet, the vendors that provide them with products, and the products themselves.
Each vendor has contact with one employee representative and needs this support.
Employees in their first year usually don't have vendors to support, as they are learning the ropes, but as they work there longer and more vendors are reached, they may be assigned their only vendor.
The owner wants to track employee names and email addresses, as well as vendor names and locations.Vendors provide products to Ath Fleet, like shoes, apparel, and equipment.
Each product they sell comes from only one vendor. Some products are made in house, but if a vendor is in the system they must have provided a product.
The owner wants to track product names and each product's unique SKU.
Finally, customers purchase products from Ath Fleet and that transaction data needs to be recorded. Each product is often purchased by lots of customers, especially if it is popular.
Customers are only put in the system if they have made a purchase, but a product does not need to have been purchased to be stored.
The owner wants to keep track of customer names and email addresses.
In: Computer Science
CompSci 251: Intermediate Computer ProgrammingLab 3 – 2019
Introduction
This lab will focus on creating a Movie class conforming to the diagram above. From this class Movie objects can be instantiated and used in a running program. I have provided a mostly completely driver, you will need to add a few lines of code where specified.
What you need to do
Declare you instance variables at the top of the class.
Write a specifying constructor. No default constructor is required.
Write getName and setName. There are no restrictions on the setting the name.
Write getMinutes and setMinutes. When setting minutes, it is not allowed to be negative.
Write getTomatoScore and setTomatoScore. When setting tomato score, score is not allowed
to be negative or over 100.
Write isFresh. A score is considered fresh if it is 60 or above. It is rotten otherwise.
Write display. Print out the name, the total minutes, and if the movie is “Fresh” or “Rotten”.
Remember, you have method which tells you this now.
The driver is mostly complete. I placed one TODO, add a new movie of your choice to the array
that stores movies (called myCollection) in the driver.
Your output should match the output below plus the one movie you add to it. Pay attention to how objects are accessed in the driver. See your TA when your output is correct.
Output:
Here are all the movies in my collection of movies.
Movie: Batman The Dark Knight Length: 2hrs 32min.
Tomato Meter: Fresh
Movie: Avengers: Endgame Length: 3hrs 2min. Tomato Meter: Fresh
Movie: The GodFather Length: 2hrs 58min. Tomato Meter: Fresh
Movie: Suicide Squad Length: 2hrs 17min. Tomato Meter: Rotten
//The movie you add will print out here.
_______________________________________________ Here are the Fresh movies.
Batman The Dark Knight is fresh. Avengers: Endgame is
fresh.
The GodFather is fresh.
Here are the Rotten movies. Suicide Squad is rotten.
//The movie you add will print out here, it’s score will determine if fresh or not.
_______________________________________________
The movie Harry Potter and the Prisoner of Azkaban was created.
Is Harry Potter and the Prisoner of Azkaban a long movie? Yes, it is a bit long.
Can I set the minutes of Harry Potter and the Prisoner of
Azkaban to a negative number?
It did NOT work. Negative runtimes are not allowed.
Can I set tomato score of Harry Potter and the Prisoner of
Azkaban to a negative number?
It did NOT work. Negative scores are not allowed.
Can I set tomato score of Harry Potter and the Prisoner of
Azkaban to a number greater than 100?
It did NOT work. Still the best Harry Potter movie out all the
movies though.
Given Driver
public class MovieDriver {
public static void main (String [] args){
Movie[] myCollection = new Movie[5];
myCollection[0] = new Movie("Batman The Dark Knight", 152, 94);
myCollection[1] = new Movie("Avengers: Endgame", 182, 94);
myCollection[2] = new Movie("The GodFather", 178, 98);
myCollection[3] = new Movie("Suicide Squad", 137, 27);
//TODO
//Initialize the variable below and add it to myCollection at index 4.
//You can pick any movie you wish.
Movie yourMovie;
System.out.println("Here are all the movies in my collection of movies.\n");
for(int i = 0; i < myCollection.length; i++) {
if(myCollection[i] != null) {
myCollection[i].display();
System.out.println();
}
}
System.out.println("_______________________________________________");
System.out.println("\nHere are the Fresh movies.\n");
for(int i = 0; i < myCollection.length; i++) {
if(myCollection[i] != null && myCollection[i].isFresh()) {
System.out.println(myCollection[i].getName() + " is fresh.");
}
}
System.out.println();
System.out.println("Here are the Rotten movies.\n");
for(Movie movieTmp: myCollection){
if (movieTmp != null && !movieTmp.isFresh())
System.out.println(movieTmp.getName() + " is rotten.");
}
System.out.println("_______________________________________________\n");
Movie harryPotter = new Movie("Harry Potter and the Prisoner of Azkaban", 144, 91);
System.out.println("The movie " + harryPotter.getName() + " was created.\n");
System.out.println("Is " + harryPotter.getName() + " a long movie?");
if(harryPotter.getMinutes() > 120) {
System.out.println("Yes, it is a bit long.\n");
} else {
System.out.println("Nope, that isn't too bad.\n");
}
System.out.println("Can I set the minutes of " + harryPotter.getName() + " to a negative number?");
harryPotter.setMinutes(-5);
if(harryPotter.getMinutes() == -5) {
System.out.println("It worked. The runtime is -5 minutes.\n");
} else {
System.out.println("It did NOT work. Negative runtimes are not allowed.\n");
}
System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a negative number?");
harryPotter.setTomatoScore(-100);
if(harryPotter.getTomatoScore() == -100) {
System.out.println("It worked. The score is -100. This movie is terrible according to the site.\n");
} else {
System.out.println("It did NOT work. Negative scores are not allowed.\n");
}
System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a number greater than 100?");
harryPotter.setTomatoScore(101);
if(harryPotter.getTomatoScore() == 101) {
System.out.println("It worked. The score is 101. Best Harry Potter movie ever!\n");
} else {
System.out.println("It did NOT work. Still the best Harry Potter movie out all the movies though.\n");
}
}
}
In: Computer Science
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you
/**
* Driver to demonstrate WholeLifePolicy class.
*
* @author Tina Comston
* @version Fall 2019
*/
public class WholeLifePolicyDriver
{
/**
* Creates WholeLifePolicy object, calls methods, displays
values.
*
*/
public static void main()
{
WholeLifePolicyDriver myDriver = new WholeLifePolicyDriver();
// create a policy
WholeLifePolicy policy = new WholeLifePolicy("WLP1234567",
50000, 20);
// display values
myDriver.displayPolicy(policy);
// now change some values
policy.setPolicyNum("WLP9871235");
policy.setFaceValue(75000);
policy.setPolicyYrs(15);
// display again
myDriver.displayPolicy(policy);
// Display termination value at 10 years, borrowed $25K
System.out.printf("Termination value @10 years 25K borrowed "
+
"is %.2f \n", policy.surrenderVal(10.0, 25000));
}
/**
* Displays data for a policy.
*
*/
private void displayPolicy(WholeLifePolicy wlp)
{
System.out.println("*******************************************");
System.out.println(wlp.toString());
System.out.println();
}
}
In: Computer Science
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you
/**
* Models a Whole Life Policy.
*
* @author Tina Comston
* @version Fall 2019
*/
public class WholeLifePolicy
{
// instance variables
private double faceValue;
// your code here - code the remaining instance field
// constants
/**
* surrender rate.
*/
public static final double SURRENDER_RATE = .65;
/**
* ADMIN FEE.
*/
public static final double ADMIN_FEE = .005;
// constructors and methods
/**
* Default constructor for objects of class WholeLifePolicy.
* This is the default constructor.
*
* Default values are:
* face value = 0.0
* policy years = 0
* policy number WLP9999999
*
*/
public WholeLifePolicy()
{
this.setPolicyNum("WLP9999999");
this.setFaceValue(0.0);
this.setPolicyYrs(0);
}
/**
* Explicit constructor for objects of class WholeLifePolicy.
*
* @param inPolicyNum Number of the policy
* @param inFaceValue Face Value of policy.
* @param inPolicyYrs Length of policy in years.
*
*/
public WholeLifePolicy(String inPolicyNum, double
inFaceValue,
int inPolicyYrs)
{
// your code here, complete the constructor
}
/**
* Copy constructor for objects of class WholeLifePolicy.
* This constructor creates an exact copy of a
* WholeLifePolicy object.
*
* @param inPolicyObject WholeLifePolicy object.
*
*/
public WholeLifePolicy(WholeLifePolicy inPolicyObject)
{
this.setPolicyNum(inPolicyObject.getPolicyNum());
// your code here, complete the constructor
}
/**
* Set the Policy Face Value.
*
* @param inFaceValue Face Value of policy.
*
*/
public void setFaceValue(double inFaceValue)
{
this.faceValue = faceValue;
}
/**
* Get the Policy Face Value.
*
* @return double Face Value of policy.
*
*/
public double getFaceValue()
{
return this.faceValue;
}
/**
* Set the Policy Years.
*
* @param inPolicyYrs Length of policy in years.
*
*/
public void setPolicyYrs(int inPolicyYrs)
{
// your code here, complete the method
}
/**
* Get the Policy Years.
*
* @return int Length of policy in years.
*
*/
public int getPolicyYrs()
{
// your code here, replace the following statement
return 9999;
}
/**
* Set the Policy Number. Use to override the default
* policy number or for copy object processing.
*
* @param inPolicyNum Policy Number.
*
*/
public void setPolicyNum(String inPolicyNum)
{
// your code here, complete the method
}
/**
* Get the Policy Number.
*
* @return String Policy Number.
*
*/
public String getPolicyNum()
{
// your code here, replace the following statement
return "incorrect value";
}
/**
* Calculate surrender value.
* Surrender value is calculated as:
* (surrender rate * face value) *
* (years held / policy years) - amount borrowed -
* (face value * administrative fee)
*
* @param inYrsHeld Length in years policy held to date.
* @param inBorAmt Amount borrowed against policy if any.
*
* @return double Policy surrender value.
*
*/
public double surrenderVal(double inYrsHeld, double inBorAmt)
{
// Termination value is the surrender rate percentage of the
face
// value as a proportion of the years held to policy years less
any
// amount borrowed on the policy less a ADMINFEE on the
// face value.
// your code here, compute the surrender value and replace
the
// following line
return 99999.99;
}
/**
* Return a string representation of the WholeLifePolicy.
*
* @return String output string.
*
* <pre>
* Produce output in the following format:
*
* Policy Information:
* Policy #: WLP1000000
* Policy Years: 20
* Face Value: 50000.0
*
* </pre>
*/
public String toString()
{
String output = "Policy Information:\n";
output = output + "Policy #: " + this.getPolicyNum() + "\n";
// your code here, finish the output string
return output;
}
}
In: Computer Science
The Fibonacci series of numbers is a favorite of mathematicians, and goes as follows: 1, 1, 2, 3, 5, 8, 13, 21, . . . That is, the first two numbers are 1, and every subsequent number is the sum of the previous two. The mathematical definition as a recursive function is the following.
∀n = 0, 1, 2, . . .
F(n) = { 1 if n <=1
F(n-1) + F(n-2) if n > 1
The closed form of such function is in O(φ n ), where φ is a number called the golden ratio.
1. Coding: Write a Java class Fibonacci that has the following static methods.
(a) (20 points) A recursive method that returns F(n).
(b) (20 points) A non-recursive method that returns F(n).
(c) (10 points) A main method to obtain from the user the index n, and call the methods above one after the other. For each of the method calls, measure and display the running time using the following snippet of code.
...
// store the time now
long startTime = System.nanoTime();
// your method call here
...
// display the time elapsed
System.out.println("t = " +
(System.nanoTime() - startTime) + " nanosecs.");
2. Experiments: (10 points) Measure running times for different values of n and fill a table like the following. (You may need to adjust n to smaller values if it takes too long or your stack overflows, 0 points if you do not have at least 5 columns of measurements.)
n | 0 | 1 | 2 | 4 | 6 | 8 | 16
recursive | | | | | | |
non-recursive | | | | | | |
3. Analysis: For your recursive method:
(a) (10 points) What is the worst-case big-O running time with respect to n? (Explain how you computed the running time, 0 points if you do not say what is the basic operation counted and what counting rules you used.)
(b) (10 points) Are your measurements consistent with this big-O running time? (Explain using your measurements, 0 points if you do not say something like "looking at row recursive, when n is doubled the running time is xxx".)
For your non-recursive method:
(c) (10 points) What is the worst-case big-O running time with respect to n? (Explain how you computed the running time, 0 points if you do not say what is the basic operation counted and what counting rules you used.)
(d) 10 points Are your measurements consistent with this big-O running time? (Explain using your measurements, 0 points if you do not say something like "looking at row non-recursive, when n is doubled the running time is xxx".)
In: Computer Science
Hello, trying to create a three way currency conversion on python. One of the things I want to do is create an error message whenever there is an incorrect currency entered. So far, I have managed to display the error message in these two cases: when both From and To currencies are incorrect, and when only the From currency is incorrect. What can I do so that my program can also display a message when the To currency is only incorrect.
money = float(input("Please enter the From amount to be
converted: "))
fromCurrency = input("Please enter the From currency (USD, EUR, or
JYP): ")
toCurrency = input("Please enter the To currency (USD, EUR, or
JYP): ")
## conversions taken as of 9/26/19
# 1 USD = .91 EUR (1.1 factor), 1 USD = 107.63 JYP (.00929 factor),
1 EUR = 117.81 JYP (.0084 factor)
usdEur = money / 1.1
eurUsd = money * 1.1
usdJyp = money / .00929
jypUsd = money * .00929
eurJyp = money / .00848
jypEur = money * .00848
# Conversion from USD to other currencies
if fromCurrency.lower() == ("usd"):
if toCurrency.lower() == ("eur"):
result = usdEur
if toCurrency.lower() == ("jyp"):
result = usdJyp
print(money, fromCurrency, "equals", result, toCurrency)
elif fromCurrency.lower() == ("eur"):
if toCurrency.lower() == ("usd"):
result = eurUsd
if toCurrency.lower() == ("jyp"):
result = eurJyp
print(money, fromCurrency, "equals", result, toCurrency)
elif fromCurrency.lower() == ("jyp"):
if toCurrency.lower() == ("usd"):
result = jypUsd
if toCurrency.lower() == ("eur"):
result = jypEur
print(money, fromCurrency, "equals", result, toCurrency)
else: #does not work when 'to' currency is wrong
print("Error! Currency not available for conversion")
In: Computer Science
In java. Using a linked list only, iterator and scanner.
Develop a program to maintain a Linked List of homework assignments name and due date. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services each contained within its own method:
In: Computer Science