Questions
MAKE node class outside of stack class class Stack{    private:        class node{   ...

MAKE node class outside of stack class

class Stack{
   private:
       class node{
           public:
               node *next;
               int data;
               node(int d,node *n = NULL){
                   data = d;
                   next = n;
               }
       };
       node *start;
      
   public:
       Stack();
       Stack(const Stack& original);
       ~Stack();
      bool isEmpty() const ;
       int top() const;
      int pop() ;
       void push(int);
};

Stack::Stack(){
   start = NULL;
}

Stack::Stack(const Stack& original){
   if (original.isEmpty()) {
       start = NULL;
   } else {
       node* p = original.start; // points to current node on other
       node* tmp = new node(p->data); // make a copy of the first node
       start = tmp;
       node* tail = tmp; // points to last node of this list
       while (p->next != NULL) {
           p = p->next;
           tmp = new node(p->data);
           tail->next = tmp;
           tail = tmp;
       }
   }
}

Stack::~Stack(){
   node * curr = start;
   node *next;
   while(curr!=NULL){
       next = curr->next;
       delete curr;
       curr = next;
   }
}

bool Stack::isEmpty() const{
   if(start==NULL)
       return 1;
   return 0;
}

int Stack::top() const{
   if(isEmpty())
       throw "Stack is Empty";  
   return (start->data);
  
}

void Stack::push(int e){
   node *p = new node(e);
   if(isEmpty()){
       start = p;
   }else{
       p->next = start;
       start = p;
   }
  
}

int Stack::pop() {
   if(isEmpty())
       throw "Stack is Empty";
   else
   {
       node *p = start;
       start = start->next;
       int d = p->data;
       delete p;
       return d;
   }
}

/* A TEST PROGRAM */

#include<iostream>
using namespace std;

class Stack{
   private:
       class node{
           public:
               node *next;
               int data;
               node(int d,node *n = NULL){
                   data = d;
                   next = n;
               }
       };
       node *start;
      
   public:
       Stack();
       Stack(const Stack& original);
       ~Stack();
      bool isEmpty() const ;
       int top() const;
      int pop() ;
       void push(int);
};

Stack::Stack(){
   start = NULL;
}

Stack::Stack(const Stack& original){
   if (original.isEmpty()) {
       start = NULL;
   } else {
       node* p = original.start; // points to current node on other
       node* tmp = new node(p->data); // make a copy of the first node
       start = tmp;
       node* tail = tmp; // points to last node of this list
       while (p->next != NULL) {
           p = p->next;
           tmp = new node(p->data);
           tail->next = tmp;
           tail = tmp;
       }
   }
}

Stack::~Stack(){
   node * curr = start;
   node *next;
   while(curr!=NULL){
       next = curr->next;
       delete curr;
       curr = next;
   }
}

bool Stack::isEmpty() const{
   if(start==NULL)
       return 1;
   return 0;
}

int Stack::top() const{
   if(isEmpty())
       throw "Stack is Empty";  
   return (start->data);
  
}

void Stack::push(int e){
   node *p = new node(e);
   if(isEmpty()){
       start = p;
   }else{
       p->next = start;
       start = p;
   }
  
}

int Stack::pop() {
   if(isEmpty())
       throw "Stack is Empty";
   else
   {
       node *p = start;
       start = start->next;
       int d = p->data;
       delete p;
       return d;
   }
}

In: Computer Science

Math V3.0 Modify the previous version of this program again so it displays a menu allowing...

Math V3.0

Modify the previous version of this program again so it displays a menu allowing the user to select addition, subtraction, multiplication, or division problem. The final selection on the menu should let the user quit the program. After the user has finished the math problem, the program should display the menu again. This process is repeated until the user chooses to quit the program. If a user selected an item not on the menu, display an error message and display the menu again.

Note: Start with your code from the previous chapter! For this assignment, you are extending your previous project by allowing for subtraction, multiplication, and division, as well as addition. This can be a bit tricky (hence this is worth two assignments), so be careful. Here is a basic outline of what your program should look like:

  1. Declare your variables, including the correct answer
  2. Display the menu and prompt the user for their choice
  3. Make sure it is a valid choice
  4. For each possible choice:
    1. Figure out the two operands appropriately
    2. Determine and store the correct answer
    3. Display the problem (formatted nicely!)
  5. Assuming they didn't hit 5 to exit, prompt for the answer
  6. Provide feedback on the user's answer
  7. Repeat the loop as necessary

All generated numbers must be random. For addition and subtraction, the range of numbers must be between 50 and 500, like before. For multiplication, limit the numbers to be in the ranges 1-100 and 1-9. For division, generate the denominator in the range of 1-9. The numerator must be a multiple of the denominator (so there are no remainders for division!), no more than 50 times larger. You might have to think about this!

The output should look like this -- user inputs are in bold blue type:

Math Menu
------------------------------
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
------------------------------
Enter your choice (1-5): 4

66 / 6 = 11

Congratulations! That's right.

Math Menu
------------------------------
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
------------------------------
Enter your choice (1-5): 2

473 - 216 = 241

Sorry! That's incorrect.

Math Menu
------------------------------
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
------------------------------
Enter your choice (1-5): 5
Thank you for using Math.

In: Computer Science

Temperature Converter Modify the previous version of this program so that it uses a loop to...

Temperature Converter

Modify the previous version of this program so that it uses a loop to display a range of temperature conversions for either Fahrenheit to Celsius or Celsius to Fahrenheit.

Note: You can start with the code from the previous version, then modify it slightly after it prompts the user for the direction to convert. It will then ask the user for a starting temperature and ending temperature. Assuming they entered the lower number first (if not, tell them and end the program), loop through the range provided, incrementing by 1 for each iteration of the loop, and generate the appropriate table.

The output should look like this -- user inputs are in bold blue type:
Temperature Conversion Table
Enter c (or C) to convert Fahrenheit to Celsius
   or f (or F) to convert Celsius to Fahrenheit: F
Enter the starting temperature: 30
Enter the ending temperature: 42

Celsius  Fahrenheit
    30        86.0
    31        87.8
    32        89.6
    33        91.4
    34        93.2
    35        95.0
    36        96.8
    37        98.6
    38       100.4
    39       102.2
    40       104.0
    41       105.8
    42       107.6

Running the program again:
Temperature Conversion Table
Enter c (or C) to convert Fahrenheit to Celsius
   or f (or F) to convert Celsius to Fahrenheit: c
Enter the starting temperature: -4
Enter the ending temperature: 4

Fahrenheit  Celsius
    -4       -20.0
    -3       -19.4
    -2       -18.9
    -1       -18.3
     0       -17.8
     1       -17.2
     2       -16.7
     3       -16.1
     4       -15.6

In: Computer Science

This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference...

This program needs to be in Java


Exercise on Single Dimensional Arrays

  1. Declare an array reference variable arrayInt for an array of integers. Create the array of size 100, and assign it to arrayInt. (2 points)
  2. Write a method to populate the array with Random numbers between 1 to 25. Signature of the method is: populateArray( int[] ) which returns nothing. Call this method from main with arrayInt--> populateArray(arrayInt). (2 points)
  3. Write a method to print an array. Signature of the method is: printArray( int[] ) which returns nothing. Print maximum of ten(10) numbers on a line (see sample output below). Call this method from main with arrayInt--> printArray(arrayInt). Hint: Use the modulus operator. Any number n % 10 will return a value 0-9. (3 points)
  4. Write a method that finds the average of the array elements. Signature of the method is: findAverage( int[] ) which returns the averageto the calling program.Call this method from main with arrayInt--> findAverage(arrayInt).  (3 points)

SAMPLE OUTPUT:

1   12 20  11  10  15  17   5  20   8  
23 6 4 20 23 15 15 24 4 19
3 10 15 12 8 5 23 24 2 25
2 19 13 3 7 22 17 8 15 9
22 17 3 5 5 20 24 19 21 13
9 1 16 5 16 8 24 11 7 1
19 16 14 11 23 22 23 25 18 3
16 3 10 3 17 15 3 17 15 17
22 16 16 7 15 7 10 22 10 1
21 20 18 4 11 24 24 2 19 12
The average is: 12.51

In: Computer Science

Using Java, Complete LinkedListSet: package Homework3; public class LinkedListSet <T> extends LinkedListCollection <T> { LinkedListSet() {...

Using Java, Complete LinkedListSet:

package Homework3;
public class LinkedListSet <T> extends LinkedListCollection <T> {
LinkedListSet() {
}
public boolean add(T element) {
// Code here
return true;
}
}

Homework3 class:

public class Homework3 {
public static void main(String[] args) {
ArrayCollection ac1 = new ArrayCollection(); // Calling Default
Constructor
ArrayCollection ac2 = new ArrayCollection(2); // Calling overloaded
constructor
ArraySet as1 = new ArraySet();
ac2.add("Apple");
ac2.add("Orange");
ac2.add("Lemon"); // This can't be added into ac2 as collection is full
System.out.println(ac2.remove("Apple")); // This should return true
System.out.println(ac2);
ac2.enlarge(10);
ac2.add("Watermelon");
System.out.println("Equals: " + ac1.equals(ac2));
as1.add("Avocado");
as1.add("Avocado"); // This will not be added, since the
collection is "set"
}
}

In: Computer Science

what is C++? what is embedded computer?

what is C++?

what is embedded computer?

In: Computer Science

JAVA PLEASE Write a recursive function that does the following: Given a number, add all the...

JAVA PLEASE
Write a recursive function that does the following:
Given a number, add all the digits and display the sum.
Example:
​​The sum of the number 5432 would be 14.
o Do not use the static modifier. No global variables. Your program should implement a non-tail recursive algorithm. In other words, it should do something as it moves towards the base case, the tail, and also do something as it comes back from the tail to the beginning.
o The input is going to be received as a single integer from the user, in the main function. The input will not be more than four digits long (no validation necessary).

In: Computer Science

There are a lot of networking and network security jobs and every IT company has network...

There are a lot of networking and network security jobs and every IT company has network engineers, admins, etc. Why and how do think understanding the OSI Model and Network Devices are important from a work standpoint? Looking for some original content.

In: Computer Science

Using Java Languse, Complete ArraySet.java down below by using (Array collection) : package Homework3; public class...

Using Java Languse, Complete ArraySet.java down below by using (Array collection) :

package Homework3;
public class ArraySet extends ArrayCollection {
public ArraySet() {
}
public ArraySet(int size) {
super(size);
}
public boolean add(T element) {
// Complete your code here
return true;
}
}

ArrayCollection.java:

package Homework3;
public class ArrayCollection {
protected static final int DEFAULT_CAPACITY = 100;
protected T[] elements;
protected int numberOfElements;
public ArrayCollection() {
this(DEFAULT_CAPACITY);
}
public ArrayCollection(int size) {
elements = (T[]) new Object[size];
numberOfElements = 0;
}
public boolean isEmpty() {
return numberOfElements == 0;
}
public boolean isFull() {
return numberOfElements == elements.length;
}
public int size() {
return numberOfElements;
}
public String toString() {
String collection = "";
for (int i = 0; i < numberOfElements; i++)
collection += elements[i] + "\n";
return collection;
}
public boolean add(T element) {
// Complete your code here
return true;
}
public boolean remove(T target) {
// Complete your code here
return true;
}
public boolean removeAll(T target) {
// Complete your code here
return true;
}
public void removeDuplicate() {
// Remove any duplicated elements
}
public boolean equals(ArrayCollection that) {
// Return true if ArrayCollection are identical.
boolean result = true;
// Complete your code here.
return result && this.size() == that.size();
}
public int count(T target) {
// Return count of target occurrences
int c = 0;
// Complete your code here
return c;
}
public void merge(ArrayCollection that) {
// Merge that ArrayCollection into this ArrayCollection
// Complete your code here
}
public void enlarge(int size) {
// Enlarge elements[] with additional size
// Complete your code here
}
public void clear() {
// Remove all elements in the collection
}
//Note: Different from textbook, this implementation has no 'found' and
'location' attributes.
// There is no find() method.
// There is a new methods findIndex().
public boolean contains(T target) {
// Return true if target is found
boolean found = false;
// Complete your code here
return found;
}
public int findIndex(T target) {
// Return index of target
int index = 0;
// Complete your code here
return index;
}
}

Homework3 class:

public class Homework3 {
public static void main(String[] args) {
ArrayCollection ac1 = new ArrayCollection(); // Calling Default
Constructor
ArrayCollection ac2 = new ArrayCollection(2); // Calling overloaded
constructor
ArraySet as1 = new ArraySet();
ac2.add("Apple");
ac2.add("Orange");
ac2.add("Lemon"); // This can't be added into ac2 as collection is full
System.out.println(ac2.remove("Apple")); // This should return true
System.out.println(ac2);
ac2.enlarge(10);
ac2.add("Watermelon");
System.out.println("Equals: " + ac1.equals(ac2));
as1.add("Avocado");
as1.add("Avocado"); // This will not be added, since the
collection is "set"
}
}

In: Computer Science

What the importance of Subnetting? Why do we need to learn Subnetting? How is it useful...

What the importance of Subnetting? Why do we need to learn Subnetting? How is it useful in day-to-day operations at a company? Looking for some original content.

In: Computer Science

The implementations of the methods addAll, removeAll, retainAll are omitted in the MyList interface. Implement these...

The implementations of the methods addAll, removeAll, retainAll are omitted in the MyList interface. Implement these methods.


/** Adds the elements in otherList to this list.
* Returns true if this list changed as a result of the call */
public default boolean addAll(Collection<? extends E> c)


/** Removes all the elements in otherList from this list
* Returns true if this list changed as a result of the call */
public default boolean removeAll(Collection<?> c)


/** Retains the elements in this list that are also in otherList
* Returns true if this list changed as a result of the call */
public default boolean retainAll(Collection<?> c)


Write a test program that creates two MyArrayLists, list1 and list2, with the initial values {"Tom", "George", "Peter", "Jean", "Jane"} and {"Tom", "George", "Michael", "Michelle", "Daniel"}, then perform the following operations:
■ Invokes list1.addAll(list2), and displays list1 and list2.
■ Recreates list1 and list2 with the same initial values, invokes list1.removeAll(list2), and displays list1 and list2.
■ Recreates list1 and list2 with the same initial values, invokes list1.retainAll(list2), and displays list1 and list2.

In: Computer Science

Java Programming : Email username generator Write an application that asks the user to enter first...

Java Programming :

Email username generator Write an application that asks the user to enter first name and last name. Generate the username from the first five letters of the last name, followed by the first two letters of the first name. Use the .toLowerCase() method to insure all strings are lower case. String aString = “Abcd” aString.toLowerCase(); aString = abcd Use aString.substring(start position, end position + 1) aString.substring(0, 3) yields the first 3 letters of a string If the last name is no more than five letters, use the entire name. If it is more than five letters, use the first 5 letters Print the email username you generated with @myCollege.edu appended

In: Computer Science

Create a simple Java class for a Month object with the following requirements:  This program...

Create a simple Java class for a Month object with the following requirements:


 This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.
 All methods will have comments concerning their purpose, their inputs, and their outputs
 One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February, etc.)
 A constructor that takes no arguments, and sets the monthNumber to 1.
 Add a second constructor that takes in an integer argument to set the initial monthNumber for the new Month object. Use data protection to prevent the user from entering a number less than 1 or greater than 12. When a non-valid input is entered, throw a new IllegalArgumentException.
 A setMonth() method that takes an integer and uses data protection to prevent the user from entering a number less than 1 or greater than 12. Also throw an IllegalArgumentException if an illegal value is entered.
 A getMonth() method that returns the monthNumber as an integer.
 Add a String array property that holds the values of the month names (e.g. monthNames[3] would hold the value “March”). Remember, you can leave the 0th index blank/null
 Add a toString() method to use the monthNumber property to return the name of the month as a String. Use the private global String array with the names of the months in it to return the proper String based on the monthNumber.
 Add an equals() method that takes in a month object and returns a boolean based on the values of each object’s monthNumber
 Add a compareTo() method that takes in a month object and returns a negative number if the called object is smaller than the passed in object, a positive number if the called object is bigger than the passed in object, and zero (0) if the two objects are equivalent.

Create a simple program using Java that demonstrates the month object with the following requirements:


 That creates a month object using the no argument constructor.
 A second month object is created using the constructor that takes in an integer argument.
 Additionally, use either a do or while loop to get the user to enter a number between 1 and 12 using the setMonth() method on the 1st month object. The loop will continue until they enter a valid number.
 The program will display the month number for both of the objects using the getMonth() method.
 Display the month names using toString() for the months created, and see whether they are the same or not.
 Additionally, use the equals() method created above to show whether the two months are equivalent to each other or not.
 Use the compareTo() method created above to show which object is the biggest.
 Use appropriate try and catch statements to properly handle erroneous input by the user.

In: Computer Science

Using Java, Complete the LinkedListBag down below by using the (LinkedListCollection.java:) package Homework3; public class LinkedListBag...

Using Java, Complete the LinkedListBag down below by using the (LinkedListCollection.java:)

package Homework3;
public class LinkedListBag extends LinkedListCollection {
LinkedListBag() {
}
public T grab() {
T result;
Node cursor = head;
int rand = (int) (Math.random() * size());
// Some code in here..
result = cursor.getInfo();
remove(result);
return result;
}
}

LinkedListCollection.java:

package Homework3;
public class LinkedListCollection <T> {
protected Node<T> head = null;
public LinkedListCollection() {
}
public boolean isEmpty() {
return head == null;
}
public int size() {
int counter = 0;
Node<T> cursor = head;
while (cursor != null) {
cursor = cursor.getLink();
counter++;
}
return counter;
}
public String toString() {
Node<T> cursor = head;
String collection = "";
while (cursor != null) {
collection += cursor.getInfo() + "\n";
cursor = cursor.getLink();
}
return collection;
}
public boolean add(T element) {
// Insert at head
Node<T> node = new Node<T>(element);
// Code here
return true;
}
public boolean remove(T target) {
Node<T> cursor = head;
Node<T> previous = head;
while (cursor != null) {
// Code here
previous = cursor;
cursor = cursor.getLink();
}
return false;
}
public boolean removeAll(T target) {
Node<T> cursor = head;
Node<T> previous = head;
boolean found = false;
// Code here
return found;
}
public void removeDuplicate() {
// Remove any duplicated elements
// Code here
}
public boolean equals(LinkedListCollection that) {
// Return true if LinkedListCollection are identical.
boolean result = true;
Node<T> cursor_this = head;
Node<T> cursor_that = that.head;
while (cursor_this != null && cursor_that != null) {
if (!cursor_this.getInfo().equals(cursor_that.getInfo()))
result = false;
cursor_this = cursor_this.getLink();
cursor_that = cursor_that.getLink();
}
return result && this.size() == that.size();
}
public int count(T target) {
// Return count of target occurrences
int c = 0;
Node<T> cursor = head;
// Code here
return c;
}
public void merge(LinkedListCollection that) {
// Merge that LinkedListCollection into this LinkedListCollection
if (that.head == null) return; // Nothing to merge
if (this == that) return; // Same list
// Code here
}
public void clear() {
// Remove all elements in the collection
}
public boolean contains(T target) {
// Return true if target is found
boolean found = false;
Node<T> cursor = head;
// Code here
return found;
}
}

Homework3 class:

public class Homework3 {
public static void main(String[] args) {
ArrayCollection ac1 = new ArrayCollection(); // Calling Default
Constructor
ArrayCollection ac2 = new ArrayCollection(2); // Calling overloaded
constructor
ArraySet as1 = new ArraySet();
ac2.add("Apple");
ac2.add("Orange");
ac2.add("Lemon"); // This can't be added into ac2 as collection is full
System.out.println(ac2.remove("Apple")); // This should return true
System.out.println(ac2);
ac2.enlarge(10);
ac2.add("Watermelon");
System.out.println("Equals: " + ac1.equals(ac2));
as1.add("Avocado");
as1.add("Avocado"); // This will not be added, since the
collection is "set"
}
}

In: Computer Science

---------------- Exercise 2: String Permutations ---------------- Create a program that takes a string from the command...

----------------

Exercise 2: String Permutations

----------------

Create a program that takes a string from the command line and prints every permutation of that string. You may assume the string will contain all unique characters. You may print the permutations in any order, as long as you print them all.

----------------

Output:

----------------

$>./prog dog
d
do
dog
dg
dgo
o
od
odg
og
ogd
g
gd
gdo
go
god

----------------

I have no idea on coding this. The files I need for this exercise are main.cpp, makefile, Executive.cpp, and Executive.h. So, will someone help me on this exercise? If so, then that will be great.

In: Computer Science