C++ On linux
Write a C++ program using the IPC. Declare two variables a=5 and b=6 in writer process. Now their product (a*b) will be communicated to the reader process along with your name. The reader process will now calculate the square root of the number and display it along with your name.
In: Computer Science
Problem
Write in drjava is fine.
Using the classes from Assignment #2, do the following:
The Vegetable class should have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method
Child classes should call parent methods whenever possible to minimize code duplication.
The driver program must test all the methods in the Vegetable class, and show that the new methods added to the Plant class can be called by each of the child classes. Include comments in your output to describe what you are testing, for example System.out.println(“testing Plant toString, accessor and mutator”);. Print out some blank lines in the output to make it easier to read and understand what is being output.
Assignment Submission:
Submit a print-out of the Plant and Vegetable classes, the driver file and a sample of the output. Also include a UML diagram of the classes involved. (Use tables in Word to create the various classes. Remember to use the correct arrows between the classes)
Marking Checklist
private String lifespan;
class Plant{
String name;
String lifeSpan;
//Default Constructor
public Plant(){
}
//Parametrized Constructor
public Plant(String name,String lifeSpan){
this.name=name;
this.lifeSpan=lifeSpan;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLifeSpan() {
return lifeSpan;
}
public void setLifeSpan(String lifeSpan) {
this.lifeSpan = lifeSpan;
}
public String toString(){
return "\n\tName:"+name+"\n\tLifeSpan:"+lifeSpan;
}
}
class Tree extends Plant{
float height;
//Default Constructor
public Tree(){
}
//Parametrized Constructor
public Tree(float height,String name,String lifeSpan){
super(name,lifeSpan); //Super Class Constructor
this.height=height;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public String toString(){
return "\n\t"+super.toString()+"\n\tHeight:"+height;
}
}
class Flower extends Plant{
String color;
//Default Constructor
public Flower(){
}
//Parametrized Constructor
public Flower(String color,String name,String lifeSpan){
super(name,lifeSpan); //Super Class Constructor
this.color=color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String toString(){
return "\n\t"+super.toString()+"\n\tColor:"+color;
}
}
public class drjava{
public static void main(String args[]){
System.out.println("\n\nPlant DETAILS\n");
Plant plant=new Plant();
System.out.println("Testing Plant Setter and Getter and toString Methods");
plant.setName("Rose");
plant.setLifeSpan("2Years");
System.out.println("Plant Name:"+plant.getName());
System.out.println("Plant LifeSpan:"+plant.getLifeSpan());
System.out.println("Plant toString:"+plant.toString());
System.out.println("\n\nTREE DETAILS\n");
Tree tree=new Tree();
System.out.println("Testing Tree Setter and Getter and toString Methods");
tree.setName(plant.getName());
tree.setLifeSpan(plant.getLifeSpan());
tree.setHeight(3.565f);
System.out.println("Tree Name:"+tree.getName());
System.out.println("Tree Height:"+tree.getHeight());
System.out.println("Tree LifeSpan"+tree.getLifeSpan());
System.out.println("Tree toString:"+tree.toString());
System.out.println("\n\nFlower DETAILS\n");
Flower flower=new Flower();
System.out.println("Testing Flower Setter and Getter and toString Methods");
flower.setName("Rose Flower");
flower.setLifeSpan("2days");
flower.setColor("Red");
System.out.println("Flower Name:"+flower.getName());
System.out.println("Flower Lifespan:"+flower.getLifeSpan());
System.out.println("Flower Color:"+flower.getColor());
System.out.println("Flower toString:\n"+flower.toString());
}
}
please put each class and driver,thank you!
In: Computer Science
Problem
Write in drjava is fine.
Using the classes from Assignment #2, do the following:
The Vegetable class should have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method
Child classes should call parent methods whenever possible to minimize code duplication.
The driver program must test all the methods in the Vegetable class, and show that the new methods added to the Plant class can be called by each of the child classes. Include comments in your output to describe what you are testing, for example System.out.println(“testing Plant toString, accessor and mutator”);. Print out some blank lines in the output to make it easier to read and understand what is being output.
Assignment Submission:
Submit a print-out of the Plant and Vegetable classes, the driver file and a sample of the output. Also include a UML diagram of the classes involved. (Use tables in Word to create the various classes. Remember to use the correct arrows between the classes)
Marking Checklist
private String lifespan;
class Plant{
String name;
String lifeSpan;
//Default Constructor
public Plant(){
}
//Parametrized Constructor
public Plant(String name,String lifeSpan){
this.name=name;
this.lifeSpan=lifeSpan;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLifeSpan() {
return lifeSpan;
}
public void setLifeSpan(String lifeSpan) {
this.lifeSpan = lifeSpan;
}
public String toString(){
return "\n\tName:"+name+"\n\tLifeSpan:"+lifeSpan;
}
}
class Tree extends Plant{
float height;
//Default Constructor
public Tree(){
}
//Parametrized Constructor
public Tree(float height,String name,String lifeSpan){
super(name,lifeSpan); //Super Class Constructor
this.height=height;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public String toString(){
return "\n\t"+super.toString()+"\n\tHeight:"+height;
}
}
class Flower extends Plant{
String color;
//Default Constructor
public Flower(){
}
//Parametrized Constructor
public Flower(String color,String name,String lifeSpan){
super(name,lifeSpan); //Super Class Constructor
this.color=color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String toString(){
return "\n\t"+super.toString()+"\n\tColor:"+color;
}
}
public class drjava{
public static void main(String args[]){
System.out.println("\n\nPlant DETAILS\n");
Plant plant=new Plant();
System.out.println("Testing Plant Setter and Getter and toString Methods");
plant.setName("Rose");
plant.setLifeSpan("2Years");
System.out.println("Plant Name:"+plant.getName());
System.out.println("Plant LifeSpan:"+plant.getLifeSpan());
System.out.println("Plant toString:"+plant.toString());
System.out.println("\n\nTREE DETAILS\n");
Tree tree=new Tree();
System.out.println("Testing Tree Setter and Getter and toString Methods");
tree.setName(plant.getName());
tree.setLifeSpan(plant.getLifeSpan());
tree.setHeight(3.565f);
System.out.println("Tree Name:"+tree.getName());
System.out.println("Tree Height:"+tree.getHeight());
System.out.println("Tree LifeSpan"+tree.getLifeSpan());
System.out.println("Tree toString:"+tree.toString());
System.out.println("\n\nFlower DETAILS\n");
Flower flower=new Flower();
System.out.println("Testing Flower Setter and Getter and toString Methods");
flower.setName("Rose Flower");
flower.setLifeSpan("2days");
flower.setColor("Red");
System.out.println("Flower Name:"+flower.getName());
System.out.println("Flower Lifespan:"+flower.getLifeSpan());
System.out.println("Flower Color:"+flower.getColor());
System.out.println("Flower toString:\n"+flower.toString());
}
}In: Computer Science
QUESTION 1
Which of the following programming languages does NOT support parametric polymorphism?
|
Java |
||
|
C++ |
||
|
Python |
||
|
C# |
10 points
QUESTION 2
Which of the following programming languages does NOT support operator overloading?
|
C# |
||
|
Python |
||
|
C |
||
|
C++ |
10 points
QUESTION 3
In a language that allows nested subprograms, the programming language has to choose a referencing environment for the executing the passed subprogram when a subprogram is passed as a parameter. Which of the following is NOT a choice?
|
just in time binding |
||
|
shallow binding |
||
|
ad hoc binding |
||
|
deep binding |
10 points
QUESTION 4
Which of the following is necessary for recursion to take place via subprogram calls?
|
static local variables |
||
|
stack dynamic local variables |
||
|
type checking |
||
|
returning values from a function |
10 points
QUESTION 5
Which of the following is NOT a concern when corresponding the actual parameters to the formal parameters?
|
default parameters |
||
|
variable number of parameters |
||
|
return type |
||
|
positional parameters v. keyword parameter |
10 points
QUESTION 6
Which of the following is NOT an inout mode of parameter passing?
|
pass by reference |
||
|
pass by result |
||
|
pass by name |
||
|
pass by value-result |
10 points
QUESTION 7
Which of the following is never used to distinguish between two subprograms in any programming language?
|
return type |
||
|
subprogram name |
||
|
parameter names |
||
|
parameter profiles |
10 points
QUESTION 8
Which of the following types of subprograms exhibit ad hoc polymorphism?
|
OOP languages |
||
|
generic subprograms |
||
|
overloaded subprograms |
||
|
typeless languages |
10 points
QUESTION 9
In which type of language is a closure never necessary?
|
static scoped language that does NOT support nested subprograms |
||
|
dynamically scoped language that does NOT support nested subprograms |
||
|
static scoped language that does support nested subprograms |
||
|
dynamically scoped language that does support nested subprograms |
10 points
QUESTION 10
In what way are coroutines the same as all other programs?
|
only one coroutine is actually in execution at any given time |
||
|
multiple entry points |
||
|
have control statements which suspend execution of the subprogram |
||
|
maintain their status between executions |
10 points
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
In: Computer Science
ShoppingListArrayList
package Shopping;
import DataStructures.*;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @version Spring 2019
* @author Paul Franklin, Kyle Kiefer
*/
public class ShoppingListArrayList implements ShoppingListADT {
private ArrayList<Grocery> shoppingList;
/**
* Default constructor of ShoppingArray object.
*/
public ShoppingListArrayList() {
this.shoppingList = new ArrayList<>();
}
/**
* Constructor of ShoppingArray object that parses from a
file.
*
* @param filename the name of the file to parse
* @throws FileNotFoundException if an error occurs when parsing the
file
*/
public ShoppingListArrayList(String filename) throws
FileNotFoundException {
this.shoppingList = new ArrayList<>();
scanFile(filename);
}
/**
* Method to add a new entry. Only new entries can be added.
Combines
* quantities if entry already exists.
*
* @param entry the entry to be added
*/
@Override
public void add(Grocery entry) {
// Check if this item already exists
if (this.contains(entry)) {
//Merge the quantity of new entry into existing entry
combineQuantity(entry);
return;
}
shoppingList.add(entry);
}
/**
* Method to remove an entry.
*
* @param ent to be removed
* @return true when entry was removed
* @throws DataStructures.ElementNotFoundException
*/
@Override
public boolean remove(Grocery ent) {
// the boolean found describes whether or not we find the
// entry to remove
boolean found = false;
// search in the shoppingList, if find ent in the
// list remove it, set the value of `found'
// Return false if not found
return found;
}
/**
* Method to find an entry.
*
* @param index to find
* @return the entry if found
* @throws Exceptions.EmptyCollectionException
*/
@Override
public Grocery find(int index) throws
IndexOutOfBoundsException,
EmptyCollectionException {
if (this.isEmpty()) {
throw new EmptyCollectionException("ECE - find");
}
throw new IndexOutOfBoundsException("ArrayList - find");
// check whether or not the input index number is legal
// for example, < 0 or falls outside of the size
// return the corresponding entry in the shoppingList
// need to change the return value
// return null;
}
/**
* Method to locate the index of an entry.
*
* @param ent to find the index
* @return the index of the entry
* @throws ElementNotFoundException if no entry was found
*/
@Override
public int indexOf(Grocery ent) throws ElementNotFoundException
{
for (int i = 0; i < shoppingList.size(); i++) {
if (shoppingList.get(i).compareTo(ent) == 0) {
return i;
}
}
throw new ElementNotFoundException("indexOf");
}
/**
* Method to determine whether the object contains an entry.
*
* @param ent to find
* @return true if and only if the entry is found
*/
@Override
public boolean contains(Grocery ent) {
boolean hasItem = false;
// go through the shoppingList and try to find the
// item in the list. If found, return true.
return hasItem;
}
/**
* Gets the size of the collection.
*
* @return the size of the collection
*/
@Override
public int size() {
return shoppingList.size();
}
/**
* Gets whether the collection is empty.
*
* @return true if and only if the collection is empty
*/
@Override
public boolean isEmpty() {
return shoppingList.isEmpty();
}
/**
* Returns a string representing this object.
*
* @return a string representation of this object
*/
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(String.format("%-25s", "NAME"));
s.append(String.format("%-18s", "CATEGORY"));
s.append(String.format("%-10s", "AISLE"));
s.append(String.format("%-10s", "QUANTITY"));
s.append(String.format("%-10s", "PRICE"));
s.append('\n');
s.append("------------------------------------------------------------"
+ "-------------");
s.append('\n');
for (int i = 0; i < shoppingList.size(); i++) {
s.append(String.format("%-25s",
shoppingList.get(i).getName()));
s.append(String.format("%-18s",
shoppingList.get(i).getCategory()));
s.append(String.format("%-10s",
shoppingList.get(i).getAisle()));
s.append(String.format("%-10s",
shoppingList.get(i).getQuantity()));
s.append(String.format("%-10s",
shoppingList.get(i).getPrice()));
s.append('\n');
s.append("--------------------------------------------------------"
+ "-----------------");
s.append('\n');
}
return s.toString();
}
/**
* Add the quantity of a duplicate entry into the existing
*
* @param entry duplicate
*/
private void combineQuantity(Grocery entry) {
try {
int index = this.indexOf(entry);
shoppingList.get(index).setQuantity(
shoppingList.get(index).getQuantity()
+ entry.getQuantity());
} catch (ElementNotFoundException e) {
System.out.println("combineQuantity - ECE");
}
}
/**
* Scans the specified file to add items to the collection.
*
* @param filename the name of the file to scan
* @throws FileNotFoundException if the file is not found
*/
private void scanFile(String filename) throws FileNotFoundException
{
Scanner scanner = new
Scanner(getClass().getResourceAsStream(filename))
.useDelimiter("(,|\r\n)");
while (scanner.hasNext()) {
Grocery temp = new Grocery(scanner.next(), scanner.next(),
Integer.parseInt(scanner.next()),
Float.parseFloat(scanner.next()),
Integer.parseInt(scanner.next()));
add(temp);
}
}
}
ShoppingListArrayListTest
package Shopping;
import DataStructures.*;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
/**
* @version Spring 2019
* @author Paul Franklin, Kyle Kiefer
*/
public class ShoppingListArrayListTest {
private ShoppingListArrayList instance;
/**
* Initialize instance and entries
*/
@Before
public void setupTestCases() {
instance = new ShoppingListArrayList();
}
/**
* Test of add method, of class ShoppingArray.
*/
@Test
public void testAdd() {
assertTrue(0==1);
}
/**
* Test of remove method, of class ShoppingArrayList.
*/
@Test
public void testRemove() {
assertTrue(0==1);
}
/**
* Test of find method, of class ShoppingArrayList.
*/
@Test
public void testFind() {
assertTrue(0==1);
}
/**
* Test of indexOf method, of class ShoppingArrayList.
*/
@Test
public void testIndexOf() {
assertTrue(0==1);
}
/**
* Test of contains method, of class ShoppingArrayList.
*/
@Test
public void testContains() {
assertTrue(0==1);
}
/**
* Test of size method, of class ShoppingArrayList.
*/
@Test
public void testSize() {
Grocery entry1 = new Grocery("Mayo", "Dressing / Mayo", 1, 2.99f,
1);
assertEquals(0, instance.size());
instance.add(entry1);
// Test increment
assertEquals(1, instance.size());
assertTrue(instance.remove(entry1));
// Test decrement
assertEquals(0, instance.size());
}
/**
* Test of isEmpty method, of class ShoppingArrayList.
*/
@Test
public void testIsEmpty() {
Grocery entry1 = new Grocery("Mayo", "Dressing / Mayo", 1, 2.99f,
1);
// Test empty
assertTrue(instance.isEmpty());
instance.add(entry1);
// Test not empty
assertFalse(instance.isEmpty());
}
}
package Shopping;
import DataStructures.*;
/**
* @version Spring 2019
* @author Paul Franklin, Kyle Kiefer
*/
public interface ShoppingListADT {
/**
* Method to add a new entry. Only new entries can be added.
Combines
* quantities if entry already exists.
*
* @param entry the entry to be added
*/
public void add(Grocery entry);
/**
* Method to remove an entry.
*
* @param ent to be removed
* @return true when entry was removed
*/
public boolean remove(Grocery ent);
/**
* Method to find an entry.
*
* @param index to find
* @return the entry if found
* @throws Exceptions.EmptyCollectionException
*/
public Grocery find(int index) throws
IndexOutOfBoundsException,
EmptyCollectionException;
/**
* Method to locate the index of an entry.
*
* @param ent to find the index
* @return the index of the entry
* @throws ElementNotFoundException if no entry was found
*/
public int indexOf(Grocery ent) throws
ElementNotFoundException;
/**
* Method to determine whether the object contains an entry.
*
* @param ent to find
* @return true if and only if the entry is found
*/
public boolean contains(Grocery ent);
/**
* Gets the size of the collection.
*
* @return the size of the collection
*/
public int size();
/**
* Gets whether the collection is empty.
*
* @return true if and only if the collection is empty
*/
public boolean isEmpty();
/**
* Returns a string representing this object.
*
* @return a string representation of this object
*/
@Override
public String toString();
}
In: Computer Science
researchers at harris interactive wondered if there was a difference between males and females in regard to whether they typically buy name- brand or store- brand products. they asked a random sample of males and females the following question. "for each of the following types of products, please indicate whether you typically buy name- brand products or store- brand products?" among the 1104 males surveyed, 343 indicated they buy name- brand over-the-counter drugs; among the 1172 females surveyed, 295 indicated they buy name- brand over-the-counter drugs. does the evidence suggests a lower proportion of females by name- brand over-the-counter drugs?
(a) explain why this study can be analyzed using the methods for conducting a hypothesis test regarding two independent portions.
(b) what are the null and alternative hypotheses?
(c) describe the sampling distribution of Pfemale- Pale draw a normal model with the area representing the P-value shaded for this hypothesis test.
(d) determine the P-value based on the model from part (c).
(e) interpret the P-value.
(f) based on the p-value, what does the sample evidence suggest? that is, what is the conclusion of the hypothesis test? Assume an alpha=0.05 level of significance.
In: Statistics and Probability
Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.
Ask the user to input a phone number.
The program checks which part of Colorado a phone number is from using the values below.
If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits are entered, display the phone number and state it is not in Colorado.
If the number is in Estes Park, the user should see: phone number + “is in Estes Park, it is time to go pick up your new Corgi puppy!”
If the second digit of a phone number is:
0 = Boulder
1 = Colorado Springs
2 = Denver
7 = Estes Park
Sample output:
Please enter your first and last name: Ollie Biscuit
Hello, O Biscuit! //displays first initial and last name
Please enter a phone number:
Your phone number is: xxx-xxx-xxxx. Your number is not in Colorado.
OR
Your phone number is: xxx-xxx-xxxx. Your number is in Denver.
OR
Your phone number is: xxx-xxx-xxxx is in Estes Park, it is time to go pick up your new Corgi puppy!
In: Computer Science
Part 2:
On January 1, 2018, Caldwell Corporation had 75,000 shares of $1 par value common stock issued and outstanding. During the year, the following transactions occurred:
Mar. 1 Issued 45,000 shares of common stock for $675,000
June 1 Declared a cash dividend of $2.00 per share to stockholders of record on June 15
June 30 Paid the $2.00 cash dividend
Dec. 1 Purchased 4,000 shares of common stock for the treasury for $18 per share
Dec. 15 Declared a cash dividend on outstanding shares of $2.50 per share to stockholders of record on December 31
NOTE: Dividends are only declared and paid on the # shares OUTSTANDING. You need to keep a running total of the # shares outstanding so that your dividends on Dec 15th are correct.
Required:
Prepare journal entries to record the above transactions. (15 points)
|
3/1/18 |
Account Name |
Debit |
Credit |
|
6/1/18 |
Account Name |
Debit |
Credit |
|
6/30/18 |
Account Name |
Debit |
Credit |
|
12/1/18 |
Account Name |
Debit |
Credit |
|
12/15/18 |
Account Name |
Debit |
Credit |
In: Accounting
Assume that you are trying to get an algorithm which is supposed to generate legit words. In default, any letter from the English alphabet is equally likely to occur right after any English letter (including itself). Now you introduce your name and lastname as separate samples to your algorithm. The algorithm will learn some information about legit words from these samples and accordingly, it will adjust the probabilities by an additive fixed value p. For example, if your name is EDA, then the algorithm adjust itself by setting the probability of having D right after E as p+1/28 similarly probability of having A right after D as p+ 1/28. Of course, in that case the probabilities of having other letters right after E and D will be adjusted accordingly. Algorithm works only on pairs, so the triple orders do not matter for the algorithm. For all other details, by aiming to maximize the learning capability of your algorithm, you are free to decide on the new strategies. So, what new information will the algorithm get from your name and last-name. With what probability your algorithm could generate the word MEDIPOL. With what probability your algorithm could generate your last-name.
In: Statistics and Probability
Once you have accomplished that action, paste the script into your assignment submission document for this part of your assignment.
In: Computer Science