Questions
Code in C++, create the erase function shown in int main() /* Use of dynamic memory...

Code in C++, create the erase function shown in int main()

/* Use of dynamic memory to implement dynamic array (like vector) */

#include <iostream>
using namespace std;

class MyVector {
private:
    int* arr; //only stores ints
    int size;
    int cap;
public:
    MyVector() : arr{nullptr} {}; // Default constructor;
    ~MyVector(); // Destructor: Cleans up stuff. Here deletes arr
    void push(int ele); // inserts element into vector
    friend ostream& operator <<(ostream& os, MyVector& v);
    
    
};


int main()
{
    MyVector vec;
    vec.push(1); //should store 1 in the vec
    vec.push(2); // should store 2 into the vec
    vec.push(10); // should print all elements
    vec.erase(0) // Erase element at position 0
    cout << vec << endl; // should print remaining elements
    
}

MyVector::~MyVector() // Destructor
{
    delete[] arr;
    cout << "Destroyed vector" << endl;
    
}

ostream& operator <<(ostream& os, MyVector& v)
{
    for(int i = 0; i < v.size; i++)
        os << v.arr[i] << " ";
    return os;
}

void MyVector::push(int ele)
{
    // Check if arr == nullptr. If yes, dynamically create an array of elements. Insert ele into array
    if (arr == nullptr) {
        cap = 2;
        arr = new int[cap];
        arr[0] = ele;
        size = 1;
    }
    else {
        // Check if there is space
        if (size < cap) {
            arr[size] = ele;
            size++;
        }
        else {
            int* temp = arr;
            arr = new int[2*cap];
            for (int i = 0; i < cap; i++)
                arr[i] = temp[i];
            delete[] temp;
            cap = 2*cap;
            arr[size] = ele;
            size++;
        }

    }
    
}

In: Computer Science

How would you explain diversity in the workplace? What are the benefits of diversity in the...

How would you explain diversity in the workplace?

What are the benefits of diversity in the workplace?

Are there different ways to manage diversity in the workplace?

Challenges a supervisor face to manage workplace diversity?

In: Operations Management

A leech would not have a notochord. segmentation. a ventral nerve cord. a coelom. mesoderm.

A leech would not have

  • a notochord.

  • segmentation.

  • a ventral nerve cord.

  • a coelom.

  • mesoderm.

In: Biology

Exercise 19. Repeat Exercise 3. with the contestant pulling the block of ice with a rope...

Exercise 19.
Repeat Exercise 3. with the contestant pulling the block of ice with a rope over his shoulder at the same angle above the horizontal as shown in Figure 5.7(b).

In: Physics

in java A NavigableSet is a set that stores it’s element in order. Say we have...

in java

A NavigableSet is a set that stores it’s element in order. Say we have a bunch of items
and we want to store them in order but we don’t want any duplicates. Write a generic
class that implements a structure that does that.

In: Computer Science

C data structure Initially, we do not need to do any error checking - we can...

C data structure

Initially, we do not need to do any error checking - we can assume that the input postfix expression is syntactically correct.

Input

The input is a string that represents a postfix expression. To simplify the problem, your calculator will be restricted to operating on single-digit non-negative integers. Only the following characters are allowed in the string:

  • the operators '+', '-'. '*', and '/'

  • the digits '0' through '9'

  • the space (blank) character ' '

Example input:

  7 8 5 * +

Processing

To handle spaces in the input, need to make one minor addition to the algorithm

  if (ch is a blank)

      ignore it

   end if

Program should ask the user to enter a text file with postfix expression on a single line. we can either read the line one character at a time, or can read the line into a string and then process the string one character at a time. Your program should then print the value of the expression. program should include a loop so that the user can evaluate multiple postfix expressions. Your output might look like:

  Enter postfix expression:

   5 8 9 + *

   The value of the expression is result of postfix

   More expressions (Y or N)? Y

   Enter postfix expression:

   9 5 /

   The value of the expression is 1

   More expressions (Y or N)? N

program should perform integer calculations only(single digit only). Do not use floating-point (float or double) variables for your calculations.

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

Second part would be interesting in this part we have to do error checking after calculator thoroughly tested.

Error checking

1). Invalid character in the input expression- if the error occurs, print an error message stating that an invalid character was encountered.

2) Stack is empty when the algorithm needs to remove an operand- this happens when the expression has too many operators or when the operators and operands are not ordered correctly. We call this a malformed expression, if this occurs, print an error message indicating that the expression is malformed.

3). When the loop in the algorithm ends, there should be exactly one value left on the stack and it is the value of input expression. If the input contained too many operands, there will be more than one value left on the stack. If you remove what should be the result of the expression and the stack is not empty, then the expression was malformed and should print error message indicating.

In all cases, if an error occurs do not try to continue processing the input string and do not try to print the value of the expression. Just print the error message. Do not end application- just ask user if he wants to try another expression.

In: Computer Science

Number of spacecraft that visited both Jupiter and Saturn but neither Uranus nor Neptune: (Please explain...

Number of spacecraft that visited both Jupiter and Saturn but neither Uranus nor Neptune:

(Please explain for a rating. Thanks!)

In: Physics

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to...

In C++ Language: Program a multiple(4) choice quiz with 10 question that allows the user to input their choice. Validate their choice, if choice is valid continue. If choice is not valid have the user input a different answer. If the user gets 3 of the 10 choices incorrect, then the quiz is over.

In: Computer Science

1) 1.95 moles of HBr in 250.0 mL flask is consumed in 1.00 minutes in the...

1) 1.95 moles of HBr in 250.0 mL flask is consumed in 1.00 minutes in the gas phase reaction 2 HBr(g) → H2(g) + Br2(g) at 150°C.   The rate of reaction is __________ M∙s-1.

3.85

0.0650

0.0169

0.260

0.0860

2)The reaction A → C is found to be zero order. Which of the following will give a linear plot?

(A) vs. time

ln(A) vs. time

1/(A) vs. time

None of these will be linear.

3)Which of the following is not a colligative property?

depression of solvent vapor pressure upon addition of a solute to a solvent

elevation of the boiling point of a solution upon addition of a solute to a solvent

depression of the freezing point of a solution upon addition of a solute to a solvent

an increase in the osmotic pressure of a solution upon the addition of more solute

the increase of reaction rates with increase in temperature

4)

Yeast and sugar are added to champagne to give the sparkle of carbonation. Under what conditions is carbon dioxide gas most soluble?

low temperature, high pressure

low temperature, low pressure

high temperature, low pressure

high temperature, high pressure

none of these

5)

In general, the solubility of ________ in water decreases as temperature increases.

liquids

solids

gases

none of these

6) In a solution, the solvent is:

always water

the substance in the greatest amount

the substance that is dissolved

always a gas

In: Chemistry

A long answer question will require one to three paragraphs Describe and compare the phenomena of...

A long answer question will require one to three paragraphs

Describe and compare the phenomena of genes that follow polygenic inheritance, multiple alleles, codominance, and incomplete dominance?

In: Biology

Please summarize some information about geography, history, demography, and socio-politico-economic aspects of the Turkey. Please do...

Please summarize some information about geography, history, demography, and socio-politico-economic aspects of the Turkey. Please do NOT copy and paste from another source. Please write at least 500 words.

In: Economics

(2) On one day a man who claimed to be Dr. Bun, of NoTrue WallPaper Ltd.,...

(2) On one day a man who claimed to be Dr. Bun, of NoTrue WallPaper Ltd., the expert wallpaper, persuaded Harry to buy the wallpaper for interior decoration. Harry bought 100 rolls wallpaper for HK$50,000 for Susan's apartment. He signed a written contract without bothering to read it. The contract said that NoTrue WallPaper Ltd. would have no liability for any defect in the wallpaper. When Harry used the wallpaper, they are wet and cannot put onto the wall. Harry goes back to NoTrue WallPaper Ltd., but it is already shut down. Harry immediately reported to the police and Consumer Council, but he was told that the man who had sold wallpaper to Harry was a rogue pretending to be Dr. Bun. Advice Harry of his legal position.

(3) Harry completes the first stage of the contracted design work. In reliance on the agreed design, Susan is planning to purchase a European L-shaped sofa made in Spain from iFurniture, a furniture company, for HK$25,000. Susan just see the sofa set from iFurniture's catalogue, she says that she would very much like to view the real sofa but that she is out of town on a five-day business trip and will not be able to view it until she returns. The boss of iFurniture, Lucas says that if another buyer comes forward, he will have to sell the sofa to that buyer. Susan says she will pay HK$2,500 if iFurniture promises not to sell the sofa to another buyer for the next five days. Lucas agrees to this. Analyse whether any contract has been made between the parties and, if so, what are its terms? Refer to the relevant case law to support your answer.

(4) Harry completes the contracted design work, but Susan only pays HKS300,000, instead of the HKS500,000 originally agreed. Advise Harry of his legal position.

In: Accounting

As a manager, what do you need to understand when reading or listening to economic and...

As a manager, what do you need to understand when reading or listening to economic and business reports? How can economic and business reports impact an individual business in a global economy?

In: Economics

Consider the two (excess return) index-model regression results for stocks A and B. The risk-free rate...

Consider the two (excess return) index-model regression results for stocks A and B. The risk-free rate over the period was 5%, and the market’s average return was 13%. Performance is measured using an index model regression on excess returns. Stock A Stock B Index model regression estimates 1% + 1.2(rM − rf) 2% + 0.8(rM − rf) R-square 0.605 0.451 Residual standard deviation, σ(e) 10.8% 19.6% Standard deviation of excess returns 22.1% 25.9% a. Calculate the following statistics for each stock: (Round your answers to 4 decimal places.) b. Which stock is the best choice under the following circumstances?

In: Finance

1.WHICH OF THE FOLLOWING IS NOT ONE OF THE FUNDAMENTAL QUESTIONS THAT SHOULD BE ASKED WHEN...

1.WHICH OF THE FOLLOWING IS NOT ONE OF THE FUNDAMENTAL QUESTIONS THAT SHOULD BE ASKED WHEN PLANNING AND CARRYING OUT ACTIVITIES IN A DEVELOPMENTALLY APPROPRIATE CLASSROOM?

A. Is it what the children want at the time of instruction?

B. Is it individually appropriate?

C. Is it socially and culturally appropriate?

D. Is it age appropriate?

2.Which of the following early childhood theorists developed the theory of learning intelligence as it pertains to individual learning styles?

A. Erik Erikson
B. Jean Piaget
C. Maria Montessori
D. Howard Gardner

3. Practice or pre-exercise theories of play pose the idea that

A. play provides children with an opportunity to practice adult activities.

B. play is necessary to reenergize human cognition.

C. children have too much energy and play will rid them of that energy.

D. children are the link between animals and human beings.

4. Direct instruction takes place when

A. Children explore their surroundings and learn based on their own curiosity and interests.

B. Learning takes place through a process of solving a specific problem.

C. The teacher shows children how something works or how to complete an activity.

D. A skill set is explicitly taught or an activity is completed.

5.Which of the following learning styles describes children who have highly developed auditory skills and the ability to use words effectively?

A. Interpersonal

B. Musical

C. Visual=spatial

D. linguistic

6. Exploratory play is best described as

A. the teacher guiding students through a process of discovery that leads to purposeful learning.
B. children being given the time necessary to explore their surroundings, learning based on their own curiosity and interests.
C. learning that takes place through a process of solving a specific problem.
D. the teacher showing children how something works or how to complete a portion of or the entire activity.

In: Physics