using python 3
2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000.
3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False.
4. In your main Python program write a for loop that counts from 1 to 1000 and calls this YesNo function inside the for loop and will print "The number xx is divisible by both 2 and 7 but not 70, or that are divisible by 57" if the YesNo function returns True. Otherwise it prints nothing. Note the print statement also prints the number where the xx is above.
In: Computer Science
Language java
Rewrite the method getMonthusing the "this" parameter
CODE:
import java.util.Scanner;
public class DateSecondTry
{
private String month;
private int day;
private int year; //a four digit number.
public void writeOutput()
{
System.out.println(month + " " + day + ", " + year);
}
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
month = keyboard.next();
day = keyboard.nextInt();
year = keyboard.nextInt();
}
public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
public int getMonth()
{
if (month.equalsIgnoreCase("January")) return 1;
else if (month.equalsIgnoreCase("February")) return 2;
else if (month.equalsIgnoreCase("March")) return 3;
else if (month.equalsIgnoreCase("April")) return 4;
else if (month.equalsIgnoreCase("May")) return 5;
else if (month.equalsIgnoreCase("June")) return 6;
else if (month.equalsIgnoreCase("July")) return 7;
else if (month.equalsIgnoreCase("August")) return 8;
else if (month.equalsIgnoreCase("September")) return 9;
else if (month.equalsIgnoreCase("October")) return 10;
else if (month.equalsIgnoreCase("November")) return 11;
else if (month.equalsIgnoreCase("December")) return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0; //Needed to keep the compiler happy
}
}
}
In: Computer Science
HOW TO PRINT THE CONTENTS OF A TWO-DIMENSIONAL ARRAY USING POINTER ARITHMETIC (USING FUNCTIONS)
(C++)
Fill out the function definition for "void print_2darray_pointer(double *twoDD, int row, int col)".
Should match the output from the function void print_2darray_subscript(double twoDD[][ARRAY_SIZE], int row, int col)
# include
using namespace std;
const int ARRAY_SIZE = 5;
const int DYNAMIC_SIZE = 15;
const int TIC_TAC_TOE_SIZE = 3;
// function definitions:
void print_2darray_subscript(double
twoDD[][ARRAY_SIZE], int row, int col)
// printing array using
subscripts
{
for (int i = 0; i < row;
i++)
{
for (int j = 0;
j < col; j++)
{
cout << twoDD[i][j] << " ";
}
cout <<
endl;
}
cout << endl;
}
void print_2darray_pointer(double *twoDD, int row,
int col)
// print array using pointer
arithmetic
{
for (int i = 0; i < row;
i++)
{
for (int j = 0;
j < col; j++)
{
// I tried doing this, but it didn't work : cout
<< *(*(twoDD + i) + j);
// our 2d array is layed out linearly in memory
as contiguous rows, one after another, there are #row rows
// each row has #col columns
// to compute the offset using pointer
math
// offset from twoDD: #row (i) * #col + #col
(j), result: pointer to array element
// ...
}
cout <<
endl;
}
cout << endl;
}
//------------------------------------------------------------------------------
int main()
{
// complete the following function
implementations
// Q#3 - pointer arithmetic, indexing multidimensional
arrays
double twoDDoubles[ARRAY_SIZE][ARRAY_SIZE] = {
{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}
};
cout << endl << "print 2d array of doubles" << endl << endl;
// print 2ddoubles via subscript operator
print_2darray_subscript(twoDDoubles, ARRAY_SIZE,
ARRAY_SIZE);
// print 2ddoubles via pointer arithmetic
print_2darray_pointer((double*)twoDDoubles,
ARRAY_SIZE, ARRAY_SIZE);
cout << endl << endl;
system("pause");
return 0;
}
In: Computer Science
More definitions and example for the following.
a. CPOE
b. Interface engine
c. Telehealth
d. EMR-EHR-PHR
e. Disc mirroring
In: Computer Science
In: Computer Science
In: Computer Science
MergeSort has a rather high memory space requirement, because every recursive call maintains a copy of the sorted subarrays that will be merged in the merge step. What is the memory space requirement in terms of O(.)? Describe how you would implement MergeSort in such a way that merge is done in-place and less memory space is needed? In-place means MergeSort does not take extra memory for the merge operation as in the default implementation.
In: Computer Science
PLEASE NO USE OF LINKED LIST OR ARRAYS(USE CHARACTER POINTERS INSTEAD) TO HOLD DATA STRUCTURES
This lab, for which you may work in groups of two, will require you to use a C structure to hold a record of any kind of data, i.e., address book, library of books as with chapter 14, etc. These records will be held in dynamic memory using memory allocation (malloc) to create new memory and the function (free) to release memory created via (malloc). Do not use linked lists for this assignment, we are using dynamic memory allocation to hold records, not using linked lists. The structures will act as an in memory database for your records (structures), and you will need to create enough memory to hold all of your records, but also when you remove records, you will need to allocate new memory, move the data over to that memory space, and free the old memory (instead of using a static size array). No use of arrays is allowed to hold your structures, but you can use arrays in other places in your program. Your program will prompt for information that will be added to a new structure that will be added when you call the add function. Delete is as simple as just taking the last record out of your database (i.e. no need to search for a “record” to delete - this assignment is about pointers and memory allocation / free, so no need to make the algorithm more complicated). In addition to your memory to hold your data / structures, your program will also need to hold a static duration memory type that will serve as the counter for how many times the database has changed. Along with the amount of times the database has changed, you will also need to have a variable to hold the number of records in your database, functions to calculate size (records multiplied by sizeof struct), and functions to add, print, and delete records. You will not be required to use lookup functions, print is just the entire database. To manage your in-memory database, you will need to use some pointers to hold locations of your data. Please take some time to write down examples of where you will need to have pointers. You will need to have at least a pointer to the beginning of your database memory, another to show which record you are on, but think about the need for other pointers when you think about functions that will delete a record, add a record, etc. One of the major points of this assignment is not just the ability to manage records in memory, it is also about how to manage the memory itself. There is a huge inherent danger in how memory is allocated and subsequently not released properly which will create a “memory leak” in your program which will consume memory over time and crash your system (due to all the memory being used, or your process hitting a max limit of memory). This will mean that you will need to manage how pointers are pointing at data very carefully as it is very easy to create a memory leak and your program will not crash, it will just not release memory properly. You will need a menu to prompt users for the above requirements that may look like: MENU ======= 1. Print all records 2. Print number of records 3. Print size of database 4. Add record 5. Delete record 6. Print number of accesses to database 7. Exit Once you have gathered the appropriate information you will need to manipulate the data to hold the data correctly, but we are not using File I/O to maintain state on the data (would require too much time). Your database is a memory only database, so once your program ends, your database is gone. Being this is the case, it will be important to create a header file that has some data in it (5-7 records), so you will not need to enter all the records every time.
In: Computer Science
You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm.
/*This function returns true if given linked list has a cycle, else returns false. */ static boolean hasCycle( Node head)
In: Computer Science
The below_freezing function takes a string as its parameter and return True if the temperature specified by the string is below freezing point for water. It returns False if the temperature is at or above the freezing point. The string takes the format of a decimal number followed by a letter where F stands for Fahrenheit, C for Celsius, and K for Kelvin. For example, below_freezing("45.5F") and below_freezing("300K") both return False. below_freezing("-1.2C") and below_freezing("272K") both return True It's critical that you include test case code to show proper testing. PLEASE DO IN PYTHON
In: Computer Science
read in firstNum.
2) read in secondNum.
3) run the loop, If secondNum is 0 then
print out firstNum, otherwise, temp =firstNum % secondNum, firstNum
= secondNum, secondNum = temp.
Your code MUST have your name, and date, and
description of the algorithms as comments.
Submit GCD.java file and the screen shoot of compile
and run result (image file or PDF file) from JGRASP.
//This program demonstrates parts of greatest common
divisor
// It shows how to calculate the remainder of two integers and
also
// how a while loop works with a place holder (temp) variable
// Algorithm
// Read in two positive integer
// Using a while loop, print the remainder value, and then
decrement the value
// Finally, print out the final value of gcd
import java.util.Scanner;
public class GCD {
public static void main(String[] args) {
int firstNum;
int secondNum;
int gcd =0;
Scanner input = new Scanner(
System.in );
//user input the first
number
……………………………………
……………………………………
……………………………………
//user input the second
number
………………………………………
………………………………………..
………………………………………..
//if the second number is
0
//while
loop
while ( secondNum !=
0){
int temp =
firstNum%secondNum;
……….............................................
........................................................
System.out.println(temp);
}
System.out.println("And finally gcd
has the value of " + gcd);
}// of main
} // of class GCD
In: Computer Science
Doing recursion to match digits of two inputted integers. Found this online and it works but I wanna understand how each line works. Like why x %10 == y%10 and calling DigitMatch(x/10,y/10)?
public int digitMatch(int x, int y){
if(x < 0 || y < 0){
throw new IllegalArgumentException();
}
else if(x < 10 || y < 10){
if(x % 10 == y % 10)
return 1;
else
return 0;
} else if( x % 10 == y % 10){
return 1 + digitMatch(x/10, y/10);
}
else{
return digitMatch(x/10,y/10);
}
In: Computer Science
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be displayed with 4 digits of precision after decimal point, in bold underline is what your user types in when they run the program): Enter Value 1: 2.34567 Enter Value 2: 3.45678 Enter Value 3: 1.23456 Enter Value 4: 5.67891 Enter Value 5: 4.56789 The values entered are: 2.3457, 3.4568, 1.2346, 5.6789, 4.5679 The minimum value is 1.2346 and maximum value is 5.6789 The average of these five values are: 3.4568
In: Computer Science
Write a brief explanation of why these commands function as described. 8. Why does `find . -name '*.pdf'` not find "BOOK.PDF" even if that file is in the current working directory? 9. Why does `find . -name 'pdf*'` not find "book.pdf" even if that file is in the current working directory? 10. Why does `find /etc -iname '*conf*'` return both directories and files?
In: Computer Science
My question is on this program I have difficulty i marked by ???
public class SortedSet { private Player[] players; private int count;
public SortedSet() { this.players = new Player[10]; }
/** * Adds the given player to the set in sorted order. Does not add
* the player if the case-insensitive name already exists in the set.
* Calls growArray() if the addition of the player will exceed the size
* of the current array. Uses an insertion sort algorithm to place the
* new player in the correct position in the set, taking advantage of
* the private swapPlayers method in this class.
* * @param player the player to add
* @return the index where the player was added, or -1 if not added
*/
public int add(Player player) {
My question is how to add sorted order with the player in the case-insensitive
????????????????????????????????????????????????????? and
return -1;
}
/**
* @param name the name of the player to remove
* @return true if removed, false if not found
*/
public boolean remove(String name) {
??????????????????????????????????????????????????????????????????????
How to removes the player with the given case-insensitive name from the set. return true;
}
/**
* @param name the player's name
* @return the index where the player is stored, or -1 if not found
*/
public int find(String name) {
?????????????????????????????????????????????????????????
How to Locates the player with the given case-insensitive name in the set. return 0;
}
/**
* @param index the index from which to retrieve the player
* @return the player object, or null if index is out of bounds.
*/
public Player get(int index) {
?????????????????????????????????????????????????????????
How to returns the player object stored at the given index. return null;
}
/**
* Provides access to the number of players currently in the set.
* @return the number of players */ public int size() { return count;
}
/**
* Provides access to the current capacity of the underlying array.
* @return the capacity of the array
*/
public int capacity() { return players.length;
}
/** Provides a default string representation of th sorted set. Takes
* advantage of Player's toString method to provide a single line String.
* Example: [ (Player: joe, Score: 100) (Player: fred, Score: 98) ]
* @return the string representing the entire set
*/ @Override
public String toString() {
??????????????????????????????????????
How to provides a default string ?????????
return null;
}
/**
* @param i the first index
* @param j the second index
*/
private void swapPlayers(int i, int j) {
??????????????????????????????????????????????????????
How to private method used during sorting to swap players in the underlying array.
}
private void growArray() {
???????????????????????????????????????????????????????????
How to private method used to double the array if adding a new player will exceed the size of the current array.
}
}
//----------------------------------------------------------------------------------------------------------------------------// //
players Classes public class Player implements Comparable {
//
fields private String name; private int score;
/**
* Full constructor.
* @param name the player's name
* @param score the player's highest score
*/
public Player(String name, int score) {
this.name = name; this.score = score;
}
/**
* Provides access to the player's name.
* @return the player's name
*/
public String getName() {
return name;
}
/**
* Allows the player's name to be set.
* @param name the player's name
*/
public void setName(String name) {
this.name = name;
}
/**
* Provides access to the player's highest score.
* @return the player's highest score
*/
public int getScore() {
return score;
}
/**
* Allows the player's highest score to be set.
* @param score the player's highest score
*/
public void setScore(int score) {
this.score = score;
}
/**
* Provides a default string representation of an object of this class.
* @return */ @Override public String toString() {
return "Player: " + name + ", Score: " + score;
}
/** * Provides a unique hash code for this object,
* based on the case-insensitive player name.
* @return the hash code
*/
@Override public int hashCode() {
int hash = 3;
hash = 83 * hash + Objects.hashCode(this.name.toLowerCase());
return hash;
}
/** * Reports if the given object is equal to this object,
* based on the case-insensitive player name.
* * @param obj the object to compare to this one
* @return true if the names are the same, false if not.
*/ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Player other = (Player) obj;
return this.name.equalsIgnoreCase(other.name);
}
/** * Compares the given object with this one to determine sort order.
* * @param other the other object to compare to this one
* @return a negative value if this object should come before the other one,
* a positive value if it should come after, or zero if they are the same
*/ @Override public int compareTo(Player other) { return other.score - this.score; } }
//----------------------------------------------------------------------------------------------------------------------------//
// Main class
public class Lab1 {
/** * All tests performed here in main method.
* * @param args the command line arguments
*/
public static void main(String[] args) {
SortedSet set = new SortedSet();
//test insertion for (int i = 0; i < 10; i++) {
if (set.add(new Player(String.valueOf((char) (i + 97)), i + 10)) != 0) {
System.out.println("INSERTION FAIL"); return; }
}
System.out.println("INSERTION PASS");
//test growing array
if (set.add(new Player("k", 9)) != 10) {
System.out.println("GROW FAIL"); return;
}
System.out.println("GROW PASS");
//test duplicate
if (set.add(new Player("D", 5)) != -1) {
System.out.println("DUPLICATE FAIL");
return;
}
System.out.println("DUPLICATE PASS");
//test valid remove
if (!set.remove("c")) {
System.out.println("VALID REMOVE FAIL");
return;
}
System.out.println("VALID REMOVE PASS");
//test invalid remove if (set.remove("z")) {
System.out.println("INVALID REMOVE FAIL");
return;
}
System.out.println("INVALID REMOVE PASS");
//test valid find
if (set.find("g") != 3) {
System.out.println("VALID FIND FAIL");
return;
}
System.out.println("VALID FIND PASS");
//test invalid find
if (set.find("z") != -1) {
System.out.println("INVALID FIND FAIL");
return;
}
System.out.println("INVALID FIND PASS");
//test valid get
if (set.get(0).getScore() != 19) {
System.out.println("VALID GET FAIL");
return;
}
System.out.println("VALID GET PASS");
//test invalid
get if (set.get(100) != null) {
System.out.println("INVALID GET FAIL");
return;
}
System.out.println("INVALID GET PASS");
//test toString method try { String str = set.toString();
if (str.equals("[ (Player: j, Score: 19) (Player: i, Score: 18) " + "(Player: h, Score: 17) (Player: g, Score: 16) " + "(Player: f, Score: 15) (Player: e, Score: 14) " + "(Player: d, Score: 13) (Player: b, Score: 11) " + "(Player: a, Score: 10) (Player: k, Score: 9) ]")) { System.out.println("TOSTRING PASS"); } else { System.out.println("TOSTRING FAIL"); } } catch (Exception e) { System.out.println("TOSTRING FAIL"); } //test proper capacity of array if (set.capacity() != 20) { System.out.println("SIMPLE CAPACITY FAIL"); return; } System.out.println("SIMPLE CAPACITY PASS"); for (int i = 0; i < 100; i++) { set.add(new Player((String.valueOf((char) (i + 97))) + i, i)); } if (set.capacity() != 160) { System.out.println("COMPLEX CAPACITY FAIL"); return; } System.out.println("COMPLEX CAPACITY PASS"); } }
In: Computer Science