Linux Create two subprocesses using the system call fork(), and then use the system call signal() to let the parent process capture the interrupt signal on the keyboard (i.e., press the DEL key); The subprocess terminates after the subprocess captures the signal and outputs the following information separately: “Child Process l is Killed by Parent!” “Child Process 2 is Killed by Parent!” After the two child processes terminate, the parent process output the following information and terminate itself: “Parent Process is Killed!” Program with screen shot and explanation. Thank you
In: Computer Science
Apex Computing is preparing for a Secret Santa gift exchange. Certain information will be gathered from each employee. Although it would be more realistic to write a program that asks a user for input, this program will just be a practice for using structures and functions so we will create the information by assigning values to the variables.
Write a program that uses a structure named EmpInfo to store the following about each employee:
Name
Age
Favorite Food
Favorite Color
The program should create three EmpInfo variables, store values in their members, and pass each one, in turn, to a function that displays the information in a clear and easy-to-read format. (Remember that you will choose the information for the variables.)
Here is an example of the output:
Name………………………………Mary Smith
Age ……………………………….. 25
Favorite food ………………… Pizza
Favorite color ……………….. Green
In: Computer Science
NEED TO BE IN PYTHON!!!
Make sure to put the main section of your code in the following if
block:
# Type code for classes here
if __name__ == "__main__":
# Type main section of code here
(1) Build the Account class with the following specifications:
Attributes
Create a constructor that has 3 parameters (in addition to self) that will be passed in from the user. (no default values)
Define a __str__() method to print an Account like the following
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $100.00
Define a deposit() method that has 1 parameter (in addition to self) that will be passed in from the user. (no default values) The method deposits the specified amount in the account.
Define a withdraw() method that has 2 parameters (in addition to self) that will be passed in from the user. (no default values) The method withdraws the specified amount (1st parameter) and fee (2nd parameter) from the account.
(2) In the main section of your code, create 3 accounts.
(3) Print the 3 accounts using print(acct1)…
(4) Deposit 25.85, 75.50 and 50 into accounts 1, 2 and 3.
(5) Print the 3 accounts.
(6) Withdraw 25.85 (2.50 fee), 75.50 (1.50 fee), 50.00 (2.00 fee).
(7) Print the 3 accounts.
Output should look like the following:
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $100.00
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $100.00
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $100.00
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $125.85
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $175.50
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $150.00
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $97.50
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $98.50
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $98.00
In: Computer Science
You will use the definition of the linked-queue from lab6, and re-write it as a template for a linked-queue (I hope you finished the function definitions)
In the driver file, create and use queues of different types to show it works.
In the documentation, indicate if there are any types it won’t work for, and why not.
driver.cpp
#include <iostream>
using namespace std;
#include "LQueue.h"
void print(Queue q)
{
q.display(cout);
}
int main()
{
Queue q1;
cout << "Queue created. Empty? " << boolalpha <<
q1.empty() << endl;
cout << "How many elements to add to the queue? ";
int numItems;
cin >> numItems;
for (int i = 1; i <= numItems; i++)
q1.enqueue(100 * i);
cout << "Contents of queue q1 (via print):\n";
print(q1); cout << endl;
Queue q2;
q2 = q1;
cout << "Contents of queue q2 after q2 = q1 (via
print):\n";
print(q2); cout << endl;
cout << "Queue q2 empty? " << q2.empty() <<
endl;
cout << "Front value in q2: " << q2.front() <<
endl;
while (!q2.empty())
{
cout << "Remove front -- Queue contents: ";
q2.dequeue();
q2.display(cout);
}
cout << "Queue q2 empty? " << q2.empty() <<
endl;
cout << "Front value in q2?" << endl <<
q2.front() << endl;
cout << "Trying to remove front of q2: " << endl;
q2.dequeue();
return 0;
}
LQueue.h
#include <iostream>
#ifndef LQUEUE
#define LQUEUE
typedef int QueueElement;
class Queue
{
public:
/***** Function Members *****/
/***** Constructors *****/
Queue();
/*-----------------------------------------------------------------------
Construct a Queue object.
Precondition: None.
Postcondition: An empty Queue
object has been constructed.
(myFront and myBack are initialized to null pointers).
-----------------------------------------------------------------------*/
Queue(const Queue & original);
/*-----------------------------------------------------------------------
Copy Constructor
Precondition: original is the queue
to be copied and is received
as a
const reference parameter.
Postcondition: A
copy of original has been constructed.
-----------------------------------------------------------------------*/
/***** Destructor *****/
~Queue();
/*-----------------------------------------------------------------------
Class destructor
Precondition: None.
Postcondition: The linked list
in the queue has been deallocated.
-----------------------------------------------------------------------*/
/***** Assignment *****/
const Queue & operator= (const Queue &
rightHandSide);
/*-----------------------------------------------------------------------
Assignment Operator
Precondition: rightHandSide is the
queue to be assigned and is
received as a const reference parameter.
Postcondition: The
current queue becomes a copy of rightHandSide
and a reference to it is returned.
-----------------------------------------------------------------------*/
bool empty() const;
/*-----------------------------------------------------------------------
Check if queue is empty.
Precondition: None.
Postcondition: Returns true if
queue is empty and false otherwise.
-----------------------------------------------------------------------*/
void enqueue(const QueueElement & value);
/*-----------------------------------------------------------------------
Add a value to a queue.
Precondition: value is to be
added to this queue.
Postcondition: value is added at
back of
queue.
-----------------------------------------------------------------------*/
void display(ostream & out) const;
/*-----------------------------------------------------------------------
Display values stored in the queue.
Precondition: ostream out is
open.
Postcondition: Queue's contents,
from front to back, have been
output to out.
-----------------------------------------------------------------------*/
QueueElement front() const;
/*-----------------------------------------------------------------------
Retrieve/Peep value at front of queue (if
any).
Precondition: Queue is
nonempty.
Postcondition: Value at front of
queue is returned, unless the queue
is empty; in that case, an error
message is displayed and a
"garbage value" is
returned.
-----------------------------------------------------------------------*/
void dequeue();
/*-----------------------------------------------------------------------
Remove value at front of queue (if any).
Precondition: Queue is
nonempty.
Postcondition: Value at front of
queue has been removed, unless
queue is empty; in that case, an
error message is displayed
and execution allowed to
proceed.
-----------------------------------------------------------------------*/
private:
void delete_q(); // utility/helper function to delete queues
for
// destructor and assignment
operator
/*** Node class for the
queue***/
class Node
{
public:
QueueElement data;
Node * next;
//--- Node constructor
Node(QueueElement value, Node * link = 0)
/*-------------------------------------------------------------------
Precondition: value and link are received
Postcondition: A Node has been constructed with value in its
data part and its next part
set to link (default 0).
------------------------------------------------------------------*/
{
data = value; next = link;
}
}; //for Node class
typedef Node * NodePointer;
/***** Data Members *****/
NodePointer myFront, // pointer to
front of queue
myBack;
// pointer to back of queue
}; // end of class declaration
#endif
LQueue-Incomplete.cpp
#include <new>
using namespace std;
#include "LQueue.h"
//--- Definition of Queue constructor
Queue::Queue()
: myFront(0), myBack(0)
{}
//--- Definition of Queue copy constructor
Queue::Queue(const Queue & original)
{
myFront = myBack = 0;
if (!original.empty())
{
// Copy first node
myFront = myBack = new Node(original.front());
// Set pointer to run through original's linked
list
NodePointer origPtr = original.myFront->next;
while (origPtr != 0)
{
myBack->next = new
Node(origPtr->data);
myBack = myBack->next;
origPtr = origPtr->next;
} //while
} //if
}
void Queue::delete_q(void) {
// Set pointer to run through the queue
NodePointer prev = myFront, // node to be released/deleted
ptr; // points to the front node
while (prev != 0)
{
ptr = prev->next;
delete prev;
prev = ptr;
}
}
//--- Definition of Queue destructor
// delete queue from the front
Queue::~Queue()
{
delete_q();
}
//--- Definition of assignment operator
const Queue & Queue::operator=(const Queue &
rightHandSide)
{
if (this !=
&rightHandSide)
// check that not q = q
{
this->delete_q();
// destroy current linked list
if
(rightHandSide.empty()) //
empty queue
myFront = myBack = 0;
else
{
// copy rightHandSide's list
//
Copy first node
myFront = myBack = new
Node(rightHandSide.front());
// Set pointer to run through rightHandSide's
linked list
NodePointer rhsPtr =
rightHandSide.myFront->next;
while (rhsPtr != 0)
{
myBack->next = new
Node(rhsPtr->data);
myBack = myBack->next;
rhsPtr = rhsPtr->next;
}
}
}
return *this;
}
//--- Definition of empty()
bool Queue::empty() const
{
return (myFront == 0);
}
//--- Definition of enqueue()
void Queue::enqueue(const QueueElement & value)
{
NodePointer newptr = new Node(value);
if (empty())
myFront = myBack = newptr;
else
{
myBack->next = newptr;
myBack = newptr;
}
}
//--- Definition of display()
void Queue::display(ostream & out) const
{
NodePointer ptr;
for (ptr = myFront; ptr != 0; ptr = ptr->next)
out << ptr->data << " ";
out << endl;
}
//--- Definition of front()
// Peep the first element of the queue
QueueElement Queue::front() const
{
if (!empty())
return (myFront->data);
else
{
cerr << "*** Queue is empty "
" -- returning garbage ***\n";
QueueElement * temp = new(QueueElement);
QueueElement garbage = *temp;
// "Garbage" value
delete temp;
return garbage;
}
}
//--- Definition of dequeue()
// simply decrement the queue
void Queue::dequeue()
{
if (!empty())
{
NodePointer ptr = myFront;
myFront = myFront->next;
delete ptr;
if (myFront == 0) // queue is
now empty
myBack = 0;
}
else
cerr << "*** Queue is empty -- can't remove a
value ***\n";
}
In: Computer Science
Hello,
How can we create two buttons in a single page side by side through html?And how can we enter different data for different buttons, so that if i click 1st button it should show specific data and if i click second it should show other data?
In: Computer Science
write the program named Lab06.java that contains the following four static methods:
• public static double max(double[] data) that returns the maximum value in the array data
• public static double min(double[] data) that returns the minimum value in the array data
• public static double sum(double[] data) that sums all items in the array and return the result
• public static double ave(double[] data) that call the sum() method and then return the average.
Once you have completed the methods above, write a simple main program that does the following:
1. Asks the user how many items will be entered
2. Creates an array of double of the correct size
3. Prompts the user and reads in the values
4. Calculates and prints out the max, min, sum, and average using the methods above.
In: Computer Science
Im working on modifying my current code to function with these changes below
Create a Java program that meets the following criteria
My current code is show as below, i was wondering how i would go about doing that im a little lost.
import java.io.File;
import java.util.Scanner;
public class Lab5 {
public static void main(String[] args) {
String inFileName;
if (args.length > 1) {
inFileName = args[0];
} else {
Scanner console = new Scanner(System.in);
System.out.println("Enter a Filename: ");
inFileName = console.nextLine();
}
double[] myData = readArray(inFileName);
double[] results = processArray(myData);
// TODO: Display Results...
}
static double[] readArray(String filename) {
File inFile = new File(filename);
if (inFile.canRead()) {
try {
Scanner fileScanner = new Scanner(inFile);
int count = fileScanner.nextInt();
double[] data = new double[count];
for (int i = 0; i < count; i++) {
data[i] = fileScanner.nextDouble();
}
return data;
} catch (Exception e) {
return new double[0];
}
} else {
System.out.println("Can't read file.");
return new double[0];
}
}
static double[] processArray(double[] dataArray) {
// TODO: Implement Functionality from Requirements.
for (double data : dataArray) {
System.out.println(data);
}
return new double[0];
}
}In: Computer Science
Start with a program that allows the user to input a number of integers, and then stores them in an int array.
Write a function called maxint() that goes through the array, element by element, looking for the largest one.The function should take as arguments the address of the array and the number of elements in it, and return the index number of the largest element. The program should call this function and then display the largest element and its index number.
In: Computer Science
Update the following C code and write the function :
void sln_stutter(sln_list* li);
that modifies the list li so that it each element is duplicated. For example the list with elements [1,2,3] would after this function call become the list [1,1,2,2,3,3].
#include <stdlib.h>
#include <stdio.h>
struct sln_node {
struct sln_node* next;
int key;
};
struct sln_list {
struct sln_node* head;
};
typedef struct sln_node sln_node;
typedef struct sln_list sln_list;
static sln_node* freelist = NULL;
/* Internal bookkeeping functions for the free list of nodes. */
sln_node* sln_allocate_node() {
sln_node* n;
if(freelist == NULL) {
freelist = malloc(sizeof(sln_node));
freelist->next = NULL;
}
n = freelist;
freelist = n->next;
n->next = NULL;
return n;
}
void sln_release_node(sln_node* n) {
n->next = freelist;
freelist = n;
}
void sln_release_freelist() {
sln_node* n;
while(freelist != NULL) {
n = freelist;
freelist = freelist->next;
free(n);
}
}
/* Create a new singly-linked list. */
sln_list* sln_create() {
sln_list* list = malloc(sizeof(sln_list));
list->head = NULL;
return list;
}
/* Release the list and all its nodes. */
void sln_release(sln_list* list) {
sln_node* n = list->head;
sln_node* m;
while(n != NULL) {
m = n->next;
sln_release_node(n);
n = m;
}
free(list);
}
/* Insert a new element to the list. */
void sln_insert(sln_list* list, int key) {
sln_node* n = sln_allocate_node();
n->key = key;
n->next = list->head;
list->head = n;
}
/* Check if the list contains the given element. Returns 1 or 0. */
int sln_contains(sln_list* list, int key) {
sln_node* n = list->head;
while(n != NULL && n->key != key) {
n = n->next;
}
return (n == NULL)? 0: 1;
}
/* Remove the first occurrence of the given element from the list.
Returns 1 if an element was removed, 0 otherwise. */
int sln_remove(sln_list* list, int key) {
sln_node* n;
sln_node* m;
n = list->head;
if(n == NULL) { return 0; }
if(n->key == key) {
list->head = n->next;
sln_release_node(n);
return 1;
}
while(n->next != NULL && n->next->key != key) {
n = n->next;
}
if(n->next != NULL) {
m = n->next;
n->next = m->next;
sln_release_node(m);
return 1;
}
return 0;
}
In: Computer Science
I have a list of things for review in C programming, could you please give me an example and a brief explanation for each question... Thank you very much
In: Computer Science
In: Computer Science
Suppose we want to make a 10 item queue starting from location
x4000. In class, we discussed using a HEAD and a TAIL pointer to
keep track of the beginning and end of the queue. In fact, we
suggested that the HEAD pointer could point to the first element
that we would remove from the queue and the TAIL pointer could
point the last element that we have added the queue. It turns out
that our suggestion does not work.
Part a) What is wrong with our suggestion? (Hint: how do we check
if the queue is full? How do we check if it is empty?)
Part b) What simple change could be made to our queue to resolve
this problem?
Part c) Using your correction, write a few instructions that check
if the queue is full. Use R3 for the HEAD pointer and R4 for the
TAIL pointer.
Part d) Using your correction, write a few instructions that check
if the queue is empty. Again, using R3 for the HEAD pointer and R4
for the TAIL pointer.
In: Computer Science
The two-dimensional arrays list1 and list2 are identical if they have the same contents. Write a method that returns true if they are identical and false if they are not. Use the following header: public static boolean equals(int [][] list1, int [][] list2)
Write a test program that prompts the user to enter two 3 x 3 arrays of integers and displays whether the two are identical.
Enter list1:
Enter list2:
The two arrays are identical or The two arrays are not identical
In: Computer Science
Here is a picture of a Binary Search Tree.
First, construct the Binary Search Tree using the following
BinaryNode as we discussed in class.
public class BinaryNode {
private int value;
private BinaryNode leftChild;
private BinaryNode rightChild;
public BinaryNode(int value) {
this.value = value;
leftChild = null;
rightChild = null;
}
public BinaryNode(int value, BinaryNode leftChild, BinaryNode rightChild)
{
this.value = value;
this.leftChild = leftChild;
this.rightChild = rightChild;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public BinaryNode getLeftChild() {
return leftChild;
}
public void setLeftChild(BinaryNode leftChild) {
this.leftChild = leftChild;
}
public BinaryNode getRightChild() {
return rightChild;
}
public void setRightChild(BinaryNode rightChild) {
this.rightChild = rightChild;
}
@Override
public String toString() {
return "BinaryNode: " +
"value=" + value;
}
}
|
Second, print the nodes in level order, that is, the root node first, then the children of the root node, then the grand-children, etc. It is recommended that you accomplish this by using a queue to store the nodes, printing the first nodes that have been added to the queue.
Your program should print the following when it runs.
42 27 50 21 38 60 33 41 72 |
Submit the file LevelOrder.java when done.
In: Computer Science
programming language: JAVA
4. For this question, write code fragments or methods as directed. (a) Create the Point class that depends on a generic data type parameter T. It has two instance variables called xCoordinate and yCoordinate that both have type T. Write a two parameter constructor to initialize the instance variables. Answer: (b) Write a main method that has instructions to perform the following tasks (in order): Declare an ArrayList of Strings called carModels. Add three models. Print the size of the list. Remove the model from index 1. Insert a model at index 0. Replace the model at index 2. Answer: (c) Write a main method with a try-catch block. Inside the block it creates an array of Strings — the array is called list and has size 10. Print the value stored in list[10]. The catch block should catch ArithmeticException and RuntimeException. Your code shouldn’t be longer than 9 lines excluding curly braces. Answer: (d) Write the private method inputCircles that is called by the following main method. As- sume that class Circle exists and has constructors and a toString method. Your method should open a Scanner and obtain a radius for each of the 20 circles that you make from the user. (You should assume that the class Scanner has already been imported.) public static void main(String args[]) { Circle[] data = new Circle[20]; inputCircles(data); for (Circle c:data) System.out.println(c); } Answer:
In: Computer Science