Question

In: Computer Science

Write a program that creates three vector objects IN C++. Fill the first two objects with...

Write a program that creates three vector objects IN C++. Fill the first two objects with 25 floating-point numbers using a for loop as follows: 1. fill the first vector object with the loop counter value; 2. fill the second vector object with the loop counter value squared; 3. finally, write a for loop that adds the corresponding elements in the first two vectors, and puts the result in the corresponding element of the third vector. Display all three vectors using the format “for counter; element + element = element”.

Solutions

Expert Solution

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

int main()
{
vector<float> vectorOne(25);
vector<float> vectorTwo(25);
vector<float> vectorThree(25);

//1. fill the first vector object with the loop counter value
for(int i=0; i<vectorOne.size(); i++)
{

vectorOne.at(i)=i;

}
//2. fill the second vector object with the loop counter value squared
for(int i=0; i<vectorOne.size(); i++)
{

vectorTwo.at(i)=i*i;

}
//3. finally, write a for loop that adds the corresponding elements in the first two vectors, and puts the result in the
//corresponding element of the third vector
for(int i=0; i<vectorOne.size(); i++)
{
vectorThree.at(i)=vectorOne.at(i)+vectorTwo.at(i);

}
//Display all three vectors using the format “for counter; element + element = element”.
for(int i=0; i<vectorOne.size(); i++)
{
cout<<"FOR COUNTER "<<i<<": "<<vectorOne.at(i)<<"+"<<vectorTwo.at(i)<<" = "<<vectorThree.at(i)<<endl;

}

return 0;
}

OUTPUT:


Related Solutions

Write a program (in C, or Java, or C++, or C#) that creates three new threads...
Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this: Thread 1 - iteration no. 1 Thread 2 - iteration no. 1 Thread 3 - iteration no. 1 Thread 1 - iteration no. 2 Thread 2 - iteration no. 2...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a Singapore Airlines Loyalty program. You are asked to write an inheritance hierarchy discount system that benefits KrisFlyer members program to calculate their profit. A brief about KrisFlyer is that it is useful for those who fly on Singapore Airlines (its partners like Virgin Australia and Air New Zealand) frequently. KrisFlyer miles can be earned through credit cards, flying and bonus miles promotions. The miles...
I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
java please Write a program that creates an ArrayList and adds 5 circle objects to the...
java please Write a program that creates an ArrayList and adds 5 circle objects to the list , and display all elements in the list by invoking the object’s toString() method.
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes...
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes should start on opposite ends of the screen and then move toward each other. When they meet in the middle of the screen, each shape reverses course and moves toward the edge of the screen. The two shapes keep oscillating and bouncing off of each other in the middle of the screen. The program terminates when the shapes meet each other in the middle...
Write a java program that creates a hashtable with 10 objects and 5 data members using...
Write a java program that creates a hashtable with 10 objects and 5 data members using mutator and accessor methods for each data member.
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
In C++, write a program that creates a two-dimensional array initialized with some integers. Have the...
In C++, write a program that creates a two-dimensional array initialized with some integers. Have the following six functions: Total (total of all values in array), Average (average of values in array), Total of specific row (this needs 2 arguments, the array, like the others, and an integer for the subscript of any row. Total of specific Column (same as row), Max value in Row ( same as previous two, but return the highest value), Minimum Value ( same as...
C programming language The program first creates a child process CP. So, there are two processes:...
C programming language The program first creates a child process CP. So, there are two processes: The parent process does the following: a. compute the summary of all the even number from 1, 2, .. 1000, and output this summary; b. wait for the termination of the child process CP, then terminate; The child process does the following: a. compute the summary of all the odd number from 1, 2, .. 1000, and output this summary; b. terminates;
1. Write a C++ program, for.cpp, that reads three integers. The first two specify a range,...
1. Write a C++ program, for.cpp, that reads three integers. The first two specify a range, call them bottom and top, and the other gives a step value. The program should print four sequences using for loops: Each value in the range from bottom to top Each value in the range from top to bottom, reverse counting Every second value in the range from bottom to top Every value from bottom to top increasing by step a: If bottom is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT