Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part a) Write a while loop to read positive integers from input until a non-positive integer is read. For each positive integer read before the

Part a)

Write a while loop to read positive integers from input until a non-positive integer is read. For each positive integer read before the non-positive integer, add the positive integer plus one to vector vect1.

Ex: If the input is 7 8 6 4 -999, then the output is:

8 9 7 5 

Note: Positive integers are greater than 0.

#include #include using namespace std;

int main() { vector vect1; int value; int i;

/* Your code goes here */

for (i = 0; i < vect1.size(); ++i) { cout << vect1.at(i) << endl; }

return 0; }

Part B)

Integer numElements is read from input. Then numElements integers are read and stored in vector pricesList. Write a loop that outputs each element in pricesList that is less than 100, and adds 60 to the element. End each output with " is set to 60 plus the current value" followed by a newline.

Ex: If the input is 3 93 215 86, then the output is:

Raw prices: 93 215 86 93 is set to 60 plus the current value 86 is set to 60 plus the current value Adjusted prices: 153 215 146

#include #include using namespace std;

int main() { int numElements; unsigned int i; vector pricesList; cin >> numElements; pricesList.resize(numElements); for (i = 0; i < pricesList.size(); ++i) { cin >> pricesList.at(i); } cout << "Raw prices: "; for (i = 0; i < pricesList.size(); ++i) { cout << pricesList.at(i) << " "; } cout << endl;

/* Your code goes here */

cout << "Adjusted prices: "; for (i = 0; i < pricesList.size(); ++i) { cout << pricesList.at(i) << " "; } cout << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions