The greatest common divisor of two integers x and y is the largest positive integer that evenly divides both. For example, gcd(12,6)=6, gcd(21,14)=7, gcd(31,10)=1, gcd(55,25)=5
Recall that the gcd of two integers is gcd(a,0) = a gcd(a,b) = gcd(b, a%b) Create int gcd(int x, int y).
Assume that the two integers are zero or positive. Write the code as a pure function. Put it in a file gcd.c. Of course, you will need to test it.
The function Φ(n) counts how many integers 1 to n are relatively prime to n. Two integers x and y are relatively prime when gcd(x,y)= 1. So 5 and 12 are relatively prime, but 3 and 12 are not.
For example, Φ(1)=1, Φ(2)=1, Φ(5)=4, Φ(6)=3, Φ(8)=4, Φ(31)=30 Write a function int phi(int n) that computes this. Make this a pure function. Put it in its own file, phi.c. Write a driver that contains main() to test it. Put this in its own file phiTester.c.
C:\Source>gcc phiTester.c gcd.c phi.c
C:\Source>.\a.exe
Enter n: 259
Phi is 216
Turn in separate source files tau.c, tauSearch.c, phi.c and phiTester.c.
From poster: Please use comments, I want to see how it works!
In: Computer Science
Create a C++ program to simulate an art gallery:
Title of painting
Artists first name
Artists last name
Address street number
Address street name
Address city
Address state
Address zip
Artists website
Category
Number
Should print to a file all of the paintings by category and in alphabetical order based on the artist's last name.
This is an example txt file but the program will be tested with multiple files with different numbers of paintings:
Full Fathom Five
Jackson
Pollock
16
Woodbury
Springs
NY
11937
www.jacksonpollock.com
Abstract
978-3-16-148410-0
Impression, Sunrise
Claude
Monet
361
Sunflower
Giverny
France
27620
www.claudemonet.com
Impressionism
968-3-16-158420-0
A Sunday Afternoon on the Island of La Grande Jatte
Georges
Seurat
89
Longview
Paris
France
75006
www.gseurat.com
Pointillism
918-3-15-152420-0
In: Computer Science
User is asked to enter a series of numbers. That input will stop when user enters -9999. Find a maximum number from that series and a minimum number from that series. Output the location of Maximum number and minimum number.
Write a C++ program that asks the user to repeatedly input positive numbers until -1 is pressed. Your program should print the second largest number and the count of even and odd numbers.
Write a C++ program that asks the user to enter a positive number N, and print the following pattern. The pattern is shown for N = 5.
12345
23451
34521
45321
54321
Write a program that takes a set of N integers and count the frequency of ODD digits appeared in these N integers.
Sample Input:
How Many Numbers you want to input: 3
Number 0: 7809
Number 1: 1127
Number 2: 8381
Output:
Frequency of appeared ODD digits:
7
The digits 7809. 5127. 8381. So the count of
these ODD digits is 7.
In: Computer Science
How do I calculate the total of all invoices?
Here is my code:
# Part F Calculate the total of invoices
invoices=[]
invoices.append((83,'Electric Sander',7,57.98))
invoices.append((24,'Power Saw',18,99.99))
invoices.append((7,'Sledge Hammer',11,21.50))
invoices.append((77,'Hammer',76,11.99))
invoices.append((39,'Jig Saw',3,79.50))
print('\nThe total of all invoices is', invoice)
for invoice in invoices:
print(invoice)
In: Computer Science
How would you map invoices by description and quantity, then sort the invoices by quantity?
Here is my code:
#Part C: Map each invoice tuple containing part description and then quantity, sort by quantity
invoices=[]
invoices.append((83,'Electric Sander',7,57.98))
invoices.append((24,'Power Saw',18,99.99))
invoices.append((7,'Sledge Hammer',11,21.50))
invoices.append((77,'Hammer',76,11.99))
invoices.append((39,'Jig Saw',3,79.50))
list(map(lambda invoice:invoice[1,2]))
invoices.sort(key=lambda invoice:invoice[2])
print('\nSorted by Quantity')
for invoice in invoices:
print(invoice)
this is python
In: Computer Science
Describe why WSDL document is important for creating a web service client?
In: Computer Science
What is the key goal of messaging for enterprise computing?
In: Computer Science
PYTHON: Develop an algorithm for finding the most frequently occurring value in a list of numbers. Use a sequence of coins. Place paper clips below each coin that count how many other coins of the same value are in the sequence. Give the pseudocode for an algorithm that yields the correct answer, and describe how using the coins and paper clips helped you find the algorithm.
Please solve in python!
In: Computer Science
PYTHON: Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer n. This function will compute all prime numbers up to n. First insert all numbers from 1 to n into a set. Then erase all multiples of 2 (except 2); that is, 4, 6, 8, 10, 12, . . . . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to √ n. The remaining numbers are all primes.
Please solve in python!
In: Computer Science
Project part 3:
Part Three: Complete the addShip() Method
1. In the Driver.java file, see below for where you will add code
to finish the addShip() method.
// Add a New Ship public static void addShip() {
// complete this method
}
2. Next, review the required functionality of the “Add Ship”
menu option below.
Menu Option Validation Check(s) Functionality
Add Ship - Ensures ship does not already exist in our system -
Ensures all class variables are populated
Adds ship to system
3. Add Ship Method: Write the code for the addShip() method. When
your code is complete, test the output. Be sure that the completed
method does the following:
a. Adds a new Ship object b. Includes all class variables c.
Updates appropriate ArrayList
TIP: You can refer to the Ship.java class constructor to make sure
you have included all variables.
Here is the given ship code:
public class Ship {
// Class Variables
private String shipName;
private int roomBalcony;
private int roomOceanView;
private int roomSuite;
private int roomInterior;
private boolean inService;
// Constructor - default
Ship() {
}
// Constructor - full
Ship(String tName, int tBalcony, int tOceanView,
int tSuite, int tInterior, boolean tInService) {
shipName = tName;
roomBalcony = tBalcony;
roomOceanView = tOceanView;
roomSuite = tSuite;
roomInterior = tInterior;
inService = tInService;
}
// Accessors
public String getShipName() {
return shipName;
}
public int getRoomBalcony() {
return roomBalcony;
}
public int getRoomOceanView() {
return roomOceanView;
}
public int getRoomSuite() {
return roomSuite;
}
public int getRoomInterior() {
return roomInterior;
}
public boolean getInService() {
return inService;
}
// Mutators
public void setShipName(String tVar) {
shipName = tVar;
}
public void setRoomBalcony(int tVar) {
roomBalcony = tVar;
}
public void setRoomOceanView(int tVar) {
roomOceanView = tVar;
}
public void setRoomSuite(int tVar) {
roomSuite = tVar;
}
public void setRoomInterior(int tVar) {
roomInterior = tVar;
}
public void setInService(boolean tVar) {
inService = tVar;
}
// print method
public void printShipData() {
int spaceCount;
String spaces = "";
spaceCount = 20 - shipName.length();
for (int i = 1; i <= spaceCount; i++) {
spaces = spaces + " ";
}
System.out.println(shipName + spaces + roomBalcony + "\t"
+
roomOceanView + "\t" + roomSuite + "\t" +
roomInterior + "\t\t" + inService);
}
// method added to print ship's name vice memory address
@Override
public String toString() {
return shipName;
}
}
And here is the driver code that needs to be completed:
import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.Integer.parseInt;
public class Driver {
// class variables (add more as needed)
private static ArrayList<Ship> shipList = new
ArrayList();
private static ArrayList<Cruise> cruiseList = new
ArrayList();
private static ArrayList<Passenger> passengerList = new
ArrayList();
public static void main(String[] args) {
initializeShipList(); // initial ships
initializeCruiseList(); // initial cruises
initializePassengerList(); // initial passengers
// add loop and code here that accepts and validates user
input
// and takes the appropriate action. include appropriate
// user feedback and redisplay the menu as needed
}
// hardcoded ship data for testing
// Initialize ship list
public static void initializeShipList() {
add("Candy Cane", 20, 40, 10, 60, true);
add("Peppermint Stick", 10, 20, 5, 40, true);
add("Bon Bon", 12, 18, 2, 24, false);
add("Candy Corn", 12, 18, 2, 24, false);
}
// hardcoded cruise data for testing
// Initialize cruise list
public static void initializeCruiseList() {
Cruise newCruise = new Cruise("Southern Swirl", "Candy Cane",
"Miami", "Cuba", "Miami");
cruiseList.add(newCruise);
}
// hardcoded cruise data for testing
// Initialize passenger list
public static void initializePassengerList() {
Passenger newPassenger1 = new Passenger("Neo Anderson", "Southern
Swirl", "STE");
passengerList.add(newPassenger1);
Passenger newPassenger2 = new Passenger("Trinity", "Southern
Swirl", "STE");
passengerList.add(newPassenger2);
Passenger newPassenger3 = new Passenger("Morpheus", "Southern
Swirl", "BAL");
passengerList.add(newPassenger3);
}
// custom method to add ships to the shipList ArrayList
public static void add(String tName, int tBalcony, int
tOceanView,
int tSuite, int tInterior, boolean tInService) {
Ship newShip = new Ship(tName, tBalcony, tOceanView, tSuite,
tInterior, tInService);
shipList.add(newShip);
}
public static void printShipList(String listType) {
// printShipList() method prints list of ships from the
// shipList ArrayList. There are three different outputs
// based on the listType String parameter:
// name - prints a list of ship names only
// active - prints a list of ship names that are "in service"
// full - prints tabbed data on all ships
if (shipList.size() < 1) {
System.out.println("\nThere are no ships to print.");
return;
}
if (listType == "name") {
System.out.println("\n\nSHIP LIST - Name");
for (int i = 0; i < shipList.size(); i++) {
System.out.println(shipList.get(i));
}
} else if (listType == "active") {
System.out.println("\n\nSHIP LIST - Active");
System.out.println("-----------------------------------------------");
System.out.println(" Number of Rooms In");
System.out.print("SHIP NAME Bal OV Ste Int Service");
System.out.println("\n-----------------------------------------------");
for (Ship eachShip: shipList) {
if(eachShip.getType()==true)
eachShip.printShipData();
}
} else if (listType == "full") {
System.out.println("\n\nSHIP LIST - Full");
System.out.println("-----------------------------------------------");
System.out.println(" Number of Rooms In");
System.out.print("SHIP NAME Bal OV Ste Int Service");
System.out.println("\n-----------------------------------------------");
for (Ship eachShip: shipList)
eachShip.printShipData();
} else
System.out.println("\n\nError: List type not defined.");
}
public static void printCruiseList(String listType) {
if (cruiseList.size() < 1) {
System.out.println("\nThere are no cruises to print.");
return;
}
if (listType == "list") {
System.out.println("\n\nCRUISE LIST");
for (int i=0; i < cruiseList.size(); i++) {
System.out.println(cruiseList.get(i));
}
} else if (listType == "details") {
System.out.println("\n\nCRUISE LIST - Details");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("
|----------------------PORTS-----------------------|");
System.out.print("CRUISE NAME SHIP NAME DEPARTURE DESTINATION
RETURN");
System.out.println("\n-----------------------------------------------------------------------------------------");
for (Cruise eachCruise: cruiseList)
eachCruise.printCruiseDetails();
} else
System.out.println("\n\nError: List type not defined.");
}
public static void printPassengerList() {
if (passengerList.size() < 1) {
System.out.println("\nThere are no passengers to print.");
return;
}
System.out.println("\n\nPASSENGER LIST");
System.out.println("-----------------------------------------------------");
System.out.print("PASSENGER NAME CRUISE ROOM TYPE");
System.out.println("\n-----------------------------------------------------");
for (Passenger eachPassenger: passengerList)
eachPassenger.printPassenger();
}
// display text-based menu
public static void displayMenu() {
System.out.println("\n\n");
System.out.println("\t\t\tLuxury Ocean Cruise Outings");
System.out.println("\t\t\t\t\tSystem Menu\n");
System.out.println("[1] Add Ship [A] Print Ship Names");
System.out.println("[2] Edit Ship [B] Print Ship In Service
List");
System.out.println("[3] Add Cruise [C] Print Ship Full
List");
System.out.println("[4] Edit Cruise [D] Print Cruise List");
System.out.println("[5] Add Passenger [E] Print Cruise
Details");
System.out.println("[6] Edit Passenger [F] Print Passenger
List");
System.out.println("[x] Exit System");
System.out.println("\nEnter a menu selection: ");
}
// Add a New Ship
public static void addShip() {
// complete this method
}
// Edit an existing ship
public static void editShip() {
In: Computer Science
Project Part 4:
Part Four: Complete the addCruise() Method
1. In the Driver.java file, see below for where you will add code
to finish the addCruise() method.
// Adda New Cruise public static void addCruise() {
// complete this method
}
2. Next, review the required functionality of the “Add Cruise” menu
option below.
Menu Option Validation Check(s) Functionality
Add Cruise - Ensures cruise does not already exist in our system -
Ensures all class variables are populated
Adds cruise to system
3. Add Cruise Method: Write the code for the addCruise() method.
When your code is complete, test the output. Be sure that the
completed method does the following:
a. Prompts the user for input b. Requires all class variables when
creating a cruise c. Validates the ship name and ensures it is in
service d. Ensures ship name is not already assigned a cruise e.
Adds the new cruise to the cruiseList ArrayList if validation
checks
Given cruise code:
public class Cruise {
// Class Variables
private String cruiseName;
private String cruiseShipName;
private String departurePort;
private String destination;
private String returnPort;
// Constructor - default
Cruise() {
}
// Constructor - full
Cruise(String tCruiseName, String tShipName, String tDeparture,
String tDestination, String tReturn) {
cruiseName = tCruiseName;
cruiseShipName = tShipName;
departurePort = tDeparture;
destination = tDestination;
returnPort = tReturn;
}
// Accessors
public String getCruiseName() {
return cruiseName;
}
public String getCruiseShipName() {
return cruiseShipName;
}
public String getDeparturePort() {
return departurePort;
}
public String getDestination() {
return destination;
}
public String getReturnPort() {
return returnPort;
}
// Mutators
public void setCruiseName(String tVar) {
cruiseName = tVar;
}
public void setCruiseShipName(String tVar) {
cruiseShipName = tVar;
}
public void setDeparturePort(String tVar) {
departurePort = tVar;
}
public void setDestination(String tVar) {
destination = tVar;
}
public void setReturnPort(String tVar) {
returnPort = tVar;
}
// print cruise details
public void printCruiseDetails() {
// complete this method
}
Here is the driver code that needs completion:
import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.Integer.parseInt;
public class Driver {
// class variables (add more as needed)
private static ArrayList<Ship> shipList = new
ArrayList();
private static ArrayList<Cruise> cruiseList = new
ArrayList();
private static ArrayList<Passenger> passengerList = new
ArrayList();
public static void main(String[] args) {
initializeShipList(); // initial ships
initializeCruiseList(); // initial cruises
initializePassengerList(); // initial passengers
// add loop and code here that accepts and validates user
input
// and takes the appropriate action. include appropriate
// user feedback and redisplay the menu as needed
}
// hardcoded ship data for testing
// Initialize ship list
public static void initializeShipList() {
add("Candy Cane", 20, 40, 10, 60, true);
add("Peppermint Stick", 10, 20, 5, 40, true);
add("Bon Bon", 12, 18, 2, 24, false);
add("Candy Corn", 12, 18, 2, 24, false);
}
// hardcoded cruise data for testing
// Initialize cruise list
public static void initializeCruiseList() {
Cruise newCruise = new Cruise("Southern Swirl", "Candy Cane",
"Miami", "Cuba", "Miami");
cruiseList.add(newCruise);
}
// hardcoded cruise data for testing
// Initialize passenger list
public static void initializePassengerList() {
Passenger newPassenger1 = new Passenger("Neo Anderson", "Southern
Swirl", "STE");
passengerList.add(newPassenger1);
Passenger newPassenger2 = new Passenger("Trinity", "Southern
Swirl", "STE");
passengerList.add(newPassenger2);
Passenger newPassenger3 = new Passenger("Morpheus", "Southern
Swirl", "BAL");
passengerList.add(newPassenger3);
}
// custom method to add ships to the shipList ArrayList
public static void add(String tName, int tBalcony, int
tOceanView,
int tSuite, int tInterior, boolean tInService) {
Ship newShip = new Ship(tName, tBalcony, tOceanView, tSuite,
tInterior, tInService);
shipList.add(newShip);
}
public static void printShipList(String listType) {
// printShipList() method prints list of ships from the
// shipList ArrayList. There are three different outputs
// based on the listType String parameter:
// name - prints a list of ship names only
// active - prints a list of ship names that are "in service"
// full - prints tabbed data on all ships
if (shipList.size() < 1) {
System.out.println("\nThere are no ships to print.");
return;
}
if (listType == "name") {
System.out.println("\n\nSHIP LIST - Name");
for (int i = 0; i < shipList.size(); i++) {
System.out.println(shipList.get(i));
}
} else if (listType == "active") {
System.out.println("\n\nSHIP LIST - Active");
System.out.println("-----------------------------------------------");
System.out.println(" Number of Rooms In");
System.out.print("SHIP NAME Bal OV Ste Int Service");
System.out.println("\n-----------------------------------------------");
for (Ship eachShip: shipList) {
if(eachShip.getType()==true)
eachShip.printShipData();
}
} else if (listType == "full") {
System.out.println("\n\nSHIP LIST - Full");
System.out.println("-----------------------------------------------");
System.out.println(" Number of Rooms In");
System.out.print("SHIP NAME Bal OV Ste Int Service");
System.out.println("\n-----------------------------------------------");
for (Ship eachShip: shipList)
eachShip.printShipData();
} else
System.out.println("\n\nError: List type not defined.");
}
public static void printCruiseList(String listType) {
if (cruiseList.size() < 1) {
System.out.println("\nThere are no cruises to print.");
return;
}
if (listType == "list") {
System.out.println("\n\nCRUISE LIST");
for (int i=0; i < cruiseList.size(); i++) {
System.out.println(cruiseList.get(i));
}
} else if (listType == "details") {
System.out.println("\n\nCRUISE LIST - Details");
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("
|----------------------PORTS-----------------------|");
System.out.print("CRUISE NAME SHIP NAME DEPARTURE DESTINATION
RETURN");
System.out.println("\n-----------------------------------------------------------------------------------------");
for (Cruise eachCruise: cruiseList)
eachCruise.printCruiseDetails();
} else
System.out.println("\n\nError: List type not defined.");
}
public static void printPassengerList() {
if (passengerList.size() < 1) {
System.out.println("\nThere are no passengers to print.");
return;
}
System.out.println("\n\nPASSENGER LIST");
System.out.println("-----------------------------------------------------");
System.out.print("PASSENGER NAME CRUISE ROOM TYPE");
System.out.println("\n-----------------------------------------------------");
for (Passenger eachPassenger: passengerList)
eachPassenger.printPassenger();
}
// display text-based menu
public static void displayMenu() {
System.out.println("\n\n");
System.out.println("\t\t\tLuxury Ocean Cruise Outings");
System.out.println("\t\t\t\t\tSystem Menu\n");
System.out.println("[1] Add Ship [A] Print Ship Names");
System.out.println("[2] Edit Ship [B] Print Ship In Service
List");
System.out.println("[3] Add Cruise [C] Print Ship Full
List");
System.out.println("[4] Edit Cruise [D] Print Cruise List");
System.out.println("[5] Add Passenger [E] Print Cruise
Details");
System.out.println("[6] Edit Passenger [F] Print Passenger
List");
System.out.println("[x] Exit System");
System.out.println("\nEnter a menu selection: ");
}
// Add a New Ship
public static void addShip() {
// complete this method
}
// Edit an existing ship
public static void editShip() {
// This method does not need to be completed
System.out.println("The \"Edit Ship\" feature is not yet
implemented.");
}
// Add a New Cruise
public static void addCruise() {
// complete this method
}
// Edit an existing cruise
public static void editCruise() {
// method added to print ship's name vice memory
address
@Override
public String toString() {
return cruiseName;
}
}
In: Computer Science
(C++ with main to test)
Task 1
Imagine that you are an engineer on a distant planet. You were
tasked with mining the
resources of the planet and have done so through largely primitive
means. However you
have managed to set up an automated train system to gather and
collect the resources
from your distant operations. Your train system collects boxes full
of resources. A box
might contain ores or wood or even liquid fuel. These boxes are
placed into the train
using drones who stack them on each other to save space. You now
need to implement
a management system using the newly researched data structures that
will prove useful.
In particular, the rapid pace of your development means that
resources are accumulated
quickly and fixed sized structures would be unwise. Therefore you
will be implementing
the stack through the use of a linked list.
2.2.1
resrcStack
The class is defined according to the simple UML diagram
below:
resrcStack<T>
-top: stackNode<T>*
2----------------------------
+resrcStack()
+~resrcStack()
+push(t: stackNode<T>*):void
+pop():void
+peek():stackNode <T>*
+print():void
+tallyWeights():int
+calculateStorageRequirements():string
The class variables are defined below:
• top: The current top of the stack. It will start as null but
should refer to the top of
the stack.
The class methods are defined below:
• resrcStack: The class constructor. It will start by initialising
the variables to null.
• ∼resrcStack: The class destructor. It will deallocate all of the
memory assigned by
the class.
• push: This will receive a stackNode to add onto the current
stack. The node is
added from the top.
• pop: This will remove the top resrcNode from the stack. If it is
empty, print out
”EMPTY” with a newline at the end and no quotation marks. When
removing the
node, it should be deleted.
• peek: This will return the top node of the stack but without
removing it from the
stack.
• print: This will print the entire contents of the stack. For each
resrc node in the
stack, print the following information out sequentially, line by
line. The format of
this is as follows:
Resource:
Quantity:
Resource:
Quantity:
Unrefined Ores
12
Refined Alloys
1000
Remember that when printing, the first nodes added will be printed
last. The first
node to be printed should be the last node pushed into the
stack.
• tallyWeights: This function will tally up the weights for all
nodes in the stack and
return their total weight. If empty, return -1.
• calculateStorageRequirements: This function must determine what
the storage re-
quirement for the materials contained in the stack. The resulting
type of storage
unit is returned. The storage requirements are determined as
follows:
31. wooden crate: If the weights of the items together are less
than 100, a wooden
crate should prove sufficient.
2. steel crate: A steel crate will be required if the weights of
the items total 200
or more and the number of nodes, is greater than 5 but less than
10.
3. silo: A silo is required when the number of node is greater than
10 under all
circumstances.
This should return wooden crate, steel crate or silo. If none of
the conditions are
met, return ”LOGISTICS ERROR” without the quotation marks. The
wooden
crate takes precedence over the steel crate which takes precedence
over the silo for
what to return.
2.2.2
stackNode
The class is defined according to the simple UML diagram
below:
stackNode<T>
-resrc:T
+next:stackNode *
-weight: int
------------------------
+stackNode(i:T,w:int)
+~stackNode()
+getResrc():T
+getWeight():int
The class variables are defined below:
• resrc: This is the basic resource unit. It will describe the
resource contained within
the box. It might be a code that describes the contents or just a
description and so
must be a template type to accommodate for a variety of
manifests.
• next: A pointer to the next node of the stack.
• weight: A variable which describes the total weight of the
resources contained within
the class.
The class methods are defined below:
• stackNode: A class constructor. It receives the template type and
the weight for
that item.
• ∼stackNode: The class destructor. It should print out ”Resource
Unit Destroyed”
with no quotation marks and a new line at the end.
• getResrc: This returns the template variable stored within the
class.
You will be allowed to use the following libraries: string,
iostream.
In: Computer Science
what is difference and similarity between docker , jenkins and swagger.I am not able to understand the difference please explain in easy words with diagrams or figures if possible.
Also give proper and easy example of docker file .How to use docker file in production environment. i am not understanding please explain with proper screenshots.
In: Computer Science
In: Computer Science