Question

TASK 1: [20] • Write a little program that creates a vector array of type doubles with 10 members (0…9) • Use a for loop to store the values i^2 in the vector for each index i • Also write code to display the content of the vector • The output shou

TASK 1: [20] 

• Write a little program that creates a vector array of type doubles with 10 members (0…9) 

• Use a for loop to store the values i^2 in the vector for each index i 

• Also write code to display the content of the vector

• The output should be: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 

• Instead of using array access, try to use push_back, pop_back, etc. also, i.e. try being dynamic.

 

TASK 2: [20] 

• Generate random numbers between -1.0 and 1.0 

• Store these numbers in a vector 

• Play a bit with random and show us what you did

Screenshot 2022-03-11 203246.png

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1)

c++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<double>v;
    //push_back element in vector
    for(int i=0;i<10;i++)
    {
        v.push_back(i*i);
    }
    cout<<"Element of vector are:";
    for(int i=0;i<10;i++)
    {
        cout<<v[i]<<" ";
    }
    
return 0;
}

c++ code screenshot::

1646912589463_image.png

1646912667937_image.png


answered by: anonymous
Add a comment
Know the answer?
Add Answer to:
TASK 1: [20] • Write a little program that creates a vector array of type doubles with 10 members (0…9) • Use a for loop to store the values i^2 in the vector for each index i • Also write code to display the content of the vector • The output shou
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT