Welcome to Westonci.ca, where your questions are met with accurate answers from a community of experts and enthusiasts. Our platform connects you with professionals ready to provide precise answers to all your questions in various areas of expertise. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

IN C++ PLEASE!!! Read integers from input and store each integer into a vector until -1 is read. Do not store -1 into the vector. Then, output all values in the vector that are greater than zero in reverse order, each on a new line.

Ex: If the input is -19 34 -54 65 -1, the output is:

65
34

#include
#include
using namespace std;

int main() {

/* Your solution goes here */

return 0;
}


Sagot :

#include
#include
using namespace std;

int main(){

int input[] = {-19, 34, -54, 65, -1};
std::vector voutput:
std::vector vinput (input, input + sizeof(input) / sizeof(int) );

for (std::vector::iterator it = vinput.begin(); it != vinput.end(); ++it)
if(*it > 0) voutput.insert(voutput.begin(), *it);
for(std::vector::iterator it = voutput.begin(); it < voutput.end(); ++it)
std::cout << *it << ‘\n’ ;

return 0;
}

The program is an illustration of vectors; vectors are data structures that are used to hold multiple values in one variable name

The main program

The program written in C++, where comments are used to explain each action is as follows:

#include <iostream>

#include <vector>

using namespace std;

int main(){

   //This declares the vector

   vector<int> nums;

   //This declares an integer variable

   int num;

   //Thie gets the first input

   cin>>num;

   //This loops is repeated until the user enters -1

   while(num != -1){

       nums.push_back(num);

       cin>>num; }  

   //This iterates through the vector

   for (auto i = nums.begin(); i != nums.end(); ++i){

       //This checks if the current element is above 1

       if(*i > 0){

           //If yes, the element is printed

           cout << *i <<endl;

       }      

   }

       return 0;

}

Read more about C++ programs at:

https://brainly.com/question/24027643