You are given an undirected graph A. The problem P asks, if there exists a cycle that contains more than half of the nodes in graph A? Is this problem in NP(nondeterministic polynomial time)? How is it related to the Hamiltonian cycle problem?
Construct your example in python.
Input: Graph A as either an edge list or adjacent list.
Output: Yes or No. If the output is yes, display the cycle as a
sequence of nodes.
In: Computer Science
please write the code in C not c++, and not to use Atoi or parseint to parse the string, Thank you.
#include <stdio.h>
#include <stdbool.h>
/*
* The isinteger() function examines the string given as its first
* argument, and returns true if and only if the string represents a
* well-formed integer. A well-formed integer consists only of an
* optional leading - followed by one or more decimal digits.
* Returns true if the given string represents an integer, false
* otherwise.
*/
bool isinteger(char *str);
/*
* The parseint() function parses a well-formed string representation of
* an integer (one which would return true from isinteger()) and returns
* the integer value represented by the string. For example, the string
* "1234" would return the value 1234. This function does not need to
* handle badly-formed strings in any particular fashion, its operation
* on badly-formed strings is undefined.
* Returns the integer value stored in the given string.
*/
int parseint(char *str);
/*
* The main function is where C programs begin.
* This function parses its arguments and returns the value they
* represent. Its arguments are either:
* - A single argument representing an integer
* - Three arguments, where the first and third are integers and the
* second is an operator to be performed on those integers
* Remember that the argument in argv[0] is the name of the program, so
* a program passed exactly one argument on the command line will
* receive _two_ arguments: its name in argv[0] and the provided
* argument in argv[1].
* Arguments:
* argc - The number of arguments received
* argv - The arguments received as an array of C strings
*
* Returns 0 if the arguments are well-formed and the calculation could
* be performed, non-zero otherwise.
*/
int main(int argc, char *argv[]) {
/* Your main program logic should go here, with helper logic in the
* functions isinteger() and parseint(), which you can place below
* the closing brace of main() */
return 0;
}
In: Computer Science
Complete the implementation of the Die class. Note that the Die class uses an array to represent the faces of a die.
You need to complete the no-argument constructor and the two methods compareTo and equals.
Code:
import java.util.Arrays;
import java.util.Objects;
import java.util.Random;
/*
* NOTE TO STUDENTS:
* The constructor that you need to complete can be found on line
47.
*
* The two methods you need to complete can be found at the end of
this file.
*/
public class Die implements Comparable<Die> {
/**
* A random number generator to simulate rolling the
die.
* DO NOT CHANGE THE DECLARATION OF rng. THE UNIT TESTS
RELY
* ON BEGIN ABLE TO ACCESS THE RANDOM NUMBER
GENERATOR.
*/
Random rng = new Random();
/**
* The array of face values.
*/
private int[] faces;
/**
* The current value of the die.
*/
private int value;
/**
* The number of faces on a die.
*/
public static int NUMBER_OF_FACES = 6;
/*
* You need to implement the no-argument constructor
below, and the
* methods compareTo and equals found at the end of the
class.
*/
public Die() {
}
private static boolean isInAscendingOrder(int[] a)
{
for (int i = 1; i < a.length;
i++) {
if (a[i] <
a[i - 1]) {
return false;
}
}
return true;
}
public Die(int[] faces) {
if (faces.length != 6) {
throw new
IllegalArgumentException();
}
if (!Die.isInAscendingOrder(faces))
{
throw new
IllegalArgumentException();
}
this.faces = Arrays.copyOf(faces,
NUMBER_OF_FACES);
this.value = this.faces[0];
}
public void setValueToFace(int face) {
if (face < 0 || face >=
NUMBER_OF_FACES) {
throw new
IllegalArgumentException();
}
this.value =
this.faces[face];
}
public int value() {
return this.value;
}
public int roll() {
int idx =
rng.nextInt(Die.NUMBER_OF_FACES);
this.value = this.faces[idx];
return this.value;
}
@Override
public int hashCode() {
return Objects.hash(this.value,
this.faces);
}
/*
* You need to implement the compareTo and equals
methods below.
*
*/
@Override
public int compareTo(Die other) {
}
@Override
public boolean equals(Object obj) {
// The method Arrays.equals may be
useful for helping
// to implement this method.
}
}
In: Computer Science
Java.
Part 1 of 4 - Amusement Park Programming Project
Requirements:
Class:
Ticket – models admission tickets.
Instance Fields:
Constructors and Methods:
In: Computer Science
How to do this in Python (using Lists):
Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird.
You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions:
1. Display all U.S. States in Alphabetical order along with Capital and Bird
2. Search for a specific state and display the appropriate Capital and Bird
3. Update a Bird for a specific state
4. Exit the program
In: Computer Science
C++
Write a definition for a structure type for records for books. The record contains ISBN number, price, and book cover (use H for Hard cover and P for paper cover). Part of the problem is appropriate choices of type and member names. Then declare two variables of the structure.
Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.
In: Computer Science
In 200 words discuss Managing IT in organizations (i.e., the role of information systems departments) has become much more complex over the past decade but some organizations may still use IT primarily for back-office support.
In: Computer Science
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables (one letter variables) and/or constants (one digit constants). IN PYTHON please
In: Computer Science
Python Program : simplist form and include comments
Shopping Data by Zip Code
Have you ever noticed that some stores ask you for your zip code before “ringing up” your transaction? Suppose you have been given three (3) text files (named kroger.txt, publix.txt, and ingles.txt) from popular grocery stores, containing zip codes of customers at each store. Additionally, you have been given a file named zipDirectory.txt which contains the zip code and city name (each on its own line). This file will be used as the "dictionary"/"lookup" for zip codes.
Text Files for this problem: Lab7Files.zip
You have been asked to write a Python program to complete the following tasks:
zipDirectory file
11111
City1
22222
public txt file
55555
66666
ingles txt file
77777
88888
99999
22222
44444
kroger.txt
11111
22222
33333
44444
55555
In: Computer Science
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would be the Student.h file //--------------------------------------------- #include <iostream> #include <cassert> using namespace std; // each student have a name, an ID (100000000~999999999), and three grades class Student { private: public: Student(); Student(); setName(); setId(); setGrade (); getName(); getId(); getGrade() ; printAll() ; }; //--------------------------------------------- // This would be the Student.cpp file //--------------------------------------------- //====================== YOUR CODE STARTS HERE ====================== Student::Student() //default constructor { } Student::Student(string aName, int anId, int Grade1, int Grade2, int Grade3) //other constructor { } Student::setName() { } Student::setId() { } Student::setGrade () { } Student::getName() { } Student::getId() { } // print all information of a student Student::printAll() { } Student::getGrade() { } //====================== YOUR CODE ENDS HERE ====================== //--------------------------------------------- // This would be the main.cpp file //--------------------------------------------- int main () { Student stu; //calls default constructor string inName; int inId; int i; cout << "********************************"<<endl; cout << "View stu after default constructor" << endl; stu.printAll(); cout << endl; //Use setters to reset the values cout << "Your name, please: "; getline(cin, inName, '\n'); // input a string stu.setName (inName); cout << "Your id, please: "; cin >> inId; //====================== YOUR CODE HERE ====================== // set stu's id and set three grades of students // // //====================== YOUR CODE ENDS HERE ====================== cout << endl; cout << "********************************"<<endl; cout << "View stu after setters" << endl; stu.printAll(); cout << endl; cout << "********************************"<<endl; cout << "Testing other constructor" << endl; Student tom ("Tom", 99, 55, 32, 68); //calls second constructor //notice using getters to print cout << "Hello, " << tom.getName() << endl; cout << "Your Student ID is " << tom.getId() << endl; cout << "Your Grades are: " << endl; for (int i=0; i < 3; i++) { cout << "Test " << i+1 << ": " << tom.getGrade(i) << " " << endl; } }
In: Computer Science
In: Computer Science
Python
Implement a program that starts by asking the user to enter a login id (i.e., a string). The program then checks whether the id entered by the user is in the list ['joe', 'sue', 'hani', 'sophie'] of valid users. Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.' before terminating.
Here is an example of a successful login:
>>> Login: joe
You are in!
Done.
And here is one that is not:
>>> Login: john
User unknown.
Done.
In: Computer Science
Rental Summary
Calculate the Amount Due.
amtDue = baseCharge + mileCharge
Print the Customer summary as follows:
Rental Summary Rental Code: The rental code Rental Period: The number of days the vehicle was rented Starting Odometer: The vehicle's odometer reading at the start of the rental period Ending Odometer: The vehicle's odometer reading at the end of the rental period Miles Driven: The number of miles driven during the rental period Amount Due: The amount of money billed displayed with a dollar sign and rounded to two digits. For example, $125.99 or $43.87
Final Check
Remove ALL print code from your script, except for the Rental
Summary.
The following data will be used in this final check:
Rental Code: D Rental Period: 5 Starting Odometer: 1234 Ending Odometer: 2222
Your final output should look like this:
Rental Code: D
Rental Period: 5
Starting Odometer: 1234
Ending Odometer: 2222
Miles Driven: 988
Amount Due: $324.40
Rental Summary Feedback Link
Before you submit your final code file for grading, it might be a good idea to get some feedback as a final check. This feedback is for your benefit and this will not submit your code for grading.
If so, click the Help Me! link below.
Help Me!
import sys
'''
Section 1: Collect customer input
'''
##Collect Customer Data - Part 1
##1) Request Rental code:
#Prompt --> "(B)udget, (D)aily, or (W)eekly rental?"
#rentalCode = ?
rentalCode = input("(B)udget, (D)aily, or (W)eekly
rental?\n")
print(rentalCode)
budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00
#2) Request time period the car was rented.
#Prompt --> "Number of Days Rented:"
#rentalPeriod = ?
# OR
#Prompt --> "Number of Weeks Rented:"
#rentalPeriod = ?
if rentalCode == 'B' or rentalCode == 'D':
rentalPeriod= int(input('Number of Days Rented:\n'))
else:
rentalPeriod =int(input('Number of Weeks Rented:\n'))
daysRented = rentalPeriod
#CUSTOMER DATA CHECK 1
#ADD CODE HERE TO PRINT:
#rentalCode
#rentalPeriod
#Calculation Part 1
##Set the base charge for the rental type as the variable
baseCharge.
#The base charge is the rental period * the appropriate rate:
#Collect Customer Data - Part 2
#4)Collect Mileage information:
#a) Prompt the user to input the starting odometer
reading and store it as the variable odoStart
#Prompt -->"Starting Odometer Reading:\n"
# odoStart = ?
#b) Prompt the user to input the ending odometer
reading and store it as the variable odoEnd
#Prompt -->"Ending Odometer Reading:"
# odoEnd = ?
#c) Calculate total miles
#Print odoStart, odoEnd and totalMiles
# Calculate Charges 2
## Calculate the mileage charge and store it
as
# the variable mileCharge:
#a) Code 'B' (budget) mileage charge: $0.25 for each mile driven
#b) Code 'D' (daily) mileage charge: no charge if
the average
# number of miles driven per day is 100 miles or less;
# i) Calculate the averageDayMiles
(totalMiles/rentalPeriod)
# ii) If averageDayMiles is above the 100 mile per
day
# limit:
# (1) calculate extraMiles (averageDayMiles -
100)
# (2) mileCharge is the charge for extraMiles,
# $0.25 for each mile
#c) Code 'W' (weekly) mileage charge: no charge if
the
# average number of miles driven per week is
# 900 miles or less;
# i) Calculate the averageWeekMiles (totalMiles/
rentalPeriod)
# ii) mileCharge is $100.00 per week if the average number of miles driven per week exceeds 900 miles
'''
Section 3: Display the results to the customer
'''
#1) Calculate the Amount Due as the variable amtDue
# This is the base charge + mile charge
#2. Display the results of the rental calculation:
print ("Rental Summary")
print("Rental Code: ", rentalCode)
print ("Rental Period: ", rentalPeriod)
print ("Starting Odometer: ", odoStart)
print ("Ending Odometer: ", odoEnd)
print ("Miles Driven: ", totalMiles)
print ("Amount Due: ", amtDue)
In: Computer Science
Using Java
The C expression m % n yields the remainders of m divided by n. Define the greatest common divisor (GCD) of two integers x and y by:
gcd(x, y) = y | if (y <= x && x % y == 0) |
gcd(x, y) = gcd(y, x) | if (x < y) |
gcd(x, y) = gcd(y, x % y) | otherwise |
You will submit a program listing (properly commented) and the output using the following data sets:
x | y |
---|---|
32 | 8 |
24 | 15 |
64 | 48 |
In: Computer Science
If you forget your password for a website and you click [Forgot my password], sometimes the company sends you a new password by email but sometimes it sends you your old password by email. Compare these two cases in terms of vulnerability of the website owner.
In: Computer Science