Question

In: Computer Science

C++ Given vector<float> vec; Using a ranged for loop, modify each value in vector to cube...

C++
Given vector<float> vec;
Using a ranged for loop, modify each value in vector to cube and subtract 12.5

Solutions

Expert Solution

ANS:

#include<string>
#include<vector>
#include<iostream>
using namespace std;

int main()
{
   vector<float> vec;
   float cube;
   cout<<"Enter Values for vector"<<endl;
   float value;
   for(int i=0;i<4;i++)
   {
       cout<<"Value:"<<i+1<<endl;
       cin>>value;
       vec.push_back(value);
      
   }
  
   //CUBE OF EACH VECTORE VALUE AND SUBTRACT BY 12.5
  
  
   for(int i=0;i<vec.size();i++)
   {
       cube=vec[i]*vec[i]*vec[i]-12.5;
       cout<<cube<<endl;
       vec[i]=cube;
      
   }
  
  
  
}

Comment down for any queries
Please give a thumbs up if you are satisfied with answer :)


Related Solutions

Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace...
Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace std; int main() { const int N=8; vector<int> nums(N); // User numbers int i=0; // Loop index cout << "\nEnter " << N << " numbers...\n"; for (i = 0; i < N; ++i) { cout << i+1 << ": "; cin >> nums.at(i); } // Convert negatives to 0 for (i = 0; i < N; ++i) { if (nums.at(i) < 0) {...
(C++)Put a new integer 1 at the second position of the vector. vec will now look...
(C++)Put a new integer 1 at the second position of the vector. vec will now look like this.   9 1 0 6 9 10 12 15 20 25 30 80 Your code: ___________________ int bmwOne(vector<int> & myVec) { int value = myVec.at(0); for (auto & x: myVec) { if (x < value) { value = x; } } return value; } Explain the code of bmwOne. What is it doing? If the function is called from the code below, what...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X,...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X, if X is greater than 1 and X is less than 100. Put the inline function in a main program that reads X from the keyboard, calls the function, and then outputs the result. 2. Show an empty statement and detail what it does? 3. A collection of predefined functions is called a Database                    C) Subroutine                       E) None of these Library                       D) Directive 4....
Given a vector of numeric values. with a R function using loop. testdouble(data). that returns TRUE...
Given a vector of numeric values. with a R function using loop. testdouble(data). that returns TRUE if all the even indexs elements of the vector are twice their preceding value, other wise your function returns FALSE. You can assume that the given vector has an even number of values. TRUE scenarios: c(3, 6, 5, 10, 11, 22, 13, 26) c(0, 0,1, 2, 2, 4, 3, 6) FALSE scenarios: c(3, 7, 5, 6, 11, 22, 13, 26) c(0, 2, 1, 2,...
Verify using an example that vector a + (vector b * vector c) is not equal...
Verify using an example that vector a + (vector b * vector c) is not equal to (vector a + vector b) * (vector a + vector c) explain the problem that arrises
Write a for loop from 1 to 3 using i as the variable. For each value...
Write a for loop from 1 to 3 using i as the variable. For each value of i: Create a vector x of 10 random numbers between 0 and 1. Create a second vector t which is equal to ten integers from 1 to 10. Plot x versus t in figure 1. Use hold on to keep each plot. Use a different color for the line for each value of i. At the very end, add the text 'time' using...
True or False: It's easy to loop through an array using a for loop in C++...
True or False: It's easy to loop through an array using a for loop in C++ because you can use the .size() function to get the total number of spaces in the array True or False: It's easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input #...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input # of rows: 2 Input Row 1: 9 8 7 6 3 2 1 5 4 Input Row 2: 1 2 4 3 5 6 9 8 7 Output 1,2,3,4,5,6,7,8,9 1,2,3,4,5,6,7,8,9
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT