Question
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
int main() { vector
/* 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
int main() { int numElements; unsigned int i; vector
/* 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started