Python
Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
In: Computer Science
ATestforPrimalityisthefollowing:
Given an integer n > 1, to test whether n is prime check to see if it is divisible by a prime number less than or equal to it’s square root. If it is not divisible by an of these numbers then it is prime.
We will show that this is a valid test.
∀n, r, s ∈ N+, r s ≤ n → (r ≤ √n ∨ s ≤ √n)
b) Prove ∀ n ∈ N+ , n is not prime →∃p ∈ N ,(p prime ∧ (p≤√n) ∧ p∣n )
(c) State the contrapositive of the statement of part(b).
In: Computer Science
// TESTING
//------------------------------------------------------------------------------
// TEST CASE 1
//
// DESCRIPTION
// Performs an acceptance test of the entire program.
//
// INPUT DATA (Note that the input data is read from a file named payroll.txt)
// Simpson Homer
// 15.25 84
// 2
//
// EXPECTED OUTPUT
// -----------------------------
// EMPLOYEE: Simpson, Homer
//
// PAY RATE: $ 15.25
// HOURS: 84.00
// GROSS PAY: $ 1311.50
// MED INS DEDUCT: $ 110.13
// 401K DEDUCT: $ 78.69
// FED TAX GROSS PAY: $ 1122.68
// TAX - FEDERAL: $ 89.48
// TAX - OASDI: $ 69.61
// TAX - MEDICARE: $ 16.28
// TAX - STATE: $ 38.62
// TAX - TOTAL: $ 213.98
// NET PAY: $ 908.70
// -----------------------------
//
// ACTUAL OUTPUT
// RESULT: Write FAIL/pass
#include <cstdlib> // For exit()
#include <fstream> // For ifstream, ofstream
#include <iomanip> // For setprecision(), setw()
#include <iostream> // For endl, fixed
#include <string> // For string class
using namespace std;
//==============================================================================
// FUNCTION PROTOTYPES
//
// Students: Some of the functions may require prototypes. For those that do,
// write the prototype in this section.
//==============================================================================
//==============================================================================
// NAMED CONSTANTS
//
// Students: Define named constants in this section.
//==============================================================================
// Define an int named constant ERR_OPEN_INPUT_FILE which is equivalent to 1.
int ERR_OPEN_INPUT_FILE = 1;
// Define an int named constant ERR_OPEN_OUTPUT_FILE which is equivalent to 2.
int ERR_OPEN_INPUT_FULE = 2;
// This is the percentage rate for calculating the OASDI deduction (this is com-
// monly known as social security). It is 6.2% of the employee's federal taxable
// gross pay.
const double SOCIAL_SECURITY = 0.062;
// All employees are required to contribute 6.0% of their pretax gross pay to
// the company 401K plan.
const double FOUR01K_PLAN = 0.06;
// Define a double constant named MEDICARE_RATE initialized to 0.0145.
// This is the percentage rate for calculating the medicare deduction. It is
// 1.45% of the employee's federal taxable gross pay.
// ???
const double MEDICARE_RATE = 0.0145;
// These constants are the monthly costs for each of the medical insurance
// plans. The amount an employee pays depends on his or her medical insurance
// status (see the group of constants following this group).
const double MEDICAL_INSURANCE_DEDUCT_EMPLOYEE_ONLY = 32.16; // Employee Only
const double MEDICAL_INSURANCE_DEDUCT_EMPLOYEE_PLUS_ONE = 64.97; // Employee + One
const double MEDICAL_INSURANCE_DEDUCT_FAMILY = 110.13; // Family
// These constants match the numbers for the employee's medical insurance status
// that will be in the input file.
const int MEDICAL_INSURANCE_STATUS_EMPLOYEE_ONLY = 0; // Employee Only
const int MEDICAL_INSURANCE_STATUS_EMPLOYEE_PLUS_ONE = 1; // Employee + One
const int MEDICAL_INSURANCE_STATUS_FAMILY = 2; // Family
void ErrorExit (string msg)
{
cout << msg << endl;
exit (-1);
}
//------------------------------------------------------------------------------
// FUNCTION: calc_gross_pay()
//
// Calculates and returns an employee's gross pay which is based on the number
// of hours worked (in parameter hrs_worked) and the employee's pay rate (in
// parameter pay_rate).
//------------------------------------------------------------------------------
double calc_gross_pay(double pay_rate, double hrs_worked)
{
double gross_pay;
if (hrs_worked <= 80){
gross_pay = hrs_worked * pay_rate;
} else {
gross_pay = (80 * pay_rate) + (hrs_worked - 80) * (1.5 * pay_rate);
}
return gross_pay;
}
//------------------------------------------------------------------------------
// FUNCTION: calc_med_ins_deduct()
//
// Determines and returns the employee's medical insurance deduction which is
// based on the employee's medical insurance status in parameter med_ins_status.
//------------------------------------------------------------------------------
double calc_med_ins_deduct (int med_ins_status){
double MedInsDeduct = 0;
if (med_ins_status == MEDICAL_INSURANCE_STATUS_EMPLOYEE_ONLY){
MedInsDeduct = MEDICAL_INSURANCE_DEDUCT_EMPLOYEE_ONLY;}
else if (med_ins_status == MEDICAL_INSURANCE_STATUS_EMPLOYEE_PLUS_ONE){
MedInsDeduct = MEDICAL_INSURANCE_DEDUCT_EMPLOYEE_PLUS_ONE;}
else {MedInsDeduct = MEDICAL_INSURANCE_DEDUCT_FAMILY;}
return MedInsDeduct;
}
//------------------------------------------------------------------------------
// FUNCTION: calc_tax_fed()
//
// Calculates and returns the employee's federal income tax which is based on
// his or her federal taxable gross pay (in parameter fed_tax_gross_pay) and the
// federal tax withholding percentage table in the lab project document.
//------------------------------------------------------------------------------
double calc_tax_fed(double fed_tax_gross_pay){
double tax_fed = 0;
if(fed_tax_gross_pay >= 384.62 && fed_tax_gross_pay < 1413.67){
tax_fed = fed_tax_gross_pay * 0.0797;
} else if (fed_tax_gross_pay >= 1413.67 && fed_tax_gross_pay < 2695.43){
tax_fed = 0.1275 * fed_tax_gross_pay;
} else if (fed_tax_gross_pay >= 2695.43){
tax_fed = 0.195 * fed_tax_gross_pay;
}
return tax_fed;}
//------------------------------------------------------------------------------
// FUNCTION: calc_tax_state()
//
// Calculates and returns the employee's state income tax which is based on his
// or her federal taxable gross pay (in parameter fed_tax_gross_pay) and the
// state tax withholding percentage table in the lab project document.
//------------------------------------------------------------------------------
double calc_tax_state(double fed_tax_gross_pay)
{
double tax_state = 0;
if (fed_tax_gross_pay < 961.54) {
tax_state = fed_tax_gross_pay * 0.0119;
} else if (fed_tax_gross_pay < 2145.66) {
tax_state = fed_tax_gross_pay * 0.0344;
} else {
tax_state = fed_tax_gross_pay * 0.0774;
}
return tax_state;
}
//------------------------------------------------------------------------------
// open_input_file(ifstream&, string) -> nothing
//
// See the comments in the function header of this function in main.cpp of Lab
// Project 6 for more information on how this function operates. Copy-and-paste
// the code for this function from your Lab 6 main.cpp source code file.
//------------------------------------------------------------------------------
void open_input_file(ifstream& fin , string);
void terminate (string msg){
cout << "Could not open Payroll.txt";
}
//------------------------------------------------------------------------------
// open_output_file(ofstream&, string) -> nothing
//
// See the comments in the function header of this function in main.cpp of Lab
// Project 6 for more information on how this function operates. Copy-and-paste
// the code for this function from your Lab 6 main.cpp source code file.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// terminate(string, int) -> nothing
//
// See the comments in the function header of this function in main.cpp of Lab
// Project 6 for more information on how this function operates. Copy-and-paste
// the code for this function from your Lab 6 main.cpp source code file.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// FUNCTION: main()
//
// This is the starting point of execution.
//------------------------------------------------------------------------------
int main()
{
// Define an ifstream object named 'fin' to read from the input file. Then
// call open_input_file() passing "payroll.txt" as the name of the file to
// be opened. If the file could not be opened for reading, then open_input
// _file() will not return.
ifstream fin;
if(!fin){
ErrorExit ("Payroll.txt could not be opened for writing");}
// Read the employee's last and first names from the input file.
string first_name, last_name;
fin >> last_name >> first_name;
// Read the employee's pay rate from the input file.
double pay_rate;
fin >> pay_rate;
// Read the employee's hours worked from the input file.
double hrs_worked;
fin >> hrs_worked;
// Read the employee's medical insurance status from the input file.
int med_ins_status;
fin >> med_ins_status;
// Close the input file because we're done reading from it.
fin.close();
// Call calc_gross_pay() to calculate the employee's gross pay. The input
// params are pay_rate and hrs_worked. The return value is assigned to vari-
// able gross_pay which is defined as a double.
double gross_pay = calc_gross_pay(pay_rate, hrs_worked);
// Calculate the employee's mandatory contribution to his/her 401k. This is
// gross_pay multiplied by the 401K rate.
double four01k_deduct = gross_pay * FOUR01K_PLAN;
// Call calc_med_ins_deduct() to determine the employee's medical insurance
// deduction which is based on the employee's medical insurance status
// stored in med_ins_status. The return value is assigned to variable
// med_ins_deduct which is defined as a double.
double med_ins_deduct = calc_med_ins_deduct(med_ins_status);
// Calculate the employee's federal taxable gross pay which is gross_pay
// minus deductions for medical insurance and 401K.
double fed_tax_gross_pay = gross_pay - med_ins_deduct - four01k_deduct;
// Call calc_tax_fed() to calculate the employee's federal income tax. The
// input parameter is fed_tax_gross_pay and the returned value is assigned
// to variable tax_fed which is defined as a double.
double tax_fed = calc_tax_fed(fed_tax_gross_pay);
// Calculate the amount withheld for OASDI and store in tax_oasdi.
double tax_oasdi = fed_tax_gross_pay * SOCIAL_SECURITY;
// Calculate the amount withheld for medicare and store in tax_medicare.
double tax_medicare = fed_tax_gross_pay * MEDICARE_RATE;
// Call calc_tax_state() to determine the employee's state tax deduction.
// The input parameter is fed_tax_gross_pay and the returned value is
// assigned to variable tax_state which is defined as a double.
double tax_state = calc_tax_state(fed_tax_gross_pay);
// Calculate the employee's total tax which is the sum of his/her federal
// tax, OASDI tax, medicare tax, and state tax. Assign to tax_total.
double tax_total = tax_fed + tax_oasdi + tax_medicare + tax_state;
// Calculate the employee's net pay which is federal taxable gross pay with
// taxes deducted. Assign to net_pay.
double net_pay = fed_tax_gross_pay - tax_total;
// Define an ofstream object named fout to write to the output file. Then
// call open_output_file() passing fout and "paycheck.txt" as the name of
// the file to be opened. If the file could not be opened for writing, then
// open_output_file() will not return.
ofstream fout;
fout.open("Paycheck.txt");
if(!fout){
ErrorExit("Payroll.txt couldn't be opened for writing.");
}
// Configure fout so real numbers will be printed in fixed notation with two
// digits after the decimal point.
fout << fixed << setprecision(2);
// Configure fout so the numbers will be printed right-justified in their
// respective fields.
fout << right;
// Output the employee paycheck. All numerical values are output in a field
// of width 8.
fout << "-----------------------------" << endl;
fout << "EMPLOYEE: " << last_name << ", " << first_name << endl << endl;
fout << "PAY RATE: $" << setw(8) << pay_rate << endl;
fout << "HOURS: " << setw(8) << hrs_worked << endl;
fout << "GROSS PAY: $" << setw(8) << gross_pay << endl;
fout << "MED INS DEDUCT: $" << setw(8) << med_ins_deduct << endl;
fout << "401K DEDUCT: $" << setw(8) << four01k_deduct << endl;
fout << "FED TAX GROSS PAY: $" << setw(8) << fed_tax_gross_pay << endl;
fout << "TAX - FEDERAL: $" << setw(8) << tax_fed << endl;
fout << "TAX - OASDI: $" << setw(8) << tax_oasdi << endl;
fout << "TAX - MEDICARE: $" << setw(8) << tax_medicare << endl;
fout << "TAX - STATE: $" << setw(8) << tax_state << endl;
fout << "TAX - TOTAL: $" << setw(8) << tax_total << endl;
fout << "NET PAY: $" << setw(8) << net_pay << endl;
fout << "-----------------------------" << endl;
// Close the output file.
fout.close();
// pause the system for a while
system("pause");
// Return 0 from main() to indicate to the OS that the program terminated
// normally.
return 0;
}
In: Computer Science
I wrote a code snippet to draw a bit of 'abstract art':
yertle.penDown(); yertle.forward(10); yertle.right(Math.PI/2); yertle.forward(10); yertle.right(Math.PI/2); yertle.forward(10); yertle.right(Math.PI/2); yertle.forward(10); yertle.right(Math.PI/2); yertle.left(Math.PI/2); yertle.forward(20); yertle.right(Math.PI/2); yertle.forward(20); yertle.right(Math.PI/2); yertle.forward(20); yertle.right(Math.PI/2); yertle.forward(20); yertle.right(Math.PI/2); yertle.left(Math.PI/2); yertle.forward(30); yertle.right(Math.PI/2); yertle.forward(30); yertle.right(Math.PI/2); yertle.forward(30); yertle.right(Math.PI/2); yertle.forward(30); yertle.right(Math.PI/2); yertle.left(Math.PI/2); yertle.forward(40); yertle.right(Math.PI/2); yertle.forward(40); yertle.right(Math.PI/2); yertle.forward(40); yertle.right(Math.PI/2); yertle.forward(40); yertle.right(Math.PI/2); yertle.left(Math.PI/2); yertle.penUp();
My instructor suggested I could get the same result from a
much shorter program, but I don't see how.
What should I write instead?
(Keep it concise, and don't include anything outside the scope of
the question)
In: Computer Science
Scanning Tools
Sniffers
In: Computer Science
This Homework would have two python files for a cheap online ticket seller. (You are free to imagine a new scenario and change any part of the question.)
The main purpose of the homework is to use basic concepts. You should try to use basic python elements like variables, if-else, loops, lists, dictionary, tuple, functions in this homework.
***
Price list to calculate the price for various destinations---
Price For Delta $ 200.00 (Economy), 300.00(Business), 400(First class)
United 220.00 (Economy), 330.00(Business), 410(First class)
Lufthansa 250.00(Economy), 340.00(Business), 410(First class)
American 260.00(Economy), 300.00(Business), 420(First class)
Price for Delta $ 250.00(Economy), 300.00(Business), 400(First class)
United $270.00 (Economy), 300.00(Business), 400(First class)
Lufthansa $ 290.00, (Economy), 300.00(Business), 400(First class)
American $ 280.00(Economy), 300.00(Business), 400(First class)
Price for Delta $ 350.00(Economy), 410.00(Business), 500.00(First class),
United 360.00(Economy), 4200.00(Business), 510(First class),
Lufthansa 370.00(Economy), 440.00(Business), 530(First class),
American 370.00(Economy), 430.00(Business), 510(First class)
Price For Delta $ 370.00(Economy), 410.00(Business), 520(First class),
United 380.00(Economy), 430.00(Business), 550(First class),
Lufthansa 390.00(Economy), 460.00(Business), 600.00(First class),
American 400.00(Economy), 470.00(Business), 590.00(First class)
For 6.00 AM and 11.00 AM flight, nothing to extra charge but 2.00 PM and & 7.00 flight has a $ 50.00 extra charge to book. However, the 11.00 PM flight has an extra charge of $ 70
***
Output: Do you Want to buy a ticket?
Enter Option 1 for buy ticket 2 for no:
How many people are you going to travel with? (Choose option Maximum 5):
Choose your destination from the below options menu:
What airline company do you want to travel with for destination:
Choose an option from the menu:
What class do you want to travel to? :
Choose an option from the menu:
What time would you like to travel to a destination? :
Choose an option from the menu:
The total price for your travel ticket is:
Enter Option 1 for buy ticket 2 for no:
In: Computer Science
use java recursion
find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters.
input is 2 strings, output is an int
input: ("Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "hello")
should output: 3
input: (" Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "Hello")
should output: 1
input: (" Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello Hello ", "Hello")
should output: 2
input: (" HELLO it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello Hello", "Hello")
should output: 1
input: (" HELLO it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello Hello", "")
should output: 0
In: Computer Science
Enlist 2 differences between matplotlib vs Seaborn
and for what type of visualization would you use one over the other?
In: Computer Science
#include <stdio.h>
typedef struct Coordinates
{
int x;
int y;
} Coordinate;
typedef union uCoordinates
{
int x;
int y;
} uCoordinate;
// TODO - Populate 4 different Coordinates with any numbers
between 1 and 99 for x & y values
// using coordinate1, coordinate2, coordinate3, & coordinate4
as Coordinate names
// TODO - Print to screen the x & y values of each
coordinate
// TODO - Replace the following with your name: Ethin Svoboda
int main()
{
// ADD YOUR CODE HERE
Coordinate coordinate1 = {.x 5, .y 7};
Coordinate coordinate2 = {.x 11, .y 20};
Coordinate coordinate3[100];
coordinate3[0].x = 10;
printf(format: "Coordinate 1 - x = %d, y = %d \n", coordinate1.x,
coordinate1.y);
printf(format: "Coordinate 2 - x = %d, y = %d \n", coordinate2.x,
coordinate2.y);
return 0;
}
The code I have is in my int main but I'm kind of confused on how to do it. What I'm supposed to do it says "TODO" before. Any help would be great thanks!
In: Computer Science
Java code for creating an Inventory Management System of any company
- designing the data structure(stack, queue, list, sort list, array, array list or linked list) (be flexible for future company growth
Java code for creating an initial list in a structure. Use Array (or ArrayList) or Linkedlist structure whichever you are confident to use. - Implement Stack, Queue, List type structure and proper operation for your application. Do not use any database. All data must use your data structures.
Minimum requirements of the system but not limited to only these:
Menu
1. Search Product
2. Search Product by other attribute
Menu
1. Show entire inventory
2. Show inventory by Manufacturer/Supplier
3. Show inventory by Type
4. Show inventory by Location
5. List products by price
6. List products by supplier
7. List products by availability
8. Show current discount items
Menu
1. Add record/product/part
2. Remove record
3. Change record
Menu for report
1. {make report - e.g. quantity report}
2. {make report - e.g. statistic report}
3. {Alert - Full or low quantity alerting}
In: Computer Science
Design a program that asks the user for a number and
the program computes the factorial of that number and displays the
result .
Implement with two different modules - one that uses a
for loop and one that uses a while loop
Grading Rubrick
Program Compiles Cleanly syntax errors25 pts-5 per
errorProgram runs without runtime errors ( validation)run-time
errors 25 pts-5 per errorProgram give correct answersLogic errors30
pts-5 per errorProgram is repeatableNot repeatable5 pts-5
ptsProgram is well modularizedBarely Modularized10 pts- 5
ptsDocumented WellDocumented Some5 pts- 3 ptsSomething Cool (but
relevant) beyond strict requirementsSomething extra5 pts + 3
ptsBest possible grade : 105
In: Computer Science
In: Computer Science
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20.
Input format: This is a sample input from a user.
|
The first line (= 4 in the example) indicates that there are four vertices in the graph. The next line (= 12 in the example) indicates the number of edges in the graph. The remaining 12 lines are the edge information with the “source vertex”, “destination vertex”, and “cost”. The last line (= 0 in the example) indicates the starting vertex of the travelling salesman problem. This is the graph with the input information provided.
Sample Run 0: Assume that the user typed the following lines
4
12
0 1 2
0 3 7
0 2 5
1 0 2
1 2 8
1 3 3
2 0 5
2 1 8
2 3 1
3 0 7
3 1 9
3 2 1
0
This is the correct output. Your program should present the path and total cost in separate lines.
Path:0->1->3->2->0
Cost:11
Sample Run 1: Assume that the user typed the following lines
5
6
0 2 7
3 1 20
0 4 3
1 0 8
2 4 100
3 0 19
3
This is the correct output.
Path:
Cost:-1
Note that if there is no path for the TSP, your program should present empty path and -1 cost.
Sample Run 2: Assume that the user typed the following lines
5
7
0 2 8
2 1 7
2 4 3
1 4 100
3 0 20
3 2 19
4 3 50
3
This is the correct output of your program.
Path:3->0->2->1->4->3
Cost:185
This is the directed graph of the input data:
[Hint]: To solve this problem, you can use all permutations of the vertices, except the starting vertex. For example, there are three vertices 1, 2, and 3, in the first sample run, except the starting vertex 0. This is all permutations with the three vertices
1, 2, 3
1, 3, 2
2, 1, 3,
2, 3, 1
3, 1, 2
3, 2, 1
In: Computer Science
Describe possible security issues that may affect Dynamic Host Configuration Protocol
In: Computer Science
Done in C language using mobaxterm if you can but use basic C
This program is broken up into three different functions of insert, delete, and main. This program implements a queue of individual characters in a circular list using only a single pointer to the circular list; separate pointers to the front and rear elements of the queue are not used.
Test Cases:
In: Computer Science