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
lina2011 [118]
3 years ago
8

Write a functionvector merge(vector a, vector b)that merges two vectors, alternating elements from both vectors. If one vector i

sshorter than the other, then alternate as long as you can and then append the remaining elements from the longer vector. For example, if a is 1 4 9 16and b is9 7 4 9 11then merge returns the vector1 9 4 7 9 4 16 9 1118. Write a predicate function bool same_elements(vector a, vector b)that checks whether two vectors have the same elements in some order, with the same multiplicities. For example, 1 4 9 16 9 7 4 9 11 and 11 1 4 9 16 9 7 4 9 would be considered identical, but1 4 9 16 9 7 4 9 11 and 11 11 7 9 16 4 1 would not. You will probably need one or more helper functions.19. What is the difference between the size and capacity of a vector
Computers and Technology
1 answer:
Roman55 [17]3 years ago
6 0

Answer:

see explaination for code

Explanation:

CODE

#include <iostream>

#include <vector>

using namespace std;

vector<int> merge(vector<int> a, vector<int> b) {

vector<int> result;

int k = 0;

int i = 0, j = 0;

while (i < a.size() && j < b.size()) {

if (k % 2 == 0) {

result.push_back(a[i ++]);

} else {

result.push_back(b[j ++]);

}

k ++;

}

while (i < a.size()) {

result.push_back(a[i ++]);

}

while(j < b.size()) {

result.push_back(b[j ++]);

}

return result;

}

int main() {

vector<int> a{1, 4, 9, 16};

vector<int> b{9, 7, 4, 9, 11};

vector<int> result = merge(a, b);

for (int i=0; i<result.size(); i++) {

cout << result[i] << " ";

}

}

You might be interested in
You're the administrator for a large bottling company. At the end of each month, you routinely view all logs and look for discre
Natali [406]

Answer:

It seems as though it would be a DDoS attack.

Explanation:

The characteristics are as follows:

A slow down of operations and attempting to get access into said service.

4 0
3 years ago
import java.util.Scanner; public class TeenagerDetector { public static void main (String [] args) { Scanner scnr = new Scanner(
Sonja [21]

Answer:

import java.util.Scanner;

public class TeenagerDetector {

   public static void main (String [] args) {

       Scanner scnr = new Scanner(System.in);

       boolean isTeenager;

       int kidAge;

       kidAge = scnr.nextInt();

       

       /* Your solution goes here */

       isTeenager = (kidAge >= 13) && (kidAge <= 19);

       if (isTeenager) {

           System.out.println("Teen");

           

       } else { System.out.println("Not teen"); } } }

Explanation:

A condition which check for the teenager age and return a boolean is assigned to isTeenager.

isTeenager = (kidAge >=13) && (kidAge <= 19);

So, if the kidAge is greater than/equal to 13 and less than/19, the boolean isTeenager will be true and the program will output "Teen" else "false" will be output.

The range of age for a teenager is 13 - 19.

5 0
4 years ago
Read 2 more answers
Write the code to declare a variable to hold the value of the grade you hope to get in this class. What stdio.h input function w
GREYUIT [131]

Answer:

// code to read grade

#include <stdio.h>

// main function

int main(void) {

   // if grade is character

char grade;

// if grade is numeric then we can use int or double

// int grade;

// double grade;

printf("Enter your grade:");

// read grade from user

scanf("%c",&grade);

// print grade

printf("your grade is:%c",grade);

return 0;

}

Explanation:

To read a value, scanf() function is used from stdio.h.Read a grade from user and assign it to variable "grade".

Output:

Enter your grade:A

your grade is:A

// code to read die volt

#include <stdio.h>

// main function

int main(void) {

// variable

double die_volt;

printf("Enter die volt:");

// read die volt from user

scanf("%lf",&die_volt);

// print die volt

printf("Entered die volt is:%0.2lf",die_volt);

return 0;

}

Explanation:

Read the die volt from user and assign it to variable "die_volt" with the help

of scanf() function.

Output:

Enter die volt:220                                                                                                        

Entered die volt is:220.00

4 0
3 years ago
The domain name is passed to a domain name server, which maps it to the correct IP address, and then the code behind the page is
maxonik [38]
It's an incomplete, therefore wrong, description of "<span>B. Browser using a URL to access a web page"

After the nameserver returns the IP address of the domain, the client machine makes the page request from the IP address. The client's browser parses (reads) the HTML code, makes calls to the server for any other files (href, img and media) and displays the HTML content according to visual specifications in the CSS (Cascading Style Sheet).
</span>
6 0
3 years ago
You have a computer at home. The computer is connected to the Internet through a dial-up connection. Every time you connect to t
worty [1.4K]

Hiya!

When you connect to the internet (especially through a dial-up connection), your computer must make the request for network resources. This is usually done through a Modem, a device designed to establish and split the connection among your devices.

Fun fact; a dial up connection uses the same radio frequencies that you would use to talk on the phone; and they're in the audible spectrum. When you start up that connection, the reason all those funny noises happen is because it's "talking" to your ISP over those lines.

Hope this helps!

3 0
3 years ago
Other questions:
  • Which of the following is true about the strategy that uses page fault frequency (PFF) to prevent thrashing?
    6·2 answers
  • What is telepresence
    8·1 answer
  • ________ network each device is connected directly to a central network switch.
    8·1 answer
  • How has the internet of things impacted buisness?
    15·1 answer
  • Assume that an array of Integers named a that contains exactly five elements has been declared and initialized. In addition, an
    12·1 answer
  • You want to multiply 50 in cell D3 by 8.90 in cell E3. Which formula should you use?
    11·1 answer
  • What tab should you choose to locate the copy and paste tool?
    10·2 answers
  • Which clauses in the Software Engineering Code of Ethics are upheld by a whistleblower (check all that apply). "Respect confiden
    15·1 answer
  • Is jesus dead or alive
    11·1 answer
  • How to execute python code in command prompt *window*?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!