1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kkurt [141]
2 years ago
6

Write the function evens which takes in a queue by reference and changes it to only contain the even elements. That is, if the q

ueue initially contains 3, 6, 1, 7, 8 then after calling odds, the queue will contain 6, 8. Note that the order of the elements in the queue remains the same. For full credit, no additional data structures (queues, stacks, vectors, etc.) should be used. Assume all libraries needed for your implementation have already been included.
Computers and Technology
1 answer:
kvv77 [185]2 years ago
3 0

Answer:

Explanation:

The following code is written in Java it goes through the queue that was passed as an argument, loops through it and removes all the odd numbers, leaving only the even numbers in the queue. It does not add any more data structures and finally returns the modified queue when its done.

  public static Queue<Integer> evens(Queue<Integer> queue) {

       int size = queue.size();

       for(int x = 1; x < size+1; x++) {

           if ((queue.peek() % 2) == 0) {

               queue.add(queue.peek());

               queue.remove();

           } else queue.remove();

       }

       return queue;

   }

You might be interested in
Consider a pipelined than can issue up to one instruction per cycle, but fewer may be issued because of pipeline hazards, multi-
a_sh-v [17]

Answer:

Achieved Instruction per cycle rate is 4.11\times 10^{15}

Solution:

As per the question:

Execution time, t = 1.4 s

No. of instructions being executed, n = 1.8 billion =

Clock speed of CPU, f = 3.2 GHz = 3.2\times 10^{9} Hz

Now, to calculate the actual issue rate achieved:

CPI (Cycle per Instruction) = \frac{t}{n\times f}

CPI = \frac{1.4}{1.8\times 10^{6}\times 3.2\times 10^{9}}

Instruction per cycle is given as the reciprocal of CPI:

Instruction per cycle = \frac{1.8\times 10^{6}\times 3.2\times 10^{9}}{1.4} = 4.11\times 10^{15}

6 0
3 years ago
Which of the following ethical guidelines is best described as refraining from using granted authorizations for personal gain or
Artyom0805 [142]

Answer:

A. Do not use computer access or the Internet for unprofessional or inappropriate purposes.

7 0
2 years ago
Create a class Car, which contains Three data members i.e. carName (of string type), ignition (of bool type), and currentSpeed (
olasank [31]

Answer:

Copy paste it.

Explanation:

#include <iostream>

#include <string>

using namespace std;

//Create a class Car, which contains • Three data members i.e. carName (of string type), ignition (of bool type), and //currentSpeed (of integer type)

class Car

{

public:

string carName;

bool ignition;

int currentSpeed;

//A no-argument constructor to initialize all data members with default values

//default value of string is "",bool is false,int is 0

Car()

{

carName="";

ignition=false;

currentSpeed=0;

}

//A parameterized constructor to initialize all data members with user-defined values

Car(string name,bool i,int speed)

{

carName=name;

ignition=i;

currentSpeed=speed;

}

//Three setter functions to set values for all data members individually

// Three getter function to get value of all data members individually

void setCarName(string s)

{

carName=s;

}

void setIgnition(bool ig)

{

ignition=ig;

}

void setCurrentSpeed(int speed)

{

currentSpeed=speed;

}

string getCarName()

{

return carName;

}

bool getIgnition()

{

return ignition;

}

int getCurrentSpeed()

{

return currentSpeed;

}

//A member function setSpeed( ) // takes integer argument for setting speed

void setSpeed(int sp1)

{

currentSpeed=sp1;

}

};

//Derive a class named Convertible

class Convertible:public Car

{

//A data member top (of Boolean type)

public:

bool top;

public:

//A no-argument constructor to assign default value as “false” to top

Convertible()

{

top=false;

}

//A four argument constructor to assign values to all data-members i.e. carName, ignition,

//currentSpeed and top.

Convertible(string n,bool i,int s,bool t):Car(n,i,s)

{

carName=n;

ignition=i;

currentSpeed=s;

top=t;

}

// A setter to set the top data member up

void setTop(bool t)

{

top=t;

}

//A function named show() that displays all data member values of invoking object

void show()

{

cout<<"Car name is:"<<carName<<endl;

cout<<"Ignition is: "<<ignition<<endl;

cout<<"Current Speed is :"<<currentSpeed<<endl;

cout<<"Top is:"<<top<<endl;

}

};

//main function

int main()

{

//creating object for Convertible class

Convertible c1("Audi",true,100,true);

c1.show();

c1.setCarName("Benz");

c1.setIgnition(true);

c1.setCurrentSpeed(80);

c1.setTop(true);

c1.show();

cout<<"Car Name is: "<<c1.getCarName()<<endl;

cout<<"Ignition is:"<<c1.getIgnition()<<endl;

cout<<"Current Speed is:"<<c1.getCurrentSpeed()<<endl;

return 0;

}

4 0
3 years ago
Are computer software programs an example of land, labor or capital?
Allisa [31]

Answer:

Labor

Explanation:

3 0
2 years ago
Read 2 more answers
Advanced Communications, a leading mobile communication service provider, has a deal with On-the-Go, a chain of several thousand
Stells [14]

Answer:

The answer is "Strategic alliance"

Explanation:

These alliances are an indo-organizational type in which several trading stakeholders decide to put resources, transfer knowledge. It also collaborates in environmentally friendly-nomic price-creating exercises.

  • In this alliances major mobile phone service provider, Advanced Phone has a contract with On-the-Go, a chain of several thousand convenience stores nationwide.
  • It depends on synergy in both the assets and technical expertise to introduce to those of the partnership by any of the trade members, that's why the strategic alliance is the correct answer.

3 0
2 years ago
Other questions:
  • Blogs are typically written by large companies or organizations as a way to express formal, technical, or scholarly information
    5·2 answers
  • What advantage do ExpressCard modules and U.S.B adapters offer over expansion cards?
    10·1 answer
  • In the windows firewall, any rules preceded by a __________ checkmark have not been enabled. black gray green red
    13·1 answer
  • A technician, joe, has replaced a faulty 500 gb hard drive in a pc system with a 1 tb hard drive. however, after the replacement
    10·1 answer
  • Do you think that feedly will help you create an effective personal online learning environment? Why or why not?
    15·1 answer
  • What food does swiss eat on christmas?
    10·1 answer
  • Which of the following Sales Hub tiers have access to work-flows (HubSpotâs automation platform)?
    9·1 answer
  • In what ways can information be slanted in a news report? List at least five ways.
    5·2 answers
  • A company is acquiring a smaller firm and is setting up a new IT system in order to consolidate the data and assets of the acqui
    11·1 answer
  • What are the values of the digital signal when sending in physical layer?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!