189k views
3 votes
Integers numEmployees, firstEmployee, middleEmployee, and lastEmployee are read from input. First, declare a vector of integers named runningNumbers with a size of numEmployees. Then, initialize the first, middle, and last element in runningNumbers to firstEmployee, middleEmployee, and lastEmployee, respectively.

Ex: If the input is 10 186 173 180, then the output is:

186 0 0 0 0 173 0 0 0 180

User Veronique
by
7.7k points

1 Answer

2 votes

Here is a C++ program that accomplishes the specified task.

#include <iostream>

#include <vector>

int main() {

int numEmployees, firstEmployee, middleEmployee, lastEmployee;

// Read input

std::cin >> numEmployees >> firstEmployee >> middleEmployee >> lastEmployee;

// Declare and initialize the vector

std::vector<int> runningNumbers(numEmployees);

runningNumbers[0] = firstEmployee;

runningNumbers[numEmployees / 2] = middleEmployee;

runningNumbers[numEmployees - 1] = lastEmployee;

// Output the result

for (int number : runningNumbers) {

std::cout << number << " ";

}

return 0;

}

No related questions found